centos 安装网桥管理工具以及ifconfig:
[root ~]# yum install bridge-utils
[root ~]# yum search ifconfig
已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.nwsuaf.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.tuna.tsinghua.edu.cn ================================== 匹配:ifconfig ================================== net-tools.x86_64 : Basic networking tools [root ~]# yum install net-tools.x86_64 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.nwsuaf.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.tuna.tsinghua.edu.cn 正在解决依赖关系 --> 正在检查事务 ---> 软件包 net-tools.x86_64.0.2.0-0.24.20131004git.el7 将被 安装 --> 解决依赖关系完成依赖关系解决
====================================================================================
Package 架构 版本 源 大小 ==================================================================================== 正在安装: net-tools x86_64 2.0-0.24.20131004git.el7 base 306 k事务概要
==================================================================================== 安装 1 软件包总下载量:306 k
安装大小:918 k Is this ok [y/d/N]: y Downloading packages: net-tools-2.0-0.24.20131004git.el7.x86_64.rpm | 306 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1 验证中 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1已安装:
net-tools.x86_64 0:2.0-0.24.20131004git.el7完毕!
然后可以查看网桥连接情况
(在此之前已经启动了一个docker容器:
root@9d04fa294f9f:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet) RX packets 4764 bytes 16630698 (16.6 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3394 bytes 187733 (187.7 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 )
[root ~]# brctl show
bridge name bridge id STP enabled interfaces docker0 8000.02421eb87b8e no veth7e77e4cveth7e77e4c: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::588d:28ff:febe:c60e prefixlen 64 scopeid 0x20<link> ether 5a:8d:28:be:c6:0e txqueuelen 0 (Ethernet) RX packets 3394 bytes 187733 (183.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4764 bytes 16630698 (15.8 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 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:1eff:feb8:7b8e prefixlen 64 scopeid 0x20<link> ether 02:42:1e:b8:7b:8e txqueuelen 0 (Ethernet) RX packets 3394 bytes 140217 (136.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4764 bytes 16630698 (15.8 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0通过ifconfig查看宿主机的docker0的网络设备,docker守护进程就是通过docker0为docker的容器提供网络连接的各种服务。
docker0是Linux虚拟网桥。
Linux虚拟网桥的特点:
- 可以设置IP地址
- 相当于拥有一个隐藏的虚拟网卡
docker守护进程在一个容器启动时,实际上它要创建网络连接的两端。一端是在容器中的网络设备,而另一端是在运行docker守护进程的主机上打开一个名为veth*的一个接口,用来实现docker这个网桥与容器的网络通信。