Adding a Public IPv4 Address on a Linux Server (CentOS 7)
Please use the “Print” function at the bottom of the page to create a PDF.
For Cloud Server
This article explains how to add additional public IPv4 and IPv6 addresses to a Cloud Server that has CentOS 7 installed.
Note
How to establish an encrypted network connection to your server using Secure Shell (SSH) is explained in the following articles:
How to configure additional, public IPv4 and IPv6 addresses in CentOS 7:
Prerequisites
You have assigned one or more additional, public IPv4 and/or IPv6 addresses to your server in the Cloud Panel.
You are logged in to the server.
You have noted down the IPv4 addresses and IPv6 addresses of the server.
To display the DNS servers used, enter the following command:
[root@localhost ~]# cat /etc/resolv.conf
The DNS servers are then displayed in the nameserver entry. Example:
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 212.227.123.16
nameserver 212.227.123.17Note down the DNS servers.
Open the file /etc/sysconfig/network-scripts/ifcfg-ens192 with the vi editor.
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens192
Replace the existing entries with the following information:
NAME=Public_<Interface_Device>
TYPE=Ethernet
DEVICE=<Interface_Device>
ONBOOT=yes
BOOTPROTO=none
IPADDR=<Main IPv4 address>
PREFIX=32
GATEWAY=10.255.255.1
DNS1=<DNS server 1>
DNS2=<DNS server 2>
IPV6INIT=yes
IPV6_AUTOCONF=no
DHCPV6C=no
IPV6ADDR=<main IPv6 address >/64
IPV6_DEFAULTGW=fe80::1%<Interface_Device>
Notes
The vi editor has an insert mode and a command mode. You can call up insert mode with the [i] key. In this mode, the characters entered are immediately inserted into the text. To call up command mode, press [ESC]. If you use command mode, your keyboard input is interpreted as a command.
To exit vi and save the file, enter the command :wq and then press Enter.
For Device=, enter the device ens192 and for DNS1 and DNS2, enter the DNS servers that you have noted. Enter your main IPv4 address for IPADDR0 and enter your main IPv6 address for IPV6ADDR.
To configure the additional IPv4 address(es), add the following entry(s):
IPADDR1=<additional IPv4 address>
PREFIX1=32
IPADDR2=<additional IPv4 address>
PREFIX2=32
IPADDRN=<additional IPv4 address>
PREFIXN=32Replace the <additional IPv4 address> part with the desired additional IPv4 address.
To configure additional IPv6 addresses, add the following entry:
IPV6ADDR_SECONDARIES=<additional IPv6 address>/64
Replace the <Additional IPv6 address> part with the desired additional IPv6 address. To configure several additional IPv6 addresses, enter them one after the other. Use a space to separate the IPv6 addresses.
The following example shows a complete entry that is used to configure the main IPv4 and the main IPv6 address as well as an additional IPv4 and an additional IPv6 address.NAME=Public_ens192
TYPE=Ethernet
DEVICE=ens192
ONBOOT=yes
BOOTPROTO=none
IPADDR=217.160.244.40
PREFIX=32
IPADDR1=212.227.213.81
PREFIX1=32
GATEWAY=10.255.255.1
DNS1=212.227.123.16
DNS2=212.227.123.17
IPV6INIT=yes
IPV6_AUTOCONF=no
DHCPV6C=no
IPV6ADDR=2001:8d8:1801:8329::1/64
IPV6ADDR_SECONDARIES=2001:8d8:1801:8329::2/64
IPV6_DEFAULTGW=fe80::1%ens192To restart the server, enter the following command:
[root@localhost ~]# systemctl reboot
Log in to the server again.
To check whether the desired IPv4 and IPv6 addresses have been configured correctly, enter the command ip addr show:
[root@localhost ~]# ip addr show
Note
If the server is no longer accessible due to a configuration error, you can log in to the server using the KVM console and correct the configuration.