[root@localhost ~]# iptables -L //查看Iptables规则链中的全部规则; [root@localhost ~]# iptables -F //清空Iptables规则链中全部规则; [root@localhost ~]# iptables -P INPUT DROP //全部进入本机的数据包都将丢弃; [root@localhost ~]# iptables -P INPUT ACCEPT //容许全部的数据包进入本机; [root@localhost ~]# iptables -A INPUT -p tcp --tcp-flags SYN,ACK SYN -j DROP //容许本地主机对外发起TCP链接时,能收到外部主机的TCP应答并创建链接; DROP tcp -- anywhere anywhere tcp flags:SYN,ACK/SYN 或者: [root@localhost ~]# iptables -A INPUT -p tcp --syn -j DROP DROP tcp -- anywhere anywhere tcp flags:SYN,RST,ACK/SYN //不但过滤SYN,还过滤reset; [root@localhost ~]# iptables -A INPUT -s ! 192.168.100.0/24 -p icmp -j DROP //禁止除192.168.100.0网段外的主机ping本地计算机; [root@localhost ~]# iptables -A OUTPUT -d ! 192.168.100.0/24 -m owner --uid-owner 0 -j DROP //把uid=0,也就是root用户的数据包除发往192.168.100.0网段外,所有drop掉; Chain OUTPUT (policy ACCEPT) target prot opt source destination DROP all -- anywhere !192.168.100.0/24 OWNER UID match root 转换源IP地址: [root@localhost ~]# iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j MASQUERADE //未来自192.168.100.0网段的数据包中来源IP地址,转换成eth0网卡的IP地址; 若是eth0有固定ip,写固定IP会比较好: [root@localhost ~]# iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -j SNAT --to-source 10.0.1.254 转换目的IP地址: [root@localhost ~]# iptables -t nat -A PREOUTING -d [url]www.example.com[/url] -p tcp --dport 80 -j DNAT --to-dest 192.168.100.1 //将全部到目的地[url]www.example.com[/url]的、使用TCP协议的、端口为80的数据包的目的地IP地址,转换为192.168.100.1 [root@localhost ~]# iptables -A INPUT -p all -s 0.0.0.0/0.0.0.0 -i lo -j ACCEPT //容许来自lo网络接口的全部数据包;