docker中不同容器之间互通

先创建两个虚拟命名空间

root@ubuntu22:~# ip netns add wkz1

root@ubuntu22:~# ip netns add wkz2

查看是否开启

root@ubuntu22:~#ip netns exec wkz1 ip a

root@ubuntu22:~#ip netns exec wkz2 ip a

创建网络设备对命名空间添加网卡

root@ubuntu22:~# ip link add veth0 type veth peer name veth1

root@ubuntu22:~# ip link add veth2 type veth peer name veth3

给虚拟空间指定网卡

root@ubuntu22:~# ip link set veth1 netns wkz1

root@ubuntu22:~# ip link set veth3 netns wkz2

给虚拟空间配置IP 网关 本地ip

root@ubuntu22:~# ip netns exec wkz1 ifconfig veth1 5.5.5.5/24 up

root@ubuntu22:~# ip netns exec wkz2 ifconfig veth3 9.9.9.9/24 up

查询一下

root@ubuntu22:~# ip netns exec wkz1 ip a

root@ubuntu22:~# ip netns exec wkz1 route add default gw 5.5.5.1

root@ubuntu22:~# ip netns exec wkz2 route add default gw 9.9.9.1

root@ubuntu22:~# ifconfig veth2 9.9.9.1/24

root@ubuntu22:~# ifconfig veth0 5.5.5.1/24

猜你喜欢

转载自blog.csdn.net/weixin_53053517/article/details/130005092