[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=:0C:::A2:
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--x86 bash
4278a68ee82a.....
//没有网络
[root@4278a68ee82a /]# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 b) TX bytes: (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... ########################################### [%]
:iproute ########################################### [%] //配置一个新的ip,只要是和br0同网段,且没有被用过
[root@localhost ~]# pipework br0 fl 192.168.216.135/
[root@localhost ~]# docker exec -it fl bash
[root@4278a68ee82a /]# ifconfig
eth1 Link encap:Ethernet HWaddr E2:9B:::C2:
inet addr:192.168.216.135 Bcast:192.168.216.255 Mask:255.255.255.0
inet6 addr: fe80::e09b:98ff:fe70:c205/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (468.0 b) TX bytes: (510.0 b) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 b) TX bytes: (0.0 b) /* 这一步不是特别重要,知道就好 */
//ping的通网关,但是还是不能上网,因为还没有配置网关和上网的路由
[root@4278a68ee82a /]# ping 192.168.216.2
PING 192.168.216.2 (192.168.216.2) () bytes of data.
bytes from 192.168.216.2: icmp_seq= ttl= time=2.07 ms
bytes from 192.168.216.2: icmp_seq= ttl= time=0.563 ms
^C
--- 192.168.216.2 ping statistics ---
packets transmitted, received, % 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 /* 这就完成了 */