创建网桥
为了和宿主机有平等的网络层级 (能使用到上面的dhcp),可以通过构建网桥的办法来实现
配置
代码语言:javascript复制[root@kvm-demo network-scripts]# grep -v "^#" ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BRIDGE=br0
[root@kvm-demo network-scripts]# grep -v "^#" ifcfg-br0
DEVICE=br0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.234
NETMASK=255.255.255.0
GATEWAY=192.168.1.2
[root@kvm-demo network-scripts]#
重启网络
为了使配置生效,得重启网络
代码语言:javascript复制[root@kvm-demo network-scripts]# /etc/init.d/network restart ; ifup br0
Shutting down interface br0: [ OK ]
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface br0: Device br0 does not seem to be present, delaying initialization.
[FAILED]
Bringing up interface eth0: [ OK ]
Determining if ip address 192.168.1.234 is already in use for device br0...
[root@kvm-demo network-scripts]#
Note: 最好使用
/etc/init.d/network restart ; ifup br0
, 因为并不一定重启网络会带着 br0 一起重启,如果是远程操作,这个时候就有很大的风险与主机失联,这时原网卡没有配置ip,br0又没启动,会产生很大的麻烦,只能去机房通过服务器的console进行恢复
这时会多出一个br0的网桥
代码语言:javascript复制[root@kvm-demo network-scripts]# ifconfig
br0 Link encap:Ethernet HWaddr E8:39:35:53:4B:E9
inet addr:192.168.1.234 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::ea39:35ff:fe53:4be9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1399 errors:0 dropped:0 overruns:0 frame:0
TX packets:882 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:250070 (244.2 KiB) TX bytes:118534 (115.7 KiB)
eth0 Link encap:Ethernet HWaddr E8:39:35:53:4B:E9
inet6 addr: fe80::ea39:35ff:fe53:4be9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:67254 errors:0 dropped:0 overruns:0 frame:0
TX packets:39584 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13622758 (12.9 MiB) TX bytes:5178583 (4.9 MiB)
Interrupt:20 Memory:fb000000-fb020000
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)
virbr0 Link encap:Ethernet HWaddr 52:54:00:83:A4:A0
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 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@kvm-demo network-scripts]#