首先在虚拟机管理界面中给该虚拟机添加一块虚拟网卡,VirtualBox虚拟机中要shutdown才能添加。
[root@rhel7 ~]# nmcli device show | grep -i device --查看网卡设备,我们可以看到新添加的enp0s8GENERAL.DEVICE: virbr0GENERAL.DEVICE: enp0s3GENERAL.DEVICE: virbr0-nicGENERAL.DEVICE: enp0s8GENERAL.DEVICE: lo[root@rhel7 ~]# nmcli connection show ---还得添加网卡配置文件才能查看到enp0s8NAME 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 yesConnection 'enp0s8' (8bf108aa-9c89-4c2c-a5d3-3d9346b2c644) successfully added.[root@rhel7 ~]# nmcli connection showNAME 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 ~]# nmcli connection modify enp0s8 ipv4.addresses 192.168.1.200/24 ipv4.gateway 192.168.1.99 ipv4.dns 192.168.1.1 ipv4.method manual connection.autoconnect yes
启动enp0s8网卡:
[root@rhel7 ~]# nmcli connection up enp0s8Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)[root@rhel7 ~]# ip a s enp0s83: enp0s8: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 inet6 fe80::a00:27ff:fe79:3c2c/64 scope link valid_lft forever preferred_lft forever
网卡添加配置完成。
============================
给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 enp0s8Connection 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: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 ~]#
给enp0s8再配置一个IPv6地址2001::1/64
[root@rhel7 ~]# nmcli connection modify enp0s8 ipv6.method manual ipv6.addresses 2001::1/64 ipv6.gateway 2001::1 ipv6.dns 2001::1[root@rhel7 ~]# ping6 2001::1connect: Network is unreachable[root@rhel7 ~]# nmcli connection down enp0s8Connection 'enp0s8' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)[root@rhel7 ~]# nmcli connection up enp0s8Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/15)[root@rhel7 ~]# ping6 2001::1PING 2001::1(2001::1) 56 data bytes64 bytes from 2001::1: icmp_seq=1 ttl=64 time=0.062 ms64 bytes from 2001::1: icmp_seq=2 ttl=64 time=0.116 ms64 bytes from 2001::1: icmp_seq=3 ttl=64 time=0.119 ms^C--- 2001::1 ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2000msrtt min/avg/max/mdev = 0.062/0.099/0.119/0.026 ms[root@rhel7 ~]#