网站首页 > 技术教程 正文
0、iptables(ACL)的匹配原则:
与cisco等一致,从上到下依次匹配。
1、iptables的基本用法:。
(1)命令格式
iptables [–ttable] command [match] [target]
table:表,有三个:filter(过滤) nat(转发) mangle(更改)
表的组成格式:链表。
command:命令,有很多:
-A –append:添加
-D –delete: 删除
-G –policy: 策略
-N –new-chain 链表
-L –list: 列出链中规则
-R –replace: 替换链表匹配的规则
-C –check: 检查匹配
-I –insert: 插入规则
举例:
-A INPUT
-I OUTPUT 3(插入到第3条)
-D INPUT 10(删除第10条)
match:匹配
-p:策略
-s:源
-d:目的
--sport:源端口
--dport:源地址
-i:入接口
-o:出接口
target:目标或者说操作
accept、drop、reject、return、log、tos 、snat、dnat、masquerade、redirect、mark、return(返回主链,中间可以转到自定义链)
(2)简单操作介绍:
接收数据包:
iptables –A INPUT –s192.168.1.0/24 –j ACCEPT
拒绝数据包:
iptable –A INPUT –s192.168.1.2 --dport 80 -j DROP
查看规则表
Iptables -L –nv
2、扩展:
--icmp-type:对应icmp的类型
--tcp-flag :syn ack fin psh rst urg(至少匹配两个为1 不匹配强制匹配为0)
3、iptables的实例:
(1)filter
要求:内网用户sale只能访问内网http服务器内网接口,tech只能访问ftp,ping全部关闭。telnet全部关闭。内部用户不能上外网。外网用户只能访问http外网接口。(nat部分后面介绍)
iptables
默认链清空iptables –Z
开始:
(1) 对于inside口:(都有-i inside 或 –oinside,写不开了)
*iptables –t filter–A INPUT –s 192.168.1.0/24 –d 192.168.254.2 –p tcp –dport 21,22 –j ACCEPT
*iptables –tfilter –A INPUT –s 192.168.2.0/24 –d 192.168.254.1 –p tcp –dport 80 –j ACCEPT
*iptables –tfilter –A INPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP
*iptables–t filter–A OUTPUT –s 192.168.254.2 –d 192.168.1.0/24 –p tcp –sport 21,22 –j ACCEPT
*iptables –tfilter –A OUTPUT –s 192.168.254.1 –d 192.168.2.0/24 –p tcp –sport 80 –j ACCEPT
*iptables –tfilter –A OUTPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP
(2) 对于outside口:(都有-i outside 或 –o outside,写不开了)
*ipables –t filter–A INPUT –s 0.0.0.0/0 –d 202.200.200.1 –p tcp –dport 80 –j ACCEPT
*ipables –t filter–A INPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP
*iptables –tfilter –A OUTPUT –s 202.200.200.1 –p –sport 80 –j ACCEPT
*iptables –tfilter –A OUTPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP
(3) 对于DMZ口:(都有-i DMZ 或 –oDMZ,写不开了):重复性的
*iptables –t filter–A INPUT –s 192.168.1.0/24 –d 192.168.254.2 –p tcp –dport 21,22 –j ACCEPT
*iptables –tfilter –A INPUT –s 192.168.2.0/24 –d 192.168.254.1 –p tcp –dport 80 –j ACCEPT
ipables –t filter–A INPUT –s 0.0.0.0/0 –d 202.200.200.1 –p tcp –dport 80 –j ACCEPT
*iptables –tfilter –A INPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP
*iptables–t filter–A OUTPUT –s 192.168.254.2 –d 192.168.1.0/24 –p tcp –sport 21,22 –j ACCEPT
*iptables –tfilter –A OUTPUT –s 192.168.254.1 –d 192.168.2.0/24 –p tcp –sport 80 –j ACCEPT
*iptables –tfilter –A OUTPUT –s 202.200.200.1 –p –sport 80 –j ACCEPT
*iptables –tfilter –A OUTPUT –s 0.0.0.0/0 –d 0.0.0.0/0 –j DROP
(2)nat
要求:主机20.20.20.2做地址转换;服务器10.10.10.2做端口映射。
*iptables –t nat–A POSTROUTING –o out –s 20.20.20.2 –j SNAT –to 192.168.1.49
*iptables –t nat–A POSTROUTING –i out –s 0.0.0.0/0 –j SNAT –to 192.168.1.48
*iptables –t nat–A POSTROUTING –o out –s 10.10.10.2 –j DNAT –to 192.168.1.50
*iptables –t nat–A POSTROUTING –i out –s 0.0.0.0/0 –p tcp –port 80 –j REDIRECT
--to-port 1080
猜你喜欢
- 2025-06-23 Linux 操作系统不需要防病毒软件和防火墙的几个原因
- 2025-06-23 Linux防火墙——iptables原理介绍
- 2025-06-23 防火墙/路由器Linux发行版Devil-Linux
- 2025-06-23 五问 Linux 网络防火墙(四):nftables 的高效框架与数据结构
- 2025-06-23 linux防火墙过滤技术iptables的原理及操作命令详解
- 2025-06-23 Linux,操作系统,防火墙,Netfilter,命令及操作
- 2025-06-23 Linux安全之网络防火墙(linux防火墙在哪)
- 2025-06-23 linux系统相关防火墙iptables命令操作
- 2025-06-23 linux 防火墙基本命令(linux防火墙主要功能)
- 2025-06-23 Linux 防火墙设置命令(linux防火墙设置firewalld)
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)