下面这个是基于debian 4.01版本. 一个简单的路由功能,要做路由转换前先要清楚自己内部的网卡的设置.
# cat /etc/network/interfaces
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet static
address 192.168.0.5
netmask 255.255.255.0
gateway 192.168.0.1
auto eth1
iface eth1 inet static
address 192.168.8.1
netmask 255.255.255.0
auto eth2
iface eth2 inet static
address 192.168.9.1
netmask 255.255.255.0
下面这个就是开始使用路由转换功能.
# cat nat.sh
/sbin/iptables -A POSTROUTING -t nat -s 192.168.8.0/255.255.255.0 -o eth0 -j MASQUERADE
/sbin/iptables -A POSTROUTING -t nat -s 192.168.9.0/255.255.255.0 -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward #这个是打开路由转发功能
要让他能开机自动运行.
#cp nat.sh /etc/rc2.d/nat.sh
#chmod 777 /etc/rc2.d/nat.sh
