标签:回调 httpd服务 direct 主机 替换 stat 清空 pen out
一、iptables命令iptables是一个规则管理工具. 具有添加、修改、删除和显示等功能.
规则和链都有计数器:
用法:
$ iptables [-t table] SUBCOMMAND CHAIN CERTERIA -j TARGET
匹配条件:
扩展匹配: -m macth_name --spec_options; 例如-m tcp --dport 22
-p icmp:
$ iptables -t filter -N IN_public
$ iptables -t filter -L -n
...
Chain IN_public (0 references)
target prot opt source destination
$ iptables -t filter -E IN_putlic OUT_pulic
$ iptables -t filter -L -n
...
Chain OUT_pulic (0 references)
target prot opt source destination
$ iptables -t filter -P FORWARD DROP
$ iptables -t filter -L -n
...
Chain FORWARD (policy DROP)
target prot opt source destination
...
$ iptables -t filter -L -n --line-numbers
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
3 FORWARD_direct all -- 0.0.0.0/0 0.0.0.0/0
4 FORWARD_IN_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/0
5 FORWARD_IN_ZONES all -- 0.0.0.0/0 0.0.0.0/0
6 FORWARD_OUT_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/0
7 FORWARD_OUT_ZONES all -- 0.0.0.0/0 0.0.0.0/0
8 DROP all -- 0.0.0.0/0 0.0.0.0/0 ctstate INVALID
9 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
$ iptables -t filter -D FORWARD 9
$ iptables -t filter -L -n --line-numbers
...
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
3 FORWARD_direct all -- 0.0.0.0/0 0.0.0.0/0
4 FORWARD_IN_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/0
5 FORWARD_IN_ZONES all -- 0.0.0.0/0 0.0.0.0/0
6 FORWARD_OUT_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/0
7 FORWARD_OUT_ZONES all -- 0.0.0.0/0 0.0.0.0/0
8 DROP all -- 0.0.0.0/0 0.0.0.0/0 ctstate INVALID
$ iptables -t filter -A INPUT -s 0.0.0.0/0 -d 192.168.123.101 -p tcp -j ACCEPT
$ iptables -t filter -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 192.168.123.101
iptables -t filter -A OUTPUT -s 192.168.123.101 -d 0.0.0.0/0 -p tcp -j ACCEPT
$ iptables -t filter -L -n
...
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 192.168.123.101 0.0.0.0/0
$ iptables -t filter -P INPUT DROP
$ iptables -t filter -P FORWARD DROP
$ iptables -t filter -P OUTPUT DROP
$ iptables -t filter -A INPUT -d 192.168.123.101 -p icmp -j ACCEPT
$ iptables -t filter -A OUTPUT -s 192.168.123.101 -d 0.0.0.0/0 -p icmp -j ACCEPT
$ iptables -L -n -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
779 83096 ACCEPT tcp -- * * 0.0.0.0/0 192.168.123.101
0 0 ACCEPT icmp -- * * 0.0.0.0/0 192.168.123.101
...
Chain OUTPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
458 64864 ACCEPT tcp -- * * 192.168.123.101 0.0.0.0/0
0 0 ACCEPT icmp -- * * 192.168.123.101 0.0.0.0/0
$ iptables -t filter -L -n --line-numbers
Chain INPUT (policy DROP)
num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 192.168.123.101
2 ACCEPT icmp -- 0.0.0.0/0 192.168.123.101
...
Chain OUTPUT (policy DROP)
num target prot opt source destination
1 ACCEPT tcp -- 192.168.123.101 0.0.0.0/0
2 ACCEPT icmp -- 192.168.123.101 0.0.0.0/0
$ iptables -t filter -D INPUT 2
$ iptables -t filter -D OUTPUT 2
$ iptables -t filter -L -n
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 192.168.123.101
...
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- 192.168.123.101 0.0.0.0/0
$ iptables -t filter -A INPUT -s 0.0.0.0/0 -d 192.168.123.101 -i ens33 -j ACCEPT
$ iptables -t filter -A OUTPUT -s 192.168.123.101 -d 0.0.0.0/0 -o ens33 -j ACCEPT
$ iptables -L -n -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
1256 133K ACCEPT tcp -- * * 0.0.0.0/0 192.168.123.101
0 0 ACCEPT all -- ens33 * 0.0.0.0/0 192.168.123.101
...
Chain OUTPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
791 113K ACCEPT tcp -- * * 192.168.123.101 0.0.0.0/0
0 0 ACCEPT all -- * ens33 192.168.123.101 0.0.0.0/0
$ iptables -t filter -A INPUT -s 0.0.0.0/0 -d 192.168.123.101 -p tcp --dport 22 -j ACCEPT
$ iptables -t filter -A OUTPUT -s 192.168.123.100 -d 0.0.0.0/0 -p tcp --sport 22 -j ACCEPT
$ iptables -t filter -L -n -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT tcp -- * * 0.0.0.0/0 192.168.123.101 tcp dpt:22
...
Chain OUTPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT tcp -- * * 192.168.123.100 0.0.0.0/0 tcp spt:22
$ iptables -t filter -D INPUT 2
$ iptables -t filter -D OUTPUT 2
$ iptables -t filter -A INPUT -s 0.0.0.0/0 -d 192.168.123.101 -p tcp --dport 80 -j ACCEPT
$ iptables -t filter -A OUTPUT -s 192.168.123.101 -d 0.0.0.0/0 -p tcp --sport 80 -j ACCEPT
$ iptables -L -n -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT tcp -- * * 0.0.0.0/0 192.168.123.101 tcp dpt:80
...
Chain OUTPUT (policy DROP 2 packets, 152 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT tcp -- * * 192.168.123.101 0.0.0.0/0 tcp spt:80
$ iptables -t filter -A OUTPUT -s 192.168.123.101 -d 0.0.0.0/0 -p icmp --icmp-type 9 -j ACCEPT
$ iptables -t filter -A INPUT -s 0.0.0.0/0 -d 192.168.123.101 -p icmp --icmp-type 0 -j ACCEPT
$ iptables -t filter -L -n -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT icmp -- * * 0.0.0.0/0 192.168.123.101 icmptype 0
...
Chain OUTPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT icmp -- * * 192.168.123.101 0.0.0.0/0 icmptype 9
标签:回调 httpd服务 direct 主机 替换 stat 清空 pen out
原文地址:http://blog.51cto.com/13501622/2143952