eth0 为外网的网卡
eth1 为内部的网卡
- #!/bin/bash
- echo "Start iptables .."
- #加载模块
- modprobe iptable_nat
- modprobe ip_conntrack
- modprobe ip_conntrack_ftp
- #打开转发
- echo 1 >/proc/sys/net/ipv4/ip_forward
- #清除表
- iptables -F INPUT
- iptables -F FORWARD
- iptables -F POSTROUTING -t nat
- iptables -t nat -F
- #默认规则为DROP(丢弃)
- iptables -P FORWARD ACCEPT
- iptables -P INPUT DROP
- iptables -P OUTPUT DROP
- #回环打开
- iptables -A INPUT -i lo -j ACCEPT
- iptables -A OUTPUT -o lo -j ACCEPT
- #############
- iptables -A FORWARD -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
- #接收所有来自eth1的网络数据
- iptables -A INPUT -i eth1 -j ACCEPT
- #打开DNS端口
- iptables -A INPUT -i eth0 -p udp -sport 53 -j ACCEPT
- #所有外部的源端口为80的允许
- iptables -A INPUT -i eth0 -p tcp --sport 80 -j ACCEPT
- #外面进来目标80端口到192.168.0.6:80(映射80,6060)
- iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.0.6:80
- iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 6060 -j DNAT --to 192.168.0.6
- iptables -t nat -A PREROUTING -i eth0 -p udp --dport 6060 -j DNAT --to 192.168.0.6
- #^-^
- iptables -A FORWARD -s 192.168.0.254 -j ACCEPT
- iptables -t nat -A POSTROUTING -o eth1 -s 192.168.0.254 -j SNAT --to 192.168.0.10
复制代码
目的:
服务器可以和局域网内部其他计算机相互通信
映射了80.6060端口到192.168.0.6, web服务器在192.168.0.6上,6060端口好像是那个花生壳的,一起映射了.
所有外部访问到服务器的80的端口映射到了192.168.0.6这台服务器上来
192.168.0.254允许上网, ^-^ ,是我的电脑 
高手帮忙看看有没有错 .. 呵呵 ~ |