CentOS 6.6下双网卡共享上网配置

实现方式:通过设置iptables的nat规则,使内网服务器可以访问Internet

1.系统环境:

[root@MysqL-server~] #cat/etc/redhat-release
CentOSrelease6.6(Final)
#uname-r
2.6.32-504.el6.x86_64
#uname-m
x86_64

2.准备两台虚拟机

==========================================================================
主机名外网内网
Web-Lnmp02eth0:192.168.73.171eth1:192.168.56.130
MysqL-servereth0:192.168.56.129
DNS:192.168.73.2
注:内网使用仅主机模式连接,手动设置IP
外网使用NAT模式连接,使用dhcp动态获取的IP
==========================================================================

3.配置Web-Lnmp02服务器

1)开启IP转发功能

[root@Web-Lnmp02network-scripts] #echo"net.ipv4.ip_forward=1">>/etc/sysctl.con
#sysctl-p

2)配置iptables

[root@Web-Lnmp02~] #iptables-F
#iptables-PINPUTACCEPT
#iptables-PFORWARDACCEPT
#iptables-tnat-APOSTROUTING-oeth0-jMASQUERADE 或者
iptables-tnat-APOSTROUTING -s ip -oeth0-jMASQUERADE
#/etc/init.d/iptablessave
#/etc/init.d/iptablesrestart
说明:
iptables-F #清除原有的filter有中的规则
iptables-tnat-F #清除原有的nat表中的规则
iptables-PFORWARDACCEPT #缺省允许IP转发

4.配置MysqL-server

1)IP设置

#cat/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT= yes
NM_CONTROLLED= yes
BOOTPROTO=none
USERCTL=no
HWADDR=00:0c:29:e2:0e:85
IPADDR=192.168.56.129
NETMASK=255.255.255.0
GATEWAY=192.168.56.130
IPV6INIT=no

2)DNS设置

#cat/etc/resolv.conf
;generatedby /sbin/dhclient-script
searchlocaldomain
nameserver192.168.73.2

5.在MysqL-server上测试是否能访问internet

[root@MysqL-server~] #pingwww.baidu.com
PINGwww.a.shifen.com(61.135.169.125)56(84)bytesofdata.
64bytesfrom61.135.169.125:icmp_seq=1ttl=127 time =5.89ms
64bytesfrom61.135.169.125:icmp_seq=2ttl=127 =9.49ms
64bytesfrom61.135.169.125:icmp_seq=3ttl=127 =6.14ms

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native