shell脚本:
说明:内网可以正常上网,只能通过端口访问DMZ里的服务器
firewall服务器和DMZ里的器不能上网,但是可以指定访问外网某个IP
外网可以通过访问DNAT映射访问内网web和FTP服务器
指定某个IP进行管理iptables,不允许外网进行管理
服务器不能主动上外网
[root@firewall ~]# cat /opt/firewall.sh
#!/bin/bash
/sbin/modprobe nf_conntrack_ftp
/sbin/modprobe nf_nat_ftp
echo "1" >/proc/sys/net/ipv4/ip_forward
#filter chain
/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -Z
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -A INPUT ! -i eth0 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT ! -i eth0 -p icmp -j ACCEPT
/sbin/iptables -A INPUT ! -i eth0 -m state --state ESTABLISHED -j ACCEPT
/sbin/iptables -A INPUT ! -i eth0 -m state --state INVALID -j DROP
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT ! -o eth0 -p icmp -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT
/sbin/iptables -A FORWARD -i eth2 -o eth0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -i eth0 -o eth2 -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -i eth2 -o eth1 -p tcp -m multiport --dport 21,80 -j ACCEPT
/sbin/iptables -A FORWARD -i eth2 -o eth1 -s 172.16.16.2 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A FORWARD -i eth2 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -i eth1 -o eth2 -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -i eth0 -o eth1 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
#nat chain
/sbin/iptables -t nat -F
/sbin/iptables -t nat -X
/sbin/iptables -t nat -Z
/sbin/iptables -t nat -P PREROUTING ACCEPT
/sbin/iptables -t nat -P OUTPUT ACCEPT
/sbin/iptables -t nat -P POSTROUTING ACCEPT
/sbin/iptables -t nat -A POSTROUTING -s 172.16.16.0/24 -o eth0 -j SNAT --to-source 192.168.1.58
/sbin/iptables -t nat -A POSTROUTING -s 10.1.1.10/24 -o eth0 -j SNAT --to-source 192.168.1.58
/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.1.1.5:80
/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 21 -j DNAT --to-destination 10.1.1.5:21
/etc/init.d/iptables save
注意:FORWARD链有好多条可以写成一条,为了易懂,我分开写了