您好,登錄后才能下訂單哦!
解決兩宿主機(jī)容器之間的透明訪問,如不進(jìn)行優(yōu)化,容器之間的訪問,日志記錄為宿主機(jī)的IP地址。
1、安裝iptables-services組件
[root@test-nodes1 ~]# yum -y install iptables-services
[root@test-nodes1 ~]# systemctl start iptables
[root@test-nodes1 ~]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
-----------------------------------------------------------------------------------------------
2、把以下iptable記錄的偽裝轉(zhuǎn)向刪除
[root@test-nodes1 ~]# iptables-save |grep -i postrouting
:POSTROUTING ACCEPT [68:4098]
:KUBE-POSTROUTING - [0:0]
-A POSTROUTING -m comment --comment "kubernetes postrouting rules" -j KUBE-POSTROUTING
-A POSTROUTING -s 172.7.21.0/24 ! -o docker0 -j MASQUERADE #刪除此條
-A KUBE-POSTROUTING -m comment --comment "kubernetes service traffic requiring SNAT" -m mark --mark 0x4000/0x4000 -j MASQUERADE
-----------------------------------------------------------------------------------------------
3、刪除該記錄
[root@test-nodes1 ~]# iptables -t nat -D POSTROUTING -s 172.7.21.0/24 ! -o docker0 -j MASQUERADE
-----------------------------------------------------------------------------------------------
4、插入一條新的記錄(排除對(duì)172.7.0.0/16網(wǎng)絡(luò)訪問的偽裝)
[root@test-nodes1 ~]# iptables -t nat -I POSTROUTING -s 172.7.21.0/24 ! -d 172.7.0.0/16 ! -o docker0 -j MASQUERADE
-----------------------------------------------------------------------------------------------
5、查看是否生效
[root@test-nodes1 ~]# iptables-save |grep -i postrouting
:POSTROUTING ACCEPT [13:814]
:KUBE-POSTROUTING - [0:0]
-A POSTROUTING -s 172.7.21.0/24 ! -d 172.7.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -m comment --comment "kubernetes postrouting rules" -j KUBE-POSTROUTING
-A KUBE-POSTROUTING -m comment --comment "kubernetes service traffic requiring SNAT" -m mark --mark 0x4000/0x4000 -j MASQUERADE
-----------------------------------------------------------------------------------------------
6、刪除iptables上所有reject拒絕規(guī)則
[root@test-nodes1 ~]# iptables-save | grep -i reject
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
[root@test-nodes1 ~]# iptables -t filter -D INPUT -j REJECT --reject-with icmp-host-prohibited
[root@test-nodes1 ~]# iptables -t filter -D FORWARD -j REJECT --reject-with icmp-host-prohibited
[root@test-nodes1 ~]# iptables-save | grep -i reject
-----------------------------------------------------------------------------------------------
7、保存iptables規(guī)則
[root@test-nodes1 ~]# iptables-save > /etc/sysconfig/iptables
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。