1. 配置网卡IP地址, 配置静态IP地址,
/etc/sysconfig/network-stripts/ifcfg-eth0配置网卡一, 外网卡, 可以联网
/etc/sysconfig/network-stripts/ifcfg-eth1配置网卡二, 内网卡, 连接内网
配置网卡配置文件
DEVICE=eth1
IPADDR=192.168.145.122// IP地址
NETMASK=255.255.255.0// IP掩码
gateway=192.168.142.2// 外网网关地址
ONBOOT=yes
或者配置/etc/sysconfig/network 添加网关地址
gateway=192.168.142.2 // 外网网关地址
2. 打开包转发功能:
echo "1" > /proc/sys/net/ipv4/ip_forward
3. 修改/etc/sysctl.conf文件, 让包转发功能在系统启动时自动生效:
net.ipv4.ip_forward = 1
4. 添加iptables nat路由规则: // 清楚其他不需要的iptables规则
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE// 其中网卡eth0 为外网卡。
保存规则到/etc/sysconfig/iptables 配置文件中
service iptables save
重新启动iptables
service iptables restart