Need to add another IP address to your Linux CentOS 7 VPS or dedicated server? With Network Manager ‘nmtui
‘ the process is fairly straightforward. Manual configuration is not recommended. However, it is still a viable option.
The nmtui Tool
The nmtui tool is the preferred way to bind additional IP addresses in CentOS 7. This is the text-based user interface, or TUI, that allows you to control NetworkManager.
Installing the nmtui Tool
CentOS versions predating 7.5 may not have the nmtui tool installed by default (packaged). The nmtui tool is a very helpful utility, and worth installing. Use the following command:
sudo yum install NetworkManager-tui
Once installed, start the NetworkManager TUI:
sudo systemctl start NetworkManager
Using nmtui to Bind IPs
1. Open the Network Manager
sudo nmtui
2. Select Edit a network connection and press enter
3. Use the arrow keys to interface you’d like to add your IP address(es) to.
4.Click Edit and then use the ‘tab’ command to get to Add.
5.Save the configs and your extra IP is now added.
You can confirm that the IP has been added by checking for the text-configs in /etc/sysconfig/network-scripts/. If nmtui has added the secondary IP, you’ll see this (replacing “ens192” with the name of your interface):
$ cat /etc/sysconfig/network-scripts/ifcfg-ens192 ... # Alias on the interface IPADDR1="10.50.23.11" PREFIX1="32"
Alternatively, you can modify the text file instead of using nmtui, but nmtui is generally the easier option.
Manual Configuration
The only instance in which you should use manual configuration is if your CentOS 7 interface doesn’t use Network Manager. This is rather rare, so you should confirm that your interface does, indeed, require manual configuration.
Confirm You Don’t Have Network Manager
$ grep 'NM_CONTROLLED' /etc/sysconfig/network-scripts/ifcfg-ens160 NM_CONTROLLED="no"
If the response is “no”, then you will need to proceed with manual configuration. If the response is “yes”, proceed with option one (nmtui) listed above.
Manually Bind IPs
The next step is to edit the configuration file, which is located in /etc/sysconfig/network-scripts/. All configuration files start with the prefix “ifcfg-“. You can use this command to open up your interface’s config file (replacing “p2p1” with the name of your interface):
vi /etc/sysconfig/network-scripts/ifcfg-p2p1
Your output will look similar to this:
TYPE="Ethernet" BOOTPROTO="static" NAME="p2p1" IPADDR="192.168.0.20" UUID="113b3841-d06d-4a3c-89e8-1a49105a904a" ONBOOT=yes HWADDR="78:45:C4:17:FA:74"
For each additional IP address, you’ll want to add a new line below “IPADDR” titled “IPADDR1”, “IPADDR2”, and so on. Here’s an example with one additional IP address added:
TYPE="Ethernet" BOOTPROTO="static" NAME="p2p1" IPADDR="192.168.0.20" IPADDR1=”192.168.0.21” UUID="113b3841-d06d-4a3c-89e8-1a49105a904a" ONBOOT=yes
The final step is to restart your network so the changes take effect. You can do so with this command:
systemctl restart network
Now all of your IPs are bound to your CentOS 7 interface. You can test that the IP addresses have been added correctly by pinging them from another location.
Temporary IP Addresses
If you only want to make the IP address a temporary addition, you can do this with the IP command. This IP will only last until you reboot the server or restart network service.
$ ip a add 10.50.100.5/24 dev eth0
This method is simple, but it’s only ideal in certain situations. If you want to add a second IP or alias for long-term use, go with option one or two.