容器网络之网桥

Posted 会飞の鱼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了容器网络之网桥相关的知识,希望对你有一定的参考价值。

 

创建网桥

# brctl addbr mhc

绑定到物理网卡(网卡会失效)

# brctl addif mhc enp3s0

# ifconfig enp3s0 0.0.0.0

给网桥配置一个ip (启用了)

# ifconfig mhc 109.105.4.65

 

# ifconfig

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        

  inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255        

  inet6 fe80::42:f1ff:fe10:e3bc  prefixlen 64  scopeid 0x20<link>        

  ether 02:42:f1:10:e3:bc  txqueuelen 0  (Ethernet)        

  RX packets 59506  bytes 3109306 (2.9 MiB)        

  RX errors 0  dropped 0  overruns 0  frame 0        

  TX packets 100421  bytes 169871693 (162.0 MiB)        

  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        

  inet6 fe80::d556:c0ae:b9f6:b958  prefixlen 64  scopeid 0x20<link>        

  ether dc:fe:07:d6:10:67  txqueuelen 1000  (Ethernet)        

  RX packets 59147107  bytes 6300109859 (5.8 GiB)        

  RX errors 0  dropped 0  overruns 0  frame 0        

  TX packets 2979383  bytes 617716890 (589.1 MiB)       

  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 1  (Local Loopback)        

  RX packets 144962  bytes 11750064 (11.2 MiB)        

  RX errors 0  dropped 0  overruns 0  frame 0        

  TX packets 144962  bytes 11750064 (11.2 MiB)        

  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

mhc: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        

  inet 109.105.4.65  netmask 255.0.0.0  broadcast 109.255.255.255        

  inet6 fe80::defe:7ff:fed6:1067  prefixlen 64  scopeid 0x20<link>       

  ether dc:fe:07:d6:10:67  txqueuelen 1000  (Ethernet)        

  RX packets 2089  bytes 113670 (111.0 KiB)        

  RX errors 0  dropped 0  overruns 0  frame 0        

  TX packets 147  bytes 13274 (12.9 KiB)        

  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

 

# brctl show
bridge name bridge id  STP enabled interfaces
docker0  8000.0242f110e3bc no  veth879059f
mhc  8000.dcfe07d61067 no  enp3s0
virbr0  8000.525400eae708 yes  virbr0-nic

 

停用网桥(ifconfig 就看不见了)

# ifconfig mhc down

删除网桥

# brctl delbr mhc

以上是关于容器网络之网桥的主要内容,如果未能解决你的问题,请参考以下文章

云计算核心技术Docker教程:Docker使用网桥网络

11、Docker的网络功能-配置容器网桥

docker系列之网络配置

docker之容器网络篇

pipework配置docker网桥网络

Docker容器的网络管理和网络隔离