Skip to content


linux 内网网关nat 上网

内网机器需要更新下载软件时,用内网可上网机器作nat连接外网

网关
外网网卡ip:61.88.54.23 网关:61.88.54.1
内网网卡ip:192.168.0.39 网关:无

客户机
内网网卡ip:192.168.0.40

内网网卡接在同一交换机上

1.网关机
#打开内核的包转发功能
echo 1 > /proc/sys/net/ipv4/ip_forward
#建立IP转发和映射

iptables -A FORWARD -d 192.168.0.0/24 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j SNAT –to-source 61.88.54.23

2.客户机
先加个corn 15点40自动清除,防止操作失败
crontab -e

40 15 * * * /sbin/route del default gw 192.168.0.39

3.添加路由
route add default gw 192.168.0.39

4.测试外网连接
ping 8.8.8.8

5.开机运行
vi /etc/rc.local

route add default gw 192.168.0.39

6.清除crontab

参考:
http://panpan.blog.51cto.com/489034/189072

Posted in LINUX.

Tagged with , .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.