模拟搭建docker桥接网络
本篇文章模拟docker桥接网络的搭建,以加深对其网络模型的理解.涉及到的知识:iptables,linux bridge,veth pair,linux namespace,unshare,nsenter等.
一.搭建图
二.创建网桥
1.安装brctl命令
yum install bridge-utils -y
2.创建网桥并设置ip
#创建网桥 命名为br01
brctl addif br01
#网桥设置ip网段
ip addr add 172.20.0.1/16 dev br0
#启动网桥
ip link set br0 up
#使用ifconfig命令验证如下
[root@localhost ~]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.20.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::a4c9:9fff:fe86:ab97 prefixlen 64 scopeid 0x20<link>
ether a6:c9:9f:86:ab:97 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14 bytes 1172 (1.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.101 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::ba99:d1d7:2105:baf7 prefixlen 64 scopeid 0x20<link>
inet6 fe80::ef4c:a887:b784:7528 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:b6:88:5e txqueuelen 1000 (Ethernet)
RX packets 4189 bytes 348799 (340.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3067 bytes 367986 (359.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 40 bytes 3520 (3.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets