docker配置橋接網絡


[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-br0
[root@localhost 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

[root@localhost 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

[root@localhost 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...
                                                      [確定]
    

 

操作遇到以下問題:!!!!

[root@localhost network-scripts]# service network restart
/*

        這里如果10秒以上沒有反應,那就需要去虛擬機檢查。

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

        --〉 ping 網關 (不通,則配置有問題) 

    --〉 (通) 檢查ifcfg-eth0 ifcfg-br0是否寫對
*/
    

 

[root@localhost network-scripts]# yum install -y git
[root@localhost network-scripts]# git clone https://github.com/jpetazzo/pipework
[root@localhost network-scripts]# cp pipework/pipework /usr/local/bin/
[root@localhost network-scripts]# cd
//用centos6來弄一個容器
[root@localhost ~]# docker run -itd --net=none --name=ff centos-6-x86 bash
4278a68ee82a.....
//沒有網絡
[root@4278a68ee82a /]# 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)
[root@4278a68ee82a /]# exit

//再次進入宿主機    
[root@localhost ~]# 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同網段,且沒有被用過
[root@localhost ~]# pipework br0 fl 192.168.216.135/24
[root@localhost ~]# docker exec -it fl bash
[root@4278a68ee82a /]# 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的通網關,但是還是不能上網,因為還沒有配置網關和上網的路由    
[root@4278a68ee82a /]# 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
[root@4278a68ee82a /]# ping www.qq.com
connect: Network is unreachable

/* 這就完成了 */

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM