(四)KVM配置桥接网卡

配置桥接网卡

添加桥接网卡br0,注释掉已有的eth0配置

[root@ubuntu01 ~]# vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#auto eth0
#iface eth0 inet dhcp

auto br0
iface br0 inet static
        address 192.168.31.10
        netmask 255.255.255.0
        broadcast 192.168.31.255
        gateway 192.168.31.2
        bridge_ports eth0
        bridge_fd 9
        bridge_hello 2
        bridge_maxage 12
        bridge_stp off

重启网络后,就可以看到桥接网卡的配置了:

[root@ubuntu01 ~]# brctl show 
bridge name     bridge id               STP enabled     interfaces
br0             8000.000c29acc95e       no              eth0
virbr0          8000.000000000000       yes
[root@ubuntu01 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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 group default qlen 1000
    link/ether 00:0c:29:ac:c9:5e brd ff:ff:ff:ff:ff:ff
    inet6 fe80::20c:29ff:feac:c95e/64 scope link
       valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:ac:c9:5e brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.10/24 brd 192.168.31.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feac:c95e/64 scope link
       valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 32:33:c1:58:2a:87 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

或者,用virsh 创建桥接网卡
virsh iface-bridge
相比于手动配置,好像用virsh配置桥接网卡可以不用重启网络

[root@ubuntu01 ~]# virsh  iface-bridge --interface eth0 --bridge br0
Created bridge br0 with attached device eth0
Bridge interface br0 started

[root@ubuntu01 ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.000c29acc95e       yes             eth0
virbr0          8000.000000000000       yes

[root@ubuntu01 ~]# virsh iface-list 
 Name                 State      MAC Address
---------------------------------------------------
 br0                  active     00:0c:29:ac:c9:5e
 lo                   active     00:00:00:00:00:00

[root@ubuntu01 ~]# ip ad
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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 group default qlen 1000
    link/ether 00:0c:29:ac:c9:5e brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 12:c0:91:80:ba:d6 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
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:ac:c9:5e brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.132/24 brd 192.168.31.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feac:c95e/64 scope link
       valid_lft forever preferred_lft forever

自动生成网卡配置:

[root@ubuntu01 ~]# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto br0
iface br0 inet dhcp
   bridge_ports eth0
   bridge_stp on
   bridge_fd 0

如果删除桥接网卡:

[root@ubuntu01 ~]# virsh  iface-unbridge br0

这个操作会导致宿主机断网,需要手动重启一下eth0网卡
创建虚拟机

virt-install 的--network选项指定bridge:

[root@ubuntu01 ~]# virt-install
    --name=centos_vm_01
    --virt-type=kvm
    --ram=1024
    --cdrom=/data/iso/CentOS-V6.5.23.iso
    --disk path=/data/img/disk01.raw
    --network bridge=br0 
    --graphics vnc,listen=0.0.0.0
    --noautoconsole
posted @ 2022-07-29 17:10  比特边界  阅读(1174)  评论(0编辑  收藏  举报