bridge veth netns
1,创建br0
2,配置br0 网络,并启动
3,创建nns1 和nns2 的网络命名空间
4,创建veth对(veth10@veth11 veth20@veth21)
5,将veth中的veth10 veth20 加入到br0中
6,将veth中的veth11移动到nns1中,并配置ip,并启动
7,将veth中的veth21移动到nns2中,并配置ip,并启动
8,检查网络的连通性(nns1—br0;nns2—br0,nns1–nns2)
最终拓扑图
1,创建br0
[root@k8s-node1 ~]# brctl addbr br0
2,配置br0 网络,并启动
[root@k8s-node1 ~]# ip address add 172.16.0.1/16 dev br0
[root@k8s-node1 ~]# ip link set br0 up
[root@k8s-node1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:46:24:dd brd ff:ff:ff:ff:ff:ff
inet 192.168.0.61/24 brd 192.168.0.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe46:24dd/64 scope link
valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether 52:c6:80:bd:93:fa brd ff:ff:ff:ff:ff:ff
inet 172.16.0.1/16 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::50c6:80ff:febd:93fa/64 scope link
valid_lft forever preferred_lft forever
[root@k8s-node1 ~]#
3,创建nns1 和nns2 的网络命名空间
[root@k8s-node1 ~]# ip netns add nns1
[root@k8s-node1 ~]# ip netns add nns2
[root@k8s-node1 ~]# ip netns list
nns2
nns1
4,创建veth对(veth10@veth11 veth20@veth21)
[root@k8s-node1 ~]# ip link add veth10 type veth peer name veth11
[root@k8s-node1 ~]# ip link add veth20 type veth peer name veth21
[root@k8s-node1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:46:24:dd brd ff:ff:ff:ff:ff:ff
inet 192.168.0.61/24 brd 192.168.0.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe46:24dd/64 scope link
valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether 52:c6:80:bd:93:fa brd ff:ff:ff:ff:ff:ff
inet 172.16.0.1/16 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::50c6:80ff:febd:93fa/64 scope link
valid_lft forever preferred_lft forever
4: veth11@veth10: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether f2:c6:77:bb:5d:01 brd ff:ff:ff:ff:ff:ff
5: veth10@veth11: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 1a:9c:72:32:20:7f brd ff:ff:ff:ff:ff:ff
6: veth21@veth20: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 22:5e:a1:ac:42:7b brd ff:ff:ff:ff:ff:ff
7: veth20@veth21: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether d2:d1:2f:b5:d4:aa brd ff:ff:ff:ff:ff:ff
5,将veth中的veth10 veth20 加入到br0中
[root@k8s-node1 ~]# brctl addif br0 veth10
[root@k8s-node1 ~]# brctl addif br0 veth20
[root@k8s-node1 ~]# ip link set veth10 up
[root@k8s-node1 ~]# ip link set veth20 up
[root@k8s-node1 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.1a9c7232207f no veth10
veth20
6,将veth中的veth11移动到nns1中,并配置ip,并启动
[root@k8s-node1 ~]# ip link set dev veth11 netns nns1
[root@k8s-node1 ~]# ip netns exec nns1 ip address add 172.16.0.10/16 dev veth11
[root@k8s-node1 ~]# ip netns exec nns1 ip link set veth11 up
[root@k8s-node1 ~]# ip netns exec nns1 ip a
1: lo: 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
4: veth11@if5: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default qlen 1000
link/ether f2:c6:77:bb:5d:01 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.16.0.10/16 scope global veth11
valid_lft forever preferred_lft forever
7,将veth中的veth21移动到nns2中,并配置ip,并启动
[root@k8s-node1 ~]# ip link set dev veth11 netns nns1
[root@k8s-node1 ~]# ip netns exec nns1 ip address add 172.16.0.10/16 dev veth11
[root@k8s-node1 ~]# ip netns exec nns1 ip link set veth11 up
[root@k8s-node1 ~]# ip netns exec nns1 ip a
1: lo: 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
4: veth11@if5: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default qlen 1000
link/ether f2:c6:77:bb:5d:01 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.16.0.10/16 scope global veth11
valid_lft forever preferred_lft forever
[root@k8s-node1 ~]# ip link set dev veth21 netns nns2
[root@k8s-node1 ~]# ip netns exec nns2 ip address add 172.16.0.21/16 dev veth21
[root@k8s-node1 ~]# ip netns exec nns2 ip link set veth21 up
[root@k8s-node1 ~]# ip netns exec nns2 ip a
1: lo: 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
6: veth21@if7: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default qlen 1000
link/ether 22:5e:a1:ac:42:7b brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.16.0.21/16 scope global veth21
valid_lft forever preferred_lft forever
8,检查网络的连通性(nns1—br0;nns2—br0,nns1–nns2)
[root@k8s-node1 ~]# ip netns exec nns2 ping 172.16.0.1
PING 172.16.0.1 (172.16.0.1) 56(84) bytes of data.
64 bytes from 172.16.0.1: icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from 172.16.0.1: icmp_seq=2 ttl=64 time=0.081 ms
— 172.16.0.1 ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 1014ms
rtt min/avg/max/mdev = 0.040/0.060/0.081/0.021 ms
[root@k8s-node1 ~]# ip netns exec nns2 ping 172.16.0.10
PING 172.16.0.10 (172.16.0.10) 56(84) bytes of data.
64 bytes from 172.16.0.10: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 172.16.0.10: icmp_seq=2 ttl=64 time=0.134 ms
64 bytes from 172.16.0.10: icmp_seq=3 ttl=64 time=0.100 ms
— 172.16.0.10 ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2008ms
rtt min/avg/max/mdev = 0.045/0.093/0.134/0.036 ms
[root@k8s-node1 ~]# ip netns exec nns1 ping 172.16.0.20
PING 172.16.0.20 (172.16.0.20) 56(84) bytes of data.
— 172.16.0.20 ping statistics —
6 packets transmitted, 0 received, 100% packet loss, time 5022ms
[root@k8s-node1 ~]# ip netns exec nns2 ip a
1: lo: 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
6: veth21@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 22:5e:a1:ac:42:7b brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.16.0.21/16 scope global veth21
valid_lft forever preferred_lft forever
inet6 fe80::205e:a1ff:feac:427b/64 scope link
valid_lft forever preferred_lft forever
[root@k8s-node1 ~]# ip netns exec nns1 ping 172.16.0.21
PING 172.16.0.21 (172.16.0.21) 56(84) bytes of data.
64 bytes from 172.16.0.21: icmp_seq=1 ttl=64 time=0.030 ms
64 bytes from 172.16.0.21: icmp_seq=2 ttl=64 time=0.154 ms