linux nat路由设置
1)网卡设置
eth0作为外网口
192.168.1.201 255.255.255.0 192.168.1.1
eth1作为内网口
192.168.0.1 255.255.255.0
2)开启ip转发
#echo 1 > /proc/sys/net/ipv4/ip_forward
永久开启方法:
#vim /etc/sysctl.conf
net.ipv4.ip_forward=1
3)使用itables开启nat( MASQUERADE)
#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
4)使用iptables允许数据流(这样是不安全的,先做测试)
#iptables -t filter -A FORWARD -i eth0 -o eth1 -j ACCEPT
#iptables -t filter -A FORWARD -o eth1 -i eth0 -j ACCEPT
5)安装DHCP服务
#rpm -ivh dhcp-3.0.5-23.el5.i386.rpm
#rpm -ivh dhcp-devel-3.0.5-23.el5.i386.rpm
[root@guojianjun ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
首先从/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample 目录下把配置文件复到 /etc/dhcpd.conf
把原来 dhcpd.conf文件复盖.
#vi /dhcpd.conf
修改下面几行,因eth1占用了192.168.0.1, 因而dhcp池从192.168.0.2开始.
range dynamic-bootp 192.168.0.2 192.168.0.254;
default-lease-time 21600;
max-lease-time 43200;
#service dhcpd restart