iptables
第1章 iptables 命令格式
1.1 格式
iptables -t table 命令 chian rules -j target
table
可以是filter nat mangle nat 默认是filter
命令
-P或--policy 用来定义默认策略,就是允许通不通过
-A或 --append 在规则列表的最后增加一条规则
-I 或insert 在指定的位置插入一条规则,不指定位置就是在最上面插入
-D 或 --delete 删除一个规则
-R或 --replace修改某条规则
-F或 --flush 删除表中的所有规则
1.2 举例
iptables -t filter -P FORWARD ACCEPT 设置filter表ACCEPT链默认接受数据包
iptables -t filter -I INPUT -p icmp -j DROP 在INPUT首插入1条规则
iptables -I INPUT 2 -p icmp -j DROP 在INPUT链第二行插入1条规则
iptables -D INPUT 2 删除INPUT链的第二条规则
iptables -R INPUT 2 -p icmp -j DROP 修改INPUT第二条规则,改成DROP
iptables -F INPUT 清除INPUT链中的所有规则
iptables -F 不指定链是清除所有
举例
1.1.1 举例
禁止外网ping route 路由器
[root@route ~]# iptables -t filter -I INPUT -p icmp -i eth1 -j DROP
之后
wai网 ping eth1网卡就不通了
但是不影响外网ping10.123的机器
1.1.1 禁止 80.123这个机器ssh连接 10.123这台机器
为什么要用FORWARD 因为80.123通过route 连接10.123 对与FORWARD来说.route负责的是转发
iptables -t filter -I FORWARD -p tcp -s 192.168.80.123/32 -d 192.168.10.123/32 --dport 22 -j DROP
之后 SSH 连接不上了
再次添加 192.168.80.0网段对 192.168.10.0网段有所有权限
[root@route ~]# iptables -t filter -I FORWARD -s 192.168.80.0/24 -d 192.168.10.0/24 -j ACCEPT
又能连接了,因为比较宽泛的规则在FORWARD最上面,匹配到了