标签:col 模拟 default 设置 space ali inf lis time
单机版多容器实例网络交互原理
添加两个namespace
[root@host-2 ~]# ip netns add test1 [root@host-2 ~]# ip netns add test2
查看添加状况
[root@host-2 ~]# ip netns list test2 test1 [root@host-2 ~]# ip netns exec test1 ip addr 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 [root@host-2 ~]# ip netns exec test2 ip addr 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 PS:这里可以看到namespace还没有mac地址
添加一对虚拟网卡
[root@host-2 ~]# ip link add veth-test1 type veth peer name veth-test2
对虚拟网卡与namespace做捆绑
[root@host-2 ~]# ip link set veth-test1 netns test1 [root@host-2 ~]# ip link set veth-test2 netns test2
对namespace中的虚拟网卡做地址设定,并激活
[root@host-2 ~]# ip netns exec test1 ip addr add 10.1.1.100/24 dev veth-test1 [root@host-2 ~]# ip netns exec test2 ip addr add 10.1.1.200/24 dev veth-test2 [root@host-2 ~]# ip netns exec test1 ip link set dev veth-test1 up [root@host-2 ~]# ip netns exec test2 ip link set dev veth-test2 up
查看设置的状况
[root@host-2 ~]# ip netns exec test1 ip addr 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 9: veth-test1@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether f2:c2:eb:2b:08:d6 brd ff:ff:ff:ff:ff:ff link-netnsid 1 inet 10.1.1.100/24 scope global veth-test1 valid_lft forever preferred_lft forever inet6 fe80::f0c2:ebff:fe2b:8d6/64 scope link valid_lft forever preferred_lft forever [root@host-2 ~]# ip netns exec test2 ip addr 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 8: veth-test2@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 5e:06:df:2b:3d:fe brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.1.1.200/24 scope global veth-test2 valid_lft forever preferred_lft forever inet6 fe80::5c06:dfff:fe2b:3dfe/64 scope link valid_lft forever preferred_lft forever
测试实验结果
[root@host-2 ~]# ip netns exec test1 ping 10.1.1.200 PING 10.1.1.200 (10.1.1.200) 56(84) bytes of data. 64 bytes from 10.1.1.200: icmp_seq=1 ttl=64 time=0.141 ms ^C --- 10.1.1.200 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.141/0.141/0.141/0.000 ms
标签:col 模拟 default 设置 space ali inf lis time
原文地址:https://www.cnblogs.com/guge-94/p/11082108.html