docker之网络桥接的两种方式


第一种:直接敲命令方式配置
安装网桥管理工具包:bridge-utile
# yum install bridge-utils -y

1.先查看ip 是否有br0
ip a
2.
brctl show
3使用brctl命令删除网桥br0
brctl delbr br0

4关闭br0
ifconfig br0 down
5删除br0
brctl delbr br0

5在查看是否有
ip a

6.使用brctl命令添加网桥br0
brctl addbr br0
7. 使用brctl命令将em1网卡加入到 br0
brctl addif br0 em1

8.在查看 是否有br0
ip a
9.添加默认IP
ifconfig br0 192.168.3.49/24
添加默认路由
ifconfig em1 0.0.0.0

ip a
11.在添加默认网关
route add default gw 192.168.3.1
12.测试
ping 114.114.114.114

第二种:修改配置文件


1.修改配置文件
[root@compute5 ~]# cat /etc/sysconfig/network-scripts/ifcfg-em1
TYPE=Ethernet
BOOTPROTO=none
NAME=em1
DEVICE=em1
ONBOOT=yes

2.添加bro配置文件
[root@compute5 yong10_16]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.3.200
NETMASK=255.255.255.0
GATEWAY=192.168.3.1

#####pipework########
下载配置IP的工具,需要借助工具才能配置IP
# git clone https://github.com/jpetazzo/pipework

# cp pipework/pipework /usr/local/bin/


批量启动容器
镜像就是ssh
for i in {113..140}; do docker run -itd --network none --name test$i ssh;done
批量配置IP
for i in {113..140}; do pipework br0 test$i 192.168.3.$i/24@192.168.3.1;done


单个启动镜像
docker run -itd --network none --name test113 ssh
pipework br0 test 192.168.3.113/24@192.168.3.1

原文地址:https://www.cnblogs.com/zoulixiang/p/11690123.html