开起转发
echo 1 > /proc/sys/net/ipv4/ip_forward
清除所有规则
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -F FORWARD
/sbin/iptables -X
/sbin/iptables -t nat �CX
默认
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD ACCEPT
/sbin/iptables -A FORWARD -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
开放端口
iptables -A INPUT -p udp --sport 53 -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
开放IP
iptables -A INPUT -s 203.86.0.243 -j ACCEPT
iptables -A OUTPUT -d 203.86.0.243 -j ACCEPT
iptables -A INPUT -m iprange --src-range 203.70.21.200-203.70.21.207 -j ACCEPT
iptables -A OUTPUT -m iprange --dst-range 203.70.21.200-203.70.21.207 -j ACCEPT
对IP
开发指定端口
iptables -A INPUT -s 222.126.154.156 -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -d 222.126.154.156 -p tcp --sport 22 -j ACCEPT
允许PING
iptables -A INPUT -p icmp -j ACCEPT
iptables -A OUTPUT -p icmp -j ACCEPT
自动返回
/sbin/iptables -A FORWARD -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
端口转发
/sbin/iptables -t nat -I PREROUTING -s 210.176.52.7 -d 119.38.224.242 -p tcp --dport 3032 -j DNAT --to 192.168.13.235:3032
/sbin/iptables -t nat -I PREROUTING -s 210.176.52.7 -d 119.38.224.242 -p tcp --dport 65400:65490 -j DNAT --to 192.168.13.235
IP
转发 NAT
单个
/sbin/iptables -t nat -I POSTROUTING -s 192.168.13.0/24 -d 121.101.216.90 -j SNAT --to-source 119.38.224.242
IP
转发 NAT
所有内网
/sbin/iptables -t nat -I POSTROUTING -s 192.168.13.0/24 -j SNAT --to-source 119.38.224.242