Sometimes you need to add more than one IP to a NIC (i.e. Network Interface Controller), this situation occurs when you need to support two or more separate networks with one CentOS server. In this article, we are going to add an extra IP to one NIC in RedHat-based Linux Distributions.
At first, we need to know the NIC name, and to find it out, login as the root user and insert the following command:
ip addr
Here’s an example of the output:
As you see in the output, the NIC name used for this demonstration is primary and the IP is 43.230.163.186. To change the NIC IP or to add more IPs, we should open the “primary” file with an editor done through the command below (don’t forget to add “ifcfg-” before the NIC name):
vi /etc/sysconfig/network-scripts/ifcfg-primary
Please Note: that primary is the demonstration server’s NIC name and will be different for your server.
The opened configuration file should look like this:
Now press ‘i’ to edit the file and enter the new IP address that you want to add as IPADDR0 like shown in the picture below. If this new IP is in a different subnet, enter the gateway and subnet mask as GATEWAY1 and PREFIX1.
After that, restart the network service:
service network restart
We execute ip addr, we see whether the primary file is showing all IPs or not. Here, it is showing all working perfectly.
Was this helpful?
0 / 0