您的位置:首页 > 运维架构 > Linux

linux 内网访问外网配置

2012-06-11 15:28 357 查看
假设公网IP地址为:115.218.232.116 ,对应的内网地址为:192.168.10.1

1、在公网服务器上执行以下命令:

# echo "1" > /proc/sys/net/ipv4/ip_forward

modprobe ip_tables

modprobe iptable_nat

modprobe iptable_filter

modprobe ip_conntrack

modprobe ip_conntrack_ftp

modprobe ip_nat_ftp

2、在公网服务器上的iptables文件增加如下内容:

# vi /etc/sysconfig/iptables

-A POSTROUTING -s 192.168.10.2 -o eth0 -j SNAT --to-source 115.218.232.116

其中192.168.10.2是需要访问外网的服务器

增加完毕后,重启防火墙

# service iptables restart

3、将10.2服务器的网关设置为公网的内网IP地址:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

GATEWAY=192.168.10.1

4、将10.2服务器的DNS(/etc/resolv.conf)配置替换成公网的DNS配置,然后重启网络:

# service network restart

5、测试

# ping -c 3 www.baidu.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: