優(yōu)化內(nèi)核
echo 'net.ipv4.ip_forward = 1' >>/etc/sysctl.conf
echo 'net.ipv4.tcp_tw_recycle=1' >>/etc/sysctl.conf
echo 'net.ipv4.tcp_tw_reuse=1' >>/etc/sysctl.conf
ifdown eth0/1關(guān)閉網(wǎng)卡,
ifup eth0/1 開啟網(wǎng)卡
1.指定外網(wǎng)服務(wù)器:
管理機m01 外網(wǎng)ip eth0 10.0.0.61 內(nèi)網(wǎng) eth1 172.16.1.61
2.內(nèi)網(wǎng)服務(wù)器:
nfs01共享存儲服務(wù)器 內(nèi)網(wǎng) eth1 172.16.1.31
backup備份服務(wù)器 內(nèi)網(wǎng) eth1 172.16.1.41
數(shù)據(jù)庫db01/db02數(shù)據(jù)庫 內(nèi)網(wǎng) eth1 172.16.1.51/52
2.在可以上網(wǎng)的服務(wù)器上執(zhí)行此命令(m01)
iptables -t nat -A POSTROUTING -o eth0 -s 172.16.1.0/24 -j SNAT --to 10.0.0.61
-s 172.16.1.0/24
#172.16.1.0/24網(wǎng)段都通過10.0.0.61上外網(wǎng)
#-s 172.16.1.41 指定單個單個ip上外網(wǎng)
--to 10.0.0.61
#指定上外網(wǎng)的服務(wù)器ip
2.查看防火墻規(guī)則
iptables -L -n -t nat
[root@m01 /etc/ansible]# iptables -L -n -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
SNAT all -- 10.8.0.0/24 !10.8.0.0/24 to:10.0.0.61
SNAT all -- 172.16.1.0/24 0.0.0.0/0 to:10.0.0.61
3.在內(nèi)網(wǎng)服務(wù)器上添加路由條目
指定上外網(wǎng)的服務(wù)器的內(nèi)網(wǎng)ip
backu服務(wù)器:
[root@backup ~]# route add default gw 172.16.1.61
[root@backup ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.16.1.61 255.255.255.0 UG 0 0 0 eth1
...
nfs01服務(wù)器:
[root@nfs01 ~]# route add default gw 172.16.1.61
[root@nfs01 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.16.1.61 255.255.255.0 UG 0 0 0 eth1
db01數(shù)據(jù)庫:
[root@db01 ~]# route add default gw 172.16.1.61
[root@db01 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.16.1.61 255.255.255.0 UG 0 0 0 eth1
4.如果環(huán)境中有外網(wǎng)網(wǎng)卡,現(xiàn)在將它關(guān)閉掉
ifdown eth0 #外網(wǎng)網(wǎng)卡
5.添加開機自啟動
第一種方法:給內(nèi)網(wǎng)服務(wù)器的/etc/rc.d/rc.local添加執(zhí)行權(quán)限并將route條目加入開機自啟
#每一臺內(nèi)網(wǎng)服務(wù)器都添加執(zhí)行權(quán)限
chmod +x /etc/rc.d/rc.local
#每一臺內(nèi)網(wǎng)服務(wù)器追路由條目到自啟動
echo "/sbin/route add default gw 172.16.1.61" /etc/rc.d/rc.local
第二種方法:為內(nèi)網(wǎng)網(wǎng)卡配置文件中添加網(wǎng)關(guān)
看清內(nèi)網(wǎng)網(wǎng)卡是eth0還是eth1
echo 'GATEWAY=172.16.1.61' >>/etc/sysconfig/network-scripts/ifcfg-eth1
5.xshell遠程是連接不上的,我們可以用管理機通過ssh協(xié)議連接
如果在練習(xí)階段懶得配置單張內(nèi)網(wǎng)網(wǎng)卡的服務(wù)器,可以先把/sbin/fidown eth0放到/etc/rc.d/rc.local中
[root@m01 ~]# ssh 172.16.1.31
Last login: Mon Jun 24 11:09:24 2019 from 172.16.1.61
[11:12 root@nfs01 ~]#
[root@m01 /etc/ansible]# ssh 172.16.1.41
Last login: Mon Jun 24 11:09:08 2019 from 172.16.1.61
[11:12 root@backup ~]#
[root@m01 ~]# ssh 172.16.1.51
Last login: Mon Jun 24 11:09:32 2019 from 172.16.1.61
[11:12 root@db01 ~]#
backup備份服務(wù)器可以上外網(wǎng)了
給nfs
給db01數(shù)據(jù)庫


