This blog is written because it needs to be used later when using keepalived to implement Nginx high availability. The role of virtual IP in high availability is followed. Today to see how to configure the server virtual IP, in fact, is to allocate more IP address.
① first check the IP address of the existing network card and run the following command with root privileges:
IP addr
Sample output:
From the above details, you can see that the server's NIC name is Eno16777736,ip address is 192.168.22.227.
The configuration file for the network card is stored in the/etc/sysconfig/network-scripts/directory. The details of each NIC will be stored in different names, such as ifcfg-eno16777736.
② Open this profile and add an additional IP address
Edit File/etc/sysconfig/network-scripts/ifcfg-eno16777736:
vi/etc/sysconfig/network-scripts/ifcfg-eno16777736
Add an additional IP address as follows.
This adds an IP address: ipaddr1= "192.168.22.231″ of course, you can also add more IP addresses.
Ipaddr2= "192.168.22.232″ ...
Finally, save and exit the file. Shortcut keys: shift+z+z
Restart the network service for the changes to take effect.
Systemctl Restart Network
③ Check to see if the IP address has been added.
Enter command:
IP addr
Sample output:
As you can see, a single NIC already has 2 IP addresses.