那就这样
#!/bin/sh
wan_if="eth1"
wan_ip="192.168.0.2"
lan_if="eth0"
lan_ip="192.168.1.1"
lan_range="192.168.1.0/24"
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat
iptables -F -t mangle
iptables -X -t mangle
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p ALL -i $lan_if -s $lan_range -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
#SNAT
iptables -t nat -A POSTROUTING -s $lan_range -o $wan_if -j SNAT --to $wan_ip
#透明代理
#iptables -t nat -A PREROUTING -s $lan_range -i $lan_if -p tcp --dport 80 -j REDIRECT --to 3128
#过滤规则
iptables -A FORWARD -s $lan_range -i $lan_if -p <tcp/udp> --dport <port(s)> -j ACCEPT
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
复制代码