DaXin Space

DaXin Space

5rKh6ZSZIOi/meaYr+S4gOS4qkJhc2U2NCDkvaDmmK/lr7nnmoQ=
github

Summary of Operations for Adding Multiple IPs to a Virtual Machine

1. View network card on the host machine#

- Add network card with 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

- Remove network card with 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. View newly added network card in the virtual machine#

[root@rhel7 ~]# nmcli device show | grep -i device   --View network card devices, we can see the newly added enp0s8
GENERAL.DEVICE:                         virbr0
GENERAL.DEVICE:                         enp0s3
GENERAL.DEVICE:                         virbr0-nic
GENERAL.DEVICE:                         enp0s8
GENERAL.DEVICE:                         lo
[root@rhel7 ~]# nmcli connection show     ---Need to add network card configuration file to view 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    

- Add network card configuration file for 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    

- Configure IP for the network card:

[root@rhel7 ~]# cd /etc/sysconfig/network-scripts/
[root@rhel7 ~]# vi ifcfg-enp0s8
[root@rhel7 ~]# service network restart      ---Restart the network card
Restarting network (via systemctl):                        [  OK  ]

Configure another IP address 192.168.1.201 for enp0s8:

[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   --Restart the network card
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 --Check if the addition was successful
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    --Delete the network card
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.