1. 在宿主機查看網卡#
- virsh attach-interface 添加網卡:
[root@ubuntu ~]# virsh domiflist CentOS-V6.5.23-server01
Interface Type Source Model MAC
-------------------------------------------------------
vnet0 network default rtl8139 52:54:00:90:0a:7a
[root@ubuntu ~]# virsh attach-interface CentOS-V6.5.23-server01 --type network --source default --model rtl8139 --live --config
Interface attached successfully
[root@ubuntu ~]# virsh domiflist CentOS-V6.5.23-server01
Interface Type Source Model MAC
-------------------------------------------------------
vnet0 network default rtl8139 52:54:00:90:0a:7a
vnet1 network default rtl8139 52:54:00:ae:84:d0
- virsh detach-interface 刪除網卡:
[root@ubuntu ~]# virsh detach-interface CentOS-V6.5.23-server01 --type network --mac 52:54:00:00:34:55 --live --config
Interface detached successfully
[root@ubuntu ~]# virsh domiflist CentOS-V6.5.23-server01
Interface Type Source Model MAC
-------------------------------------------------------
vnet0 network default rtl8139 52:54:00:90:0a:7a
2. 在虛擬機裡查看新增加網卡#
[root@rhel7 ~]# nmcli device show | grep -i device --查看網卡設備,我們可以看到新添加的enp0s8
GENERAL.DEVICE: virbr0
GENERAL.DEVICE: enp0s3
GENERAL.DEVICE: virbr0-nic
GENERAL.DEVICE: enp0s8
GENERAL.DEVICE: lo
[root@rhel7 ~]# nmcli connection show ---還得添加網卡配置文件才能查看到enp0s8
NAME UUID TYPE DEVICE
virbr0-nic c6a02e0f-24af-4b3b-983d-1643fee355df generic virbr0-nic
virbr0 eecfd3a6-4d29-4f9c-a62c-1a30df56e011 bridge virbr0
enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet enp0s3
- 添加 enp0s8 的網卡配置文件:
[root@rhel7 ~]# nmcli connection add type ethernet con-name enp0s8 ifname enp0s8 autoconnect yes
Connection 'enp0s8' (8bf108aa-9c89-4c2c-a5d3-3d9346b2c644) successfully added.
[root@rhel7 ~]# nmcli connection show
NAME UUID TYPE DEVICE
virbr0-nic c6a02e0f-24af-4b3b-983d-1643fee355df generic virbr0-nic
virbr0 eecfd3a6-4d29-4f9c-a62c-1a30df56e011 bridge virbr0
enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet enp0s3
enp0s8 8bf108aa-9c89-4c2c-a5d3-3d9346b2c644 802-3-ethernet enp0s8
- 給網卡配置 IP:
[root@rhel7 ~]# cd /etc/sysconfig/network-scripts/
[root@rhel7 ~]# vi ifcfg-enp0s8
[root@rhel7 ~]# service network restart ---重啟網卡
Restarting network (via systemctl): [ OK ]
給 enp0s8 再配置一個 IP 地址 192.168.1.201:
[root@rhel7 ~]# nmcli connection modify enp0s8 +ipv4.addresses 192.168.1.201/24 ipv4.gateway 192.168.1.99
[root@rhel7 ~]# nmcli connection down enp0s8 --重啟網卡
Connection 'enp0s8' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)
[root@rhel7 ~]# nmcli connection up enp0s8
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)
[root@rhel7 ~]# nmcli connection show
NAME UUID TYPE DEVICE
virbr0-nic c6a02e0f-24af-4b3b-983d-1643fee355df generic virbr0-nic
virbr0 eecfd3a6-4d29-4f9c-a62c-1a30df56e011 bridge virbr0
enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet enp0s3
enp0s8 8bf108aa-9c89-4c2c-a5d3-3d9346b2c644 802-3-ethernet enp0s8
[root@rhel7 ~]# ip addr show enp0s8 --查看添加成功
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:79:3c:2c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.200/24 brd 192.168.1.255 scope global enp0s8
valid_lft forever preferred_lft forever
inet 192.168.1.201/24 brd 192.168.1.255 scope global secondary enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe79:3c2c/64 scope link
valid_lft forever preferred_lft forever
[root@rhel7 ~]# nmcli con delete enp0s8 --刪除網卡