Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Container communication between different virtual machines

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Make docker communication impossible in the virtual machine

The ip of web1 is 192.168.8.126

The ip of web2 is 192.168.8.127

The ip of mysql is 192.168.8.130

(1) modify docker bridge ip

Web1:

Ifconfig docker0 172.17.1.1 netmask 255.255.255.0

Service docker restart

Web2:

Ifconfig docker0 172.17.2.1 netmask 255.255.255.0

Service docker restart

Mysql:

Ifconfig docker0 172.17.3.1 netmask 255.255.255.0

Service docker restart

(2) add rout

# web1

Route add-net 172.17.3.0 netmask 255.255.255.0 gw 192.168.130

Iptables-t nat-F POSTROUTING

Iptables-t nat-A POSTROUTING-s 172.17.1.0 MASQUERAD 24!-d 172.17.0.0 MASQUERAD 16-j

# web2:

Route add-net 172.17.3.0 netmask 255.255.255.0 gw 192.168.130

Sudo iptables-t nat-F POSTROUTING

Sudo iptables-t nat-A POSTROUTING-s 172.17.2.0 MASQUERADE 24!-d 172.17.0.0 MASQUERADE 16-j

# mysql:

Route add-net 172.17.1.0 netmask 255.255.255.0 gw 192.168.126

Sudo iptables-t nat-F POSTROUTING

Sudo iptables-t nat-A POSTROUTING-s 172.17.3.0 MASQUERADE 24!-d 172.17.0.0 MASQUERADE 16-j

Route add-net 172.17.2.0 netmask 255.255.255.0 gw 192.168.127

Sudo iptables-t nat-F POSTROUTING

Sudo iptables-t nat-A POSTROUTING-s 172.17.3.0 MASQUERADE 24!-d 172.17.0.0 MASQUERADE 16-j

(3) testing

In the container on the mysql host, ping web1 and web2:

Ping 192.168.8.126

Ping 192.168.8.127

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report