Adding public IPv4 and IPv6 addresses to a Linux Server (CentOS Stream 8)
Please use the “Print” function at the bottom of the page to create a PDF.
For Cloud Servers and Virtual Server Cloud managed in the Cloud Panel
This article explains how to add additional public IPv4 and IPv6 addresses to a server that has CentOS Stream 8 installed.
Note
How to establish an encrypted network connection to your server using Secure Shell (SSH) is explained in the following articles:
Requirements
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.
Display Network Interface
Identify the file name of the network interface. To do this, enter the following command:
[root@localhost ~]# ip addr
Show Default DNS Server
To display the DNS servers used, enter the following commands:
[root@localhost ~]# curl http://169.254.169.254/latest/meta_data/dns/nameservers -Lv
[root@localhost ~]# curl http://169.254.169.254/latest/meta_data/dns/nameservers6 -LvThe DNS servers are then displayed at the end of the output. Example:
[root@localhost ~]# curl http://169.254.169.254/latest/meta_data/dns/nameservers -Lv
* Trying 169.254.169.254...
* TCP_NODELAY set
* Connected to 169.254.169.254 (169.254.169.254) port 80 (#0)
> GET /latest/meta_data/dns/nameservers HTTP/1.1
> Host: 169.254.169.254
> User-Agent: curl/7.61.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 08 Sep 2022 12:19:36 GMT
< Server: Apache
< Strict-Transport-Security: max-age=63072000; includeSubDomains
< Vary: Accept-Encoding
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: X-TOKEN, X-HASH, X-MICROTIME, X-USER, Content-Type, X-API-TOKEN, Authorisation
< Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
< Access-Control-Expose-Headers: Error-Msg
< Cache-control: no-cache, no-store, max-age=0
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: X-TOKEN, X-HASH, X-MICROTIME, Content-Type, X-API-TOKEN, Authorisation
< Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
< Access-Control-Expose-Headers: Error-Msg
< Transfer-Encoding: chunked
< Content-Type: text/plain;charset=UTF-8
<
212.227.123.16,212.227.123.17
* Connection #0 to host 169.254.169.254 left intactNote down the DNS servers. In the above example, the DNS servers are displayed above the line * Connection #0 to host 169.254.169.254 left intact.
Display Gateway for IPv4 and IPv6
To display the default gateway of the active interface, enter the following commands:
IPv4:[root@localhost ~]# ip route show | grep 'default'
IPv6:
[root@localhost ~]# ip -6 route show | grep 'default'
Make a note of the gateways.
Add IPv4 and IPv6 addresses
Open the file /etc/sysconfig/network-scripts/ifcfg-ens192 with the vi editor. To do this, enter the following command:
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens192
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.
Insert the following entries:
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>Enter the device ens192 under Device= and enter the DNS servers you have noted down under DNS1 and DNS2. 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%ens192Restart the server to apply the changes. To do this, 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.