Implementation: By setting iptables NAT rules, the intranet server can access the Internet
1. System Environment:
[Email protected] ~]# cat/etc/redhat-release CentOS release 6.6 (Final) [[email protected] ~]# uname-r2.6.32-504.el6.x86 _64[[email protected] ~]# uname-mx86_64
2. Prepare two virtual machines
========================================================================== host name outside network intranet WEB-LNM P02 eth0:192.168.73.171 Eth1:192.168.56.130mysql-server eth0:192.168.56.129dns:192 .168.73.2 Note: Intranet uses only host mode connection, manually set IP extranet using NAT mode connection, using DHCP dynamically acquired ip======================================================== ==================
3. Configuring the WEB-LNMP02 Server
1) Turn on the IP forwarding function
[Email protected] network-scripts]# echo "Net.ipv4.ip_forward = 1" >>/etc/sysctl.con [[email protected] network-scripts]# sysctl-p
2) configuration Iptables
[[email protected] ~]# iptables-f[[email protected] ~]# iptables-p INPUT accept[[email protected] ~]# iptables-p Forwar D ACCEPT [email protected] ~]# iptables-t nat-a postrouting-o eth0-j Masquerade [[email protected] ~]#/ETC/INIT.D/IP Tables Save[[email protected] ~]#/etc/init.d/iptables Restart Description: iptables-f #清除原有的filter有中的规则 iptables-t nat-f #清除原 There are rules in the NAT table Iptables-p FORWARD ACCEPT #缺省允许IP转发
4. Configure Mysql-server
1) IP Settings
[Email protected] ~]# cat/etc/sysconfig/network-scripts/ifcfg-eth0device=eth0type=ethernetonboot=yesnm_ controlled=yesbootproto=noneuserctl=nohwaddr=00:0c:29:e2:0e:85ipaddr=192.168.56.129netmask= 255.255.255.0gateway=192.168.56.130ipv6init=no
2) DNS Settings
[Email protected] ~]# cat/etc/resolv.conf; Generated By/sbin/dhclient-scriptsearch localdomainnameserver 192.168.73.2
5. Test for Internet access on Mysql-server
[Email protected] ~]# ping Www.baidu.comPING www.a.shifen.com (61.135.169.125), bytes of data.64 bytes from 61.135. 169.125:icmp_seq=1 ttl=127 time=5.89 ms64 bytes from 61.135.169.125:icmp_seq=2 ttl=127 time=9.49 ms64 bytes from 61.135. 169.125:icmp_seq=3 ttl=127 time=6.14 ms
Dual-NIC shared Internet configuration under CentOS 6.6