网卡配置文件 及 bridge的静态配置
centos7 Bridge配置
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# vim ifcfg-ens33
- TYPE="Ethernet"
- BOOTPROTO="static"
- DEFROUTE="yes"
- IPV4_FAILURE_FATAL="no"
- IPV6INIT="yes"
- IPV6_AUTOCONF="yes"
- IPV6_DEFROUTE="yes"
- IPV6_FAILURE_FATAL="no"
- IPV6_ADDR_GEN_MODE="stable-privacy"
- NAME="ens33"
- UUID="44dad4b3-8c0b-4cd7-aa95-8d05168b0bcb"
- DEVICE="ens33"
- IPV6_PEERDNS="yes"
- IPV6_PEERROUTES="yes"
- IPV6_PRIVACY="no"
- ONBOOT=yes
- #IPADDR=192.168.1.151
- #GATEWAY=192.168.1.1
- #PREFIX=24
- #DNS1=114.114.114.114
- BRIDGE=br0
[[email protected] network-scripts]# vim ifcfg-br0
- TYPE=Bridge
- BOOTPROTO=static
- DEFROUTE=yes
- PEERDNS=yes
- PEERROUTES=yes
- IPV4_FAILURE_FATAL=no
- IPADDR=192.168.1.151
- GATEWAY=192.168.1.1
- PREFIX=24
- DNS1=114.114.114.114
- DEVICE=br0
- ONBOOT=yes
注意: TYPE 为 Bridge,不是Ethernet
BOOTPROTO 为 static,需要添加 IPADD=XXXX 配置IP地址及网关
DEVICE 为设备名称
以上三项为必有项。
ONBOOT 系统启动时,是否启动。yes 启动,no 不启动。 no时需要手动启动 ifup br0
创建好网桥配置文件后,重启网络或br0
# service network restart
或
#ifup br0
最好使用后者,前者会重启所有网络,由于其他网卡配置文件不正确,导致重启失败。
通过 命令查看 网桥是否存在:
#ip a
或 # ifconfig
通过 brctl show 查看网卡是否挂载到 网桥上。
如果没有brctl 命令
yum install bridge-utils -y
[[email protected] network-scripts]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000c295ce379 no ens33 veth1pl4004 docker0 8000.02425b035439 no vethc4a2cc5
pipework 安装
[[email protected] ~]# yum install git -y
[[email protected] ~]# git clone https://github.com/jpetazzo/pipework.git
[[email protected] ~]# cp -rp pipework/pipework /usr/local/bin/
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lys/v1.0 latest efd998bd6817 2 years ago 296.9 MB
[[email protected] ~]#docker run -itd --name="192-168-1-152" lys/v1.0 bin/bash
[[email protected] ~]# pipework br0 192-168-1-152 192.168.1.152/[email protected]
[[email protected] ~]# docker exec -it ce8d6be241cb bin/bash
bash-4.1# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 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 6: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff inet 172.17.0.3/16 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::42:acff:fe11:3/64 scope link valid_lft forever preferred_lft forever 9: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP qlen 1000 link/ether 06:e8:83:82:45:5b brd ff:ff:ff:ff:ff:ff inet 192.168.1.152/24 brd 192.168.1.255 scope global eth1 valid_lft forever preferred_lft forever inet6 fe80::4e8:83ff:fe82:455b/64 scope link valid_lft forever preferred_lft forever
此时你会看到容器中新增加了一块网卡