O0十一、理解 virbr0

 
virbr0 是KVM 默認建立的一個Bridge ,其做用是爲該宿主機上的虛機提供NAT上網的功能。virbr0默認分配了一個IP地址 192.168.122.1 併爲鏈接在上面的虛擬網卡提供DHCP服務。
 
下面咱們演示如何使用 virbr0
 
建立虛機 VM3 ,並設置網卡鏈接到 NAT 網絡中
 
 
root@ubuntu:~# virsh list     #    查看VM3運行狀態
Id    Name                           State
----------------------------------------------------
10    VM3                            running
 
root@ubuntu:~# virsh domiflist VM3    #    查看VM3 虛機接口
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet0      network    default    rtl8139     52:54:00:e3:0f:d2
 
root@ubuntu:~# brctl show    #    查看 VM3 虛機接口鏈接到了 virbr0 上
bridge name    bridge id        STP enabled    interfaces
br0        8000.005056874c70    no        ens160
virbr0        8000.fe5400e30fd2    yes        vnet0
 
root@ubuntu:~# ps -ef | grep dnsmasq    #    virbr0 使用 dnsmasq提供 DHCP服務
libvirt+  3803     1  0 21:58 ?        00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
root      3804  3803  0 21:58 ?        00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
root      6121  5694  0 23:03 pts/3    00:00:00 grep --color=auto dnsmasq
 
root@ubuntu:~# cat /var/lib/libvirt/dnsmasq/default.conf    #    DHCP 配置文件
##WARNING:  THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST.  Changes to this configuration should be made using:
##    virsh net-edit default
## or other application using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
user=libvirt-dnsmasq
pid-file=/var/run/libvirt/network/default.pid
except-interface=lo
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254
dhcp-no-override
dhcp-lease-max=253
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
 
 
在虛機中進行網絡連通性測試,DHCP或得的IP地址能夠ping同宿主機和宿主機外面的網絡
 
相關文章
相關標籤/搜索