大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
解决两宿主机容器之间的透明访问,如不进行优化,容器之间的访问,日志记录为宿主机的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记录的伪装转向删除
[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、插入一条新的记录(排除对172.7.0.0/16网络访问的伪装)
[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拒绝规则
[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规则
[root@test-nodes1 ~]# iptables-save > /etc/sysconfig/iptables