场景说明:KVM虚拟机之前没有设置为Bridge模式,然后就直接创建虚拟机了(当时网卡模式选择的为default),后来调整KVM网卡模式为Bridge后,虚拟机没法正常联网。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@node160 ~]
# virsh shudown CentOS-7.3-X86_64
[root@node160 ~]
# virsh edit CentOS-7.3-X86_64
将xml配置文件中的:
<interface
type
=
'network'
>
<mac address=
'52:54:00:e4:7c:77'
/>
<
source
network=
'default'
/>
<model
type
=
'virtio'
/>
<address
type
=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x03'
function
=
'0x0'
/>
<
/interface
>
修改为:
<interface
type
=
'bridge'
>
<mac address=
'52:54:00:e4:7c:77'
/>
<
source
bridge=
'br0'
/>
<model
type
=
'virtio'
/>
<address
type
=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x03'
function
=
'0x0'
/>
<
/interface
>
|
由于kvm虚拟机使用的是bridge模式,可以把virbr0接口(即NAT方式里面的default虚拟网络)删除
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
[root@node160 ~]
# ip add list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link
/loopback
00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1
/8
scope host lo
valid_lft forever preferred_lft forever
inet6 ::1
/128
scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link
/ether
00:0c:29:14:2b:9a brd ff:ff:ff:ff:ff:ff
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
link
/ether
52:54:00:9f:ad:48 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1
/24
brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
link
/ether
52:54:00:9f:ad:48 brd ff:ff:ff:ff:ff:ff
7: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link
/ether
00:0c:29:14:2b:9a brd ff:ff:ff:ff:ff:ff
inet 10.10.10.160
/24
brd 10.10.10.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe14:2b9a
/64
scope link
valid_lft forever preferred_lft forever
8: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 1000
link
/ether
fe:54:00:71:7b:aa brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fe71:7baa
/64
scope link
valid_lft forever preferred_lft forever
10: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 1000
link
/ether
fe:54:00:e4:7c:77 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fee4:7c77
/64
scope link
valid_lft forever preferred_lft forever
[root@node160 ~]
# virsh net-list --all
Name State Autostart Persistent
----------------------------------------------------------
default active
yes
yes
[root@node160 ~]
# brctl show
bridge namebridge idSTP enabledinterfaces
br08000.000c29142b9anoeth0
vnet0
vnet1
virbr08000.5254009fad48yesvirbr0-nic
[root@node160 ~]
# virsh net-destroy default
Network default destroyed
[root@node160 ~]
# virsh net-undefine default
Network default has been undefined
|
配置完成后,再次查看网卡信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@node160 ~]
# ip add list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link
/loopback
00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1
/8
scope host lo
valid_lft forever preferred_lft forever
inet6 ::1
/128
scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link
/ether
00:0c:29:14:2b:9a brd ff:ff:ff:ff:ff:ff
7: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link
/ether
00:0c:29:14:2b:9a brd ff:ff:ff:ff:ff:ff
inet 10.10.10.160
/24
brd 10.10.10.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe14:2b9a
/64
scope link
valid_lft forever preferred_lft forever
8: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 1000
link
/ether
fe:54:00:71:7b:aa brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fe71:7baa
/64
scope link
valid_lft forever preferred_lft forever
10: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 1000
link
/ether
fe:54:00:e4:7c:77 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fee4:7c77
/64
scope link
valid_lft forever preferred_lft forever
|
本文转自 冰冻vs西瓜 51CTO博客,原文链接:http://blog.51cto.com/molewan/1926137,如需转载请自行联系原作者