docker配置桥接网络

Posted Frankiee

tags:

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

[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-eth0 ifcfg-br0
[[email protected] network-scripts]# vi ifcfg-eth0
//改成这样
DEVICE=eth0
HWADDR=00:0C:29:06:A2:35
TYPE=Ethernet
UUID=34b706cc-aa46-4be3-91fc-d1f48c301f23
ONBOOT=yes
BRIDGE=br0
NM_CONTROLLED=yes
BOOTPROTO=static

[[email protected] network-scripts]# vi ifcfg-br0
//改成这样
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.216.131
NETMASK=255.255.255.0
GATEWAY=192.168.216.2
DNS=8.8.8.8

[[email protected] network-scripts]# service network restart
正在关闭接口 eth0: bridge br0 does not exist!
                                                      [确定]
关闭环回接口:                                        [确定]
弹出环回接口:                                        [确定]
弹出界面 eth0:                                       [确定]
弹出界面 br0: Determining if ip address 192.168.216.131 is already in use for device br0...
                                                      [确定]
    

 

操作遇到以下问题:!!!!

[[email protected] network-scripts]# service network restart
/*

        这里如果10秒以上没有反应,那就需要去虚拟机检查。

        登陆--〉 ifconfig 查看eth0是否存在  --〉 ping www.baidu.com (是否通)

        --〉 ping 网关 (不通,则配置有问题) 

    --〉 (通) 检查ifcfg-eth0 ifcfg-br0是否写对
*/
    

 

[[email protected] network-scripts]# yum install -y git
[[email protected] network-scripts]# git clone https://github.com/jpetazzo/pipework
[[email protected] network-scripts]# cp pipework/pipework /usr/local/bin/
[[email protected] network-scripts]# cd
//用centos6来弄一个容器
[[email protected] ~]# docker run -itd --net=none --name=ff centos-6-x86 bash
4278a68ee82a.....
//没有网络
[[email protected] /]# ifconfig
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
[[email protected] /]# exit

//再次进入宿主机    
[[email protected] ~]# rpm -Uvh https://repos.fedorapeople.org/openstack/EOL/openstack-grizzly/epel-6/iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm
Retrieving https://repos.fedorapeople.org/openstack/EOL/openstack-grizzly/epel-6/iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm
warning: /var/tmp/rpm-tmp.QuEQJe: Header V4 RSA/SHA1 Signature, key ID d97b3247: NOKEY
Preparing...                ########################################### [100%]
   1:iproute                ########################################### [100%]

//配置一个新的ip,只要是和br0同网段,且没有被用过
[[email protected] ~]# pipework br0 fl 192.168.216.135/24
[[email protected] ~]# docker exec -it fl bash
[[email protected] /]# ifconfig
eth1      Link encap:Ethernet  HWaddr E2:9B:98:70:C2:05
          inet addr:192.168.216.135  Bcast:192.168.216.255  Mask:255.255.255.0
          inet6 addr: fe80::e09b:98ff:fe70:c205/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:468 (468.0 b)  TX bytes:510 (510.0 b)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

/* 这一步不是特别重要,知道就好 */
//ping的通网关,但是还是不能上网,因为还没有配置网关和上网的路由    
[[email protected] /]# ping 192.168.216.2
PING 192.168.216.2 (192.168.216.2) 56(84) bytes of data.
64 bytes from 192.168.216.2: icmp_seq=1 ttl=128 time=2.07 ms
64 bytes from 192.168.216.2: icmp_seq=2 ttl=128 time=0.563 ms
^C
--- 192.168.216.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1498ms
rtt min/avg/max/mdev = 0.563/1.319/2.075/0.756 ms
[[email protected] /]# ping www.qq.com
connect: Network is unreachable

/* 这就完成了 */

 

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

centos 桥接配置 设置网络代理 lnmp搭建

docker配置桥接网络

网络桥接

虚拟机网络配置,桥接模式和NAT模式

vmware在桥接模式下配置centos7网络

centos7网络桥接模式下配置