在 CentOS 7 系统的安装过程中,如果有选择相关虚拟化的的服务安装系统后,启动网卡时会发现有一个以网桥连接的私网地址的 virbr0 网卡,这个是因为在虚拟化中有使用到 libvirtd 服务生成的,如果不需要可以关闭后去掉:
一、查看IP及网桥设备
查看系统版本:
[root@node ~]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core)
查看IP地址:
[root@node ~]# ip -4 addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 inet 192.168.51.103/24 brd 192.168.51.255 scope global noprefixroute dynamic ens33 valid_lft 5089sec preferred_lft 5089sec 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever
查看网桥信息:
[root@node ~]# brctl show bridge name bridge id STP enabled interfaces virbr0 8000.525400f9f9fe yes virbr0-nic
二、使用 brctl 命令管理网桥
brctl 命令的帮助信息:
[root@node ~]# brctl Usage: brctl [commands] commands: addbr <bridge> add bridge //增加网桥 delbr <bridge> delete bridge //删除网桥 addif <bridge> <device> add interface to bridge delif <bridge> <device> delete interface from bridge hairpin <bridge> <port> {on|off} turn hairpin on/off setageing <bridge> <time> set ageing time setbridgeprio <bridge> <prio> set bridge priority setfd <bridge> <time> set bridge forward delay sethello <bridge> <time> set hello time setmaxage <bridge> <time> set max message age setpathcost <bridge> <port> <cost> set path cost setportprio <bridge> <port> <prio> set port priority show <bridge> ] show a list of bridges showmacs <bridge> show a list of mac addrs showstp <bridge> show bridge stp info stp <bridge> {on|off} turn stp on/off
删除网桥:
[root@node ~]# ifconfig virbr0 down [root@node ~]# brctl delbr virbr0
三、禁用开机自启动 libvirtd 服务
[root@node ~]# systemctl disable libvirtd.service # 禁用libvirtd 服务开机自启动
Removed symlink /etc/systemd/system/multi-user.target.wants/libvirtd.service.
Removed symlink /etc/systemd/system/sockets.target.wants/virtlogd.socket.
Removed symlink /etc/systemd/system/sockets.target.wants/virtlockd.socket.
[root@node ~]# systemctl status libvirtd.service
● libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; disabled; vendor preset: enabled)
Active: inactive (dead) since Sun 2019-12-15 13:31:13 CST; 42min ago
Docs: man:libvirtd(8)
https://libvirt.org
Main PID: 1193 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/libvirtd.service
├─1822 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
└─1823 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
Dec 15 11:43:15 node dnsmasq-dhcp[1822]: DHCP, sockets bound exclusively to interface virbr0
Dec 15 11:43:15 node dnsmasq[1822]: no servers found in /etc/resolv.conf, will retry
Dec 15 11:43:15 node dnsmasq[1822]: read /etc/hosts - 2 addresses
Dec 15 11:43:15 node dnsmasq[1822]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
Dec 15 11:43:15 node dnsmasq-dhcp[1822]: read /var/lib/libvirt/dnsmasq/default.hostsfile
Dec 15 13:30:01 node dnsmasq[1822]: reading /etc/resolv.conf
Dec 15 13:30:01 node dnsmasq[1822]: using nameserver 192.168.1.1#53
Dec 15 13:30:01 node dnsmasq[1822]: using nameserver 192.168.51.1#53
Dec 15 13:31:13 node systemd[1]: Stopping Virtualization daemon...
Dec 15 13:31:13 node systemd[1]: Stopped Virtualization daemon.
[root@node ~]# systemctl mask libvirtd.service
Created symlink from /etc/systemd/system/libvirtd.service to /dev/null.
四、验证
[root@node ~]# ip -4 add 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 inet 192.168.51.103/24 brd 192.168.51.255 scope global noprefixroute dynamic ens33 valid_lft 4464sec preferred_lft 4464sec
结果发现:virbr0 已被删除。