前几天写了一个很简单的iptables脚本,贴出来,时常温习一下语法结构:
- #!/bin/bash
- #
- iptables -F
- iptables -Z
- iptables -X
- iptables -F -t nat
- iptables -X -t nat
- iptables -Z -t nat
- # For lookback
- iptables -A INPUT -i lo -j ACCEPT
- iptables -A OUTPUT -o lo -j ACCEPT
- #For APP Server
- iptables -A INPUT -p tcp -m multiport --port 80,443,21099 -j ACCEPT
- iptables -A INPUT -p udp --dport 21099 -j ACCEPT
- #For SSH
- iptables -A INPUT -p tcp -s 192.168.0.0/16 --dport 22 -j ACCEPT
- iptables -A INPUT -p tcp -s 10.10.0.0/16 --dport 22 -j ACCEPT
- # For ping
- iptables -A OUTPUT -p icmp -j ACCEPT
- iptables -A INPUT -p icmp -j ACCEPT
- # For default
- iptables -P INPUT DROP
- iptables -P OUTPUT ACCEPT
- iptables -P FORWARD ACCEPT
- iptables -t nat -P PREROUTING ACCEPT
- iptables -t nat -P POSTROUTING ACCEPT
- iptables -t nat -P OUTPUT ACCEPT
- iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
本文转自 li_qinshan 51CTO博客,原文链接:
http://blog.51cto.com/share/866284
http://blog.51cto.com/share/866284