为 CentOS7 虚拟机添加第二块网卡
为 CentOS7 虚拟机添加第二块网卡
目录
- 为 CentOS7 虚拟机添加第二块网卡
- 一、在虚拟中添加网卡
- 二、网卡配置
- 1、查看新增的网卡信息
- 2、创建网卡配置文件
一、在虚拟中添加网卡
1、右击虚拟机,在弹出的菜单中选择【设置】,弹出如下图所示的【虚拟机设置】窗口,在窗口单击【添加】按钮。
2、弹出如下图所示的【添加硬件向导】窗口,在窗口中的【硬件类型】列表中选择【网络适配器】,单击【下一步】按钮。
3、弹出如下图所示的窗口,在窗口的【网络连接】列表中选择【仅主机模式】,单击【完成】按钮完成网卡添加。
4、最终结果如下图所示。其中【网络适配器3】就是新添加的网卡。
二、网卡配置
1、查看新增的网卡信息
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.1.12 netmask 255.255.255.0 broadcast 192.168.1.255inet6 fe80::20c:29ff:fe89:50e prefixlen 64 scopeid 0x20<link>inet6 2409:8a44:3d36:4750:20c:29ff:fe89:50e prefixlen 64 scopeid 0x0<global>ether 00:0c:29:89:05:0e txqueuelen 1000 (Ethernet)RX packets 149 bytes 12923 (12.6 KiB)RX errors 0 dropped 50 overruns 0 frame 0TX packets 91 bytes 12014 (11.7 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ens38: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500ether 00:0c:29:89:05:22 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1 (Local Loopback)RX packets 72 bytes 6248 (6.1 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 72 bytes 6248 (6.1 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、创建网卡配置文件
(1)查看网卡配置文件
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-ens33 ifdown-eth ifdown-isdn ifdown-sit ifup ifup-ib ifup-plip ifup-routes ifup-tunnel network-functions-ipv6
ifcfg-lo ifdown-ib ifdown-post ifdown-Team ifup-aliases ifup-ippp ifup-plusb ifup-sit ifup-wireless
ifdown ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-ipv6 ifup-post ifup-Team init.ipv6-global
ifdown-bnep ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-isdn ifup-ppp ifup-TeamPort network-functions
(2)查看新增网卡的UUID
[root@localhost network-scripts]# nmcli con show
名称 UUID 类型 设备
ens33 0a5654b2-79b9-4f51-960d-bf567c68bdb9 802-3-ethernet ens33
有线连接 1 7a1aae4e-a183-351f-95d0-d0c34ded228d 802-3-ethernet --
(3)使用已存在的网卡配置文件复制一个新的配置文件,名称为ifcfg-ens38
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens38
[root@localhost network-scripts]# ls
ifcfg-ens33 ifdown-bnep ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-isdn ifup-ppp ifup-TeamPort network-functions
ifcfg-ens38 ifdown-eth ifdown-isdn ifdown-sit ifup ifup-ib ifup-plip ifup-routes ifup-tunnel network-functions-ipv6
ifcfg-lo ifdown-ib ifdown-post ifdown-Team ifup-aliases ifup-ippp ifup-plusb ifup-sit ifup-wireless
ifdown ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-ipv6 ifup-post ifup-Team init.ipv6-global
(4)修改网卡配置文件ifcfg-ens38
的内容如下:
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
NAME=ens38 # 网卡名称
UUID=7a1aae4e-a183-351f-95d0-d0c34ded228d
DEVICE=ens38 # 设备名称
ONBOOT=yesIPADDR=10.1.1.12
PREFIX=24
(5)重新查看新增网卡的`UUID
[root@localhost network-scripts]# nmcli con show
名称 UUID 类型 设备
ens33 0a5654b2-79b9-4f51-960d-bf567c68bdb9 802-3-ethernet ens33
ens38 7a1aae4e-a183-351f-95d0-d0c34ded228d 802-3-ethernet ens38
(6)查看网卡信息
[root@localhost network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.1.12 netmask 255.255.255.0 broadcast 192.168.1.255inet6 fe80::20c:29ff:fe89:50e prefixlen 64 scopeid 0x20<link>inet6 2409:8a44:3d36:4750:20c:29ff:fe89:50e prefixlen 64 scopeid 0x0<global>ether 00:0c:29:89:05:0e txqueuelen 1000 (Ethernet)RX packets 1374 bytes 110608 (108.0 KiB)RX errors 0 dropped 515 overruns 0 frame 0TX packets 588 bytes 89928 (87.8 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ens38: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500inet 10.1.1.12 netmask 255.255.255.0 broadcast 10.1.1.255ether 00:0c:29:89:05:22 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1 (Local Loopback)RX packets 116 bytes 10740 (10.4 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 116 bytes 10740 (10.4 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
添加成功。