標籤:雙網卡 iptables nat
實現方式:通過設定iptables的nat規則,使內網伺服器可以訪問Internet
1.系統內容:
[[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.準備兩台虛擬機器
==========================================================================主機名稱 外網 內網Web-Lnmp02 eth0:192.168.73.171 eth1:192.168.56.130MySQL-server eth0:192.168.56.129DNS:192.168.73.2註:內網使用僅主機模式串連,手動設定IP 外網使用NAT模式串連,使用dhcp動態擷取的IP==========================================================================
3.配置Web-Lnmp02伺服器
1)開啟IP轉寄功能
[[email protected] network-scripts]# echo "net.ipv4.ip_forward = 1">>/etc/sysctl.con [[email protected] network-scripts]# sysctl -p
2)配置iptables
[[email protected] ~]# iptables -F[[email protected] ~]# iptables -P INPUT ACCEPT[[email protected] ~]# iptables -P FORWARD ACCEPT [[email protected] ~]# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE [[email protected] ~]# /etc/init.d/iptables save[[email protected] ~]# /etc/init.d/iptables restart說明: iptables -F #清除原有的filter有中的規則 iptables -t nat -F #清除原有的nat表中的規則 iptables -P FORWARD ACCEPT #預設允許IP轉寄
4.配置MySQL-server
1)IP設定
[[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設定
[[email protected] ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-scriptsearch localdomainnameserver 192.168.73.2
5.在MySQL-server上測試是否能訪問internet
[[email protected] ~]# ping www.baidu.comPING www.a.shifen.com (61.135.169.125) 56(84) 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
CentOS 6.6下雙網卡共用上網配置