//查看网卡配置文件
[root@libvirt ~]# cd /etc/sysconfig/network-scripts/
[root@libvirt network-scripts]# ll
-rw-r--r--. 1 root root ? 381 9月 ?15 17:32 ifcfg-ens33? ?
-rw-r--r--. 1 root root ? 254 5月 ?22 2020 ifcfg-lo
lrwxrwxrwx. 1 root root ? ?24 9月 ?15 22:21 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root ? 654 5月 ?22 2020 ifdown-bnep
-rwxr-xr-x. 1 root root ?6532 5月 ?22 2020 ifdown-eth
...........
//没有网卡配置文件则查看网卡设备名称
[root@libvirt network-scripts]# nmcli con show
NAME ? ? ? ?UUID ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TYPE ? ? ?DEVICE?
ens33 ? ? ? 7f650b0b-7f05-413b-a598-832d8df94877 ?ethernet ?ens33 ?
有线连接 1 ?38e58bba-a6b6-302a-9981-5d16efe654c6 ?ethernet ?ens36 ?
virbr0 ? ? ?4d97d2d4-10c7-4757-83cd-493a8697a59c ?bridge ? ?virbr0?
//添加网卡信息
[root@libvirt network-scripts]# nmcli con add con-name ens36 type ethernet ifname ens36
连接 "ens36" (a67c9c1b-f7c2-4c7e-bfaa-2cea1993cb56) 已成功添加。?
[root@libvirt network-scripts]# ll
总用量 256
-rw-r--r--. 1 root root ? 381 9月 ?15 17:32 ifcfg-ens33? ?---用于与kvm虚拟机桥接?
-rw-r--r-- ?1 root root ? 280 10月 ?3 17:39 ifcfg-ens36? ?---用于管理VMware虚拟机
-rw-r--r--. 1 root root ? 254 5月 ?22 2020 ifcfg-lo
//复制ifcfg-ens33为ifcfg-br0,修改ifcfg-br0
[root@libvirt network-scripts]# cp ifcfg-ens33 ifcfg-br0
[root@libvirt network-scripts]# vim ifcfg-br0
TYPE=Bridge
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=br0
UUID=7f650b0b-7f05-413b-a598-832d8df94877
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.100.145
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
DNS1=192.168.100.2
DNS2=8.8.8.8
ZONE=public
//修改ifcfg-ens33配置
[root@libvirt network-scripts]# vim ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=7f650b0b-7f05-413b-a598-832d8df94877
DEVICE=ens33
ONBOOT=yes
ZONE=public
BRIDGE=br0
MACADDR=00:0c:29:5d:3c:9b? ? ?---新开终端,使用ifconfig查看,如图:
//重启网络
[root@libvirt network-scripts]# systemctl restart network
Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
[root@libvirt network-scripts]# systemctl restart network
//查看网桥信息验证绑定是否成功
[root@libvirt network-scripts]# brctl show
bridge name?? ?bridge id?? ??? ?STP enabled?? ?interfaces
br0?? ??? ?8000.000c295d3c9b?? ?no?? ??? ?ens33?? ? ?---网桥br0绑定到ens33网卡上
virbr0?? ??? ?8000.525400f6fce1?? ?yes?? ??? ?virbr0-nic
?
//创建网桥br0
[root@master ~]# nmcli connection add type bridge con-name br0 ifname br0 autoconnect yes
连接 "br0" (c575a747-b844-4514-9f50-57275fcd7c86) 已成功添加。
//将br0跟物理网卡ens33桥接
[root@master ~]# nmcli connection add type bridge-slave ifname ens33 master br0
连接 "bridge-slave-ens33" (5f1d8814-3428-4903-9a13-954dc43777b7) 已成功添加。
//切换至网卡配置路径
[root@master ~]# cd /etc/sysconfig/network-scripts/?
[root@master network-scripts]# ls
ifcfg-br0 ? ? ? ? ? ? ? ? ifdown-isdn ? ? ?ifup-bnep ? ifup-routes
ifcfg-bridge-slave-ens33 ?ifdown-post ? ? ?ifup-eth ? ?ifup-sit
ifcfg-ens33 ? ? ? ? ? ? ? ifdown-ppp ? ? ? ifup-ib ? ? ifup-Team
ifcfg-lo ? ? ? ? ? ? ? ? ?ifdown-routes ? ?ifup-ippp ? ifup-TeamPort
ifdown ? ? ? ? ? ? ? ? ? ?ifdown-sit ? ? ? ifup-ipv6 ? ifup-tunnel
ifdown-bnep ? ? ? ? ? ? ? ifdown-Team ? ? ?ifup-isdn ? ifup-wireless
ifdown-eth ? ? ? ? ? ? ? ?ifdown-TeamPort ?ifup-plip ? init.ipv6-global
ifdown-ib ? ? ? ? ? ? ? ? ifdown-tunnel ? ?ifup-plusb ?network-functions
ifdown-ippp ? ? ? ? ? ? ? ifup ? ? ? ? ? ? ifup-post ? network-functions-ipv6
ifdown-ipv6 ? ? ? ? ? ? ? ifup-aliases ? ? ifup-ppp
?
//刷新配置文件,查看网络设备连接
[root@master network-scripts]# nmcli c reload
[root@master network-scripts]# nmcli c?
NAME ? ? ? ? ? ? ? ?UUID ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TYPE ? ? ?DEVICE?
br0 ? ? ? ? ? ? ? ? c575a747-b844-4514-9f50-57275fcd7c86 ?bridge ? ?br0 ? ?
ens33 ? ? ? ? ? ? ? 417d6e6c-50f2-4e8f-8f11-a8ad9fd8dea3 ?ethernet ?ens33 ?
virbr0 ? ? ? ? ? ? ?b07c5898-3da0-4762-90c0-aa7218499e33 ?bridge ? ?virbr0?
bridge-slave-ens33 ?5f1d8814-3428-4903-9a13-954dc43777b7 ?ethernet ?-- ??
//改ifcfg-ens33配置
[root@master network-scripts]# vim ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=417d6e6c-50f2-4e8f-8f11-a8ad9fd8dea3
DEVICE=ens33
ONBOOT=no? ---改为no
IPADDR=192.168.100.130
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
DNS1=192.168.100.2
DNS2=8.8.8.8? ?---复制蓝色区域的IP地址配置,将其粘贴至下方紫色区域
//改ifcfg-br0配置
[root@master network-scripts]# vim ifcfg-br0
STP=yes
BRIDGING_OPTS=priority=32768
TYPE=Bridge
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static? ---改为static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=br0
UUID=c575a747-b844-4514-9f50-57275fcd7c86
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.100.130? ? ---将ifcfg-ens33中复制的IP地址配置添加至此
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
DNS1=192.168.100.2
DNS2=8.8.8.8
//查看ifcfg-bridge-slave-ens33配置
[root@master network-scripts]# cat ifcfg-bridge-slave-ens33
TYPE=Ethernet
NAME=bridge-slave-ens33
UUID=5f1d8814-3428-4903-9a13-954dc43777b7
DEVICE=ens33
ONBOOT=yes
BRIDGE=br0
?
//查看设备连接
[root@master network-scripts]# nmcli c
NAME ? ? ? ? ? ? ? ?UUID ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TYPE ? ? ?DEVICE?
br0 ? ? ? ? ? ? ? ? c575a747-b844-4514-9f50-57275fcd7c86 ?bridge ? ?br0 ? ?
ens33 ? ? ? ? ? ? ? 417d6e6c-50f2-4e8f-8f11-a8ad9fd8dea3 ?ethernet ?ens33 ?
virbr0 ? ? ? ? ? ? ?b07c5898-3da0-4762-90c0-aa7218499e33 ?bridge ? ?virbr0?
bridge-slave-ens33 ?5f1d8814-3428-4903-9a13-954dc43777b7 ?ethernet ?-- ? ?
//启动设备
[root@master network-scripts]# ?nmcli c up bridge-slave-ens33
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6)
[root@master network-scripts]# nmcli c up br0
连接已成功激活(master waiting for slaves)(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/7)
?
//查看设[root@master network-scripts]# nmcli c reload
[root@master network-scripts]# nmcli c reload
[root@master network-scripts]# nmcli c?
NAME ? ? ? ? ? ? ? ?UUID ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TYPE ? ? ?DEVICE?
br0 ? ? ? ? ? ? ? ? c575a747-b844-4514-9f50-57275fcd7c86 ?bridge ? ?br0 ? ?
virbr0 ? ? ? ? ? ? ?b07c5898-3da0-4762-90c0-aa7218499e33 ?bridge ? ?virbr0?
bridge-slave-ens33 ?5f1d8814-3428-4903-9a13-954dc43777b7 ?ethernet ?ens33 ?
ens33 ? ? ? ? ? ? ? 417d6e6c-50f2-4e8f-8f11-a8ad9fd8dea3 ?ethernet ?-- ? ?
//如果配置有误,修改网卡配置后,需要刷新配置文件,再启动网络(非必须步骤)
[root@master network-scripts]# nmcli c reload
[root@master network-scripts]# systemctl restart network
?
//查看网桥信息
[root@master network-scripts]# brctl show
bridge name?? ?bridge id?? ??? ?STP enabled?? ?interfaces
br0?? ??? ?8000.000c29498078?? ?yes?? ??? ?ens33
virbr0?? ??? ?8000.525400d9ae19?? ?yes?? ??? ?virbr0-nic
?
//查看网络信息
[root@master network-scripts]# ifconfig?
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> ?mtu 1500
? ? ? ? inet 192.168.100.130 ?netmask 255.255.255.0 ?broadcast 192.168.100.255
? ? ? ? inet6 fe80::2a06:5497:5071:f8bd ?prefixlen 64 ?scopeid 0x20<link>
? ? ? ? ether 00:0c:29:49:80:78 ?txqueuelen 1000 ?(Ethernet)
? ? ? ? RX packets 6 ?bytes 396 (396.0 B)
? ? ? ? RX errors 0 ?dropped 0 ?overruns 0 ?frame 0
? ? ? ? TX packets 27 ?bytes 3040 (2.9 KiB)
? ? ? ? TX errors 0 ?dropped 0 overruns 0 ?carrier 0 ?collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> ?mtu 1500
? ? ? ? ether 00:0c:29:49:80:78 ?txqueuelen 1000 ?(Ethernet)
? ? ? ? RX packets 1837 ?bytes 2438656 (2.3 MiB)
? ? ? ? RX errors 0 ?dropped 0 ?overruns 0 ?frame 0
? ? ? ? TX packets 449 ?bytes 42034 (41.0 KiB)
? ? ? ? TX errors 0 ?dropped 0 overruns 0 ?carrier 0 ?collisions 0
//验证网络
[root@master network-scripts]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.12) 56(84) bytes of data.
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=1 ttl=128 time=6.46 ms
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=2 ttl=128 time=6.40 ms
?
//查看默认路由
[root@master network-scripts]# route
Kernel IP routing table
Destination ? ? Gateway ? ? ? ? Genmask ? ? ? ? Flags Metric Ref ? ?Use Iface
default ? ? ? ? gateway ? ? ? ? 0.0.0.0 ? ? ? ? UG ? ?425 ? ?0 ? ? ? ?0 br0
192.168.100.0 ? 0.0.0.0 ? ? ? ? 255.255.255.0 ? U ? ? 425 ? ?0 ? ? ? ?0 br0
192.168.122.0 ? 0.0.0.0 ? ? ? ? 255.255.255.0 ? U ? ? 0 ? ? ?0 ? ? ? ?0 virbr0