Centos 6 Docker配置橋接網路

來源:互聯網
上載者:User

為了使本網中的機器和Docker容器更方便的通訊,我們經常會有將Docker容器配置到和主機同一網段的需求。這個需求其實很容易實現,我們只要將Docker容器和宿主機的網卡橋接起來,再給Docker容器配上IP就可以了。

Centos 6按照下面的方法操作(6與7的操作有所不同)

[root@localhost ~]# cd /etc/sysconfig/network-scripts/[root@localhost network-scripts]# lsifcfg-eth0   ifdown-ib    ifdown-ppp     ifup-aliases  ifup-ipv6   ifup-ppp       init.ipv6-globalifcfg-lo     ifdown-ippp  ifdown-routes  ifup-bnep     ifup-isdn   ifup-routes    net.hotplugifdown       ifdown-ipv6  ifdown-sit     ifup-eth      ifup-plip   ifup-sit       network-functionsifdown-bnep  ifdown-isdn  ifdown-tunnel  ifup-ib       ifup-plusb  ifup-tunnel    network-functions-ipv6ifdown-eth   ifdown-post  ifup           ifup-ippp     ifup-post   ifup-wireless[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-br0
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
[root@localhost network-scripts]# vi ifcfg-eth0DEVICE=eth0HWADDR=00:0C:29:DB:B2:28TYPE=EthernetUUID=b2268aab-fa2e-49e9-bd67-2572f29e5790ONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=staticIPADDR=192.168.1.179NETMASK=255.255.255.0GATEWAY=192.168.1.1DNS1=114.114.114.114DNS2=8.8.4.4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14

增加BRIDGE=br0,刪除IPADDR、NETMASK、GATEWAY、DNS

DEVICE=eth0HWADDR=00:0C:29:DB:B2:28TYPE=EthernetUUID=b2268aab-fa2e-49e9-bd67-2572f29e5790ONBOOT=yesBRIDGE=br0BOOTPROTO=none#IPADDR=192.168.1.179#NETMASK=255.255.255.0#GATEWAY=192.168.1.1#DNS1=114.114.114.114#DNS2=8.8.4.4
1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13

儲存退出

[root@localhost network-scripts]# vi ifcfg-br0DEVICE=eth0HWADDR=00:0C:29:DB:B2:28TYPE=EthernetUUID=b2268aab-fa2e-49e9-bd67-2572f29e5790ONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=staticIPADDR=192.168.1.179NETMASK=255.255.255.0GATEWAY=192.168.1.1DNS1=114.114.114.114DNS2=8.8.4.4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14

修改DEVICE為br0,Type為Bridge,把eth0的網路設定設定到這裡來

DEVICE=br0TYPE=BridgeONBOOT=yesBOOTPROTO=staticIPADDR=192.168.1.179NETMASK=255.255.255.0GATEWAY=192.168.1.1DNS1=114.114.114.114DNS2=8.8.4.4
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10

儲存退出

[root@localhost network-scripts]# service network restart
1 1

這一步我出現了問題,不過重啟宿主機後就OK了。

[root@localhost ~]# ifconfigbr0       Link encap:Ethernet  HWaddr 00:0C:29:DB:B2:28          inet addr:192.168.1.179  Bcast:192.168.1.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fedb:b228/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:137 errors:0 dropped:0 overruns:0 frame:0          TX packets:93 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0          RX bytes:13745 (13.4 KiB)  TX bytes:11095 (10.8 KiB)docker0   Link encap:Ethernet  HWaddr C6:01:70:AF:C6:E4          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0          inet6 addr: fe80::c401:70ff:feaf:c6e4/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0          RX bytes:0 (0.0 b)  TX bytes:468 (468.0 b)eth0      Link encap:Ethernet  HWaddr 00:0C:29:DB:B2:28          inet6 addr: fe80::20c:29ff:fedb:b228/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:137 errors:0 dropped:0 overruns:0 frame:0          TX packets:101 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000          RX bytes:15663 (15.2 KiB)  TX bytes:11959 (11.6 KiB)lo        Link encap:Local Loopback          inet addr:127.0.0.1  Mask:255.0.0.0          inet6 
相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。