自己改进了一下iptables,上次发的不是很好,这次修改了一下。只要拿个这个脚本只要在相应的基础上修改端口号就可以了,前面都不需要修改最后startNAT如果用到某个功能就把#号去掉即可,MAC 地址修改一下,ip地址修改一下即可。
#!/bin/sh
# this is nat command for NAT
modprobe ip_tables > /dev/null 2>&1
modprobe iptable_nat > /dev/null 2>&1
modprobe ip_conntrack_ftp > /dev/null 2>&1
modprobe ip_nat_ftp > /dev/null 2>&1
modprobe ip_nat_irc > /dev/null 2>&1
modprobe ip_conntrack > /dev/null 2>&1
modprobe ip_conntrack_irc > /dev/null 2>&1
#clean default set
iptables -F
iptables -X
iptables -Z
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat
#setup filter table default ruler
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
#start ip_forward
#echo 1 > /proc/sys/net/ipv4/ip_forward
#accept protocol
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 10000 -j ACCEPT
iptables -A INPUT -p gre -j ACCEPT
iptables -A INPUT -p tcp --dport 47 -j ACCEPT
iptables -A INPUT -p tcp --dport 1723 -j ACCEPT
iptables -A INPUT -p tcp --dport 901 -j ACCEPT
iptables -A INPUT -p udp --dport 137 -j ACCEPT
iptables -A INPUT -p tcp --dport 81 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 3128 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT
iptables -A INPUT -p tcp --dport 53 -j ACCEPT
iptables -A INPUT -p udp --dport 137 -j ACCEPT
iptables -A INPUT -p udp --dport 138 -j ACCEPT
iptables -A INPUT -p tcp --dport 139 -j ACCEPT
iptables -A INPUT -p tcp --dport 445 -j ACCEPT
iptables -A INPUT -i lo -p all -j ACCEPT
iptables -A OUTPUT -p tcp --sport 31337 -j DROP
iptables -A OUTPUT -p tcp --dport 31337 -j DROP
iptables -A INPUT -p icmp -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
iptables -A FORWARD -p TCP ! --syn -m state --state NEW -j DROP
iptables -A FORWARD -f -m limit --limit 100/s --limit-burst 100 -j ACCEPT
iptables -A FORWARD -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -s 192.168.100.0/24 -j DROP
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -m state --state INVALID -j DROP
iptables -A FORWARD -m state --state INVALID -j DROP
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -I FORWARD -m mac --mac-source 00:05:5D:6D:88:57 -j ACCEPT
iptables -I FORWARD -m mac --mac-source 00:05:5D:67:F2:3E -j ACCEPT
#start NAT
#iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j SNAT --to-source 192.168.20.88 //表示启动NAT代理
#iptables -t nat -A PREROUTING -i eth1 -p tcp -s 192.168.100.0/24 --dport 80 -j REDIRECT --to-ports 3128//主要用于squid代理
#iptables -t nat -A PREROUTING -p tcp -s 192.168.100.0/24 --dport 80 -mstate --state NEW,ESTABLISHED,RELATED -j REDIRECT --to-port 3128//这个也是squid代理
#iptables -t nat -A PREROUTING -p tcp -d 24.68.32.118 --dport 8080 -j DNAT --to 192.168.xxx.xxx:80 //这个是DNAT
本文转自zh888 51CTO博客,原文链接:http://blog.51cto.com/zh888/741727,如需转载请自行联系原作者