Adding public IPv4 and IPv6 addresses to a Linux Server (CentOS Stream 9)
Please use the “Print” function at the bottom of the page to create a PDF.
For Cloud Servers and Virtual Server Cloud
This article explains how to add additional public IPv4 and IPv6 addresses to a server that has CentOS Stream 9 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 Stream 9:
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.
Identify Network Interface
Idnetify the file name of the network interface. To do this, enter the following command:
[root@localhost ~]# ip addr
In the following example, the network interface ens192 is used:
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:0a:1b:3b brd ff:ff:ff:ff:ff:ff:ff
altname enp11s0
inet 217.160.36.149/32 scope global noprefixroute ens192
valid_lft forever preferred_lft forever
inet 217.160.36.232/32 scope global noprefixroute ens192
valid_lft forever preferred_lft forever
inet6 2001:8d8:1801:75e::1/64 scope global noprefixroute
valid_lft forever preferred_lft forever
inet6 2001:8d8:1801:75e::2/64 scope global noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::33fc:a146:c6f0:5fbe/64 scope link noprefixroute
valid_lft forever preferred_lft forever
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.
Generate UUID
Generate a Universally Unique Identifier (UUID) and note it down. This will be needed later on for the network configuration.
To generate a UUID, enter the following command:
[root@localhost ~]# uuidgen
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'
Note down the IP addresses of the gateways. These are listed directly after the default via part. Examples:
IPv4 Gateway:[root@localhost ~]# ip route show | grep 'default'
default via 10.255.255.1 dev ens192 proto static metric 100IPv6 Gateway:
[root@localhost ~]# ip -6 route show | grep 'default'
default via fe80::1 dev ens192 proto static metric 100 pref medium
Add IPv4 and IPv6 Addresses
Open the file /etc/NetworkManager/system-connections/ens192.nmconnection with the vi editor. To do this, enter the following command:
[root@localhost ~]# vi /etc/NetworkManager/system-connections/ens192.nmconnection
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.
In the [connection] area, enter the new UUID you have generated in the uuid= entry.
Replace the existing entries in the [ipv4] area with the following entries:
[ipv4]
address1=<IPv4-ADDRESS1>/32,10.255.255.1
address2=<IPv4-ADDRESS2>/32,10.255.255.1
dns=<DNS-Server1>;<DNS-Server2>;
method=manualExample:
[ipv4]
address1=217.160.141.60/32,10.255.255.1
address2=82.165.254.101/32,10.255.255.1
dns=127.0.0.53;
method=manualReplace the placeholders <IPv4-ADDRESS1> and <IPv4-ADDRESS2> with the main IPv4 address and the additional IPv4 address. Then enter the DNS server you have determined in the dns= entry.
Replace the existing entries in the [ipv6] area with the following entries:
[ipv6]
addr-gen-mode=stable-privacy
address1=<IPv6-ADDRESS1>/64,fe80::1
address2=<IPv6-ADDRESS2>/64,fe80::1
dhcp-duid=ll
dns=<dns1>;<dns2>;
method=manualExample:
[ipv6]
addr-gen-mode=stable-privacy
address1=<2001:8d8:1801:75e::1>/64,fe80::1
address2=<2001:8d8:1801:75e::2>/64,fe80::1
dhcp-duid=ll
dns=fe80::1;
method=manualReplace the placeholders <IPv6-ADDRESS1> and <IPv6-ADDRESS2> with the main IPv6 address and the additional IPv6 address. Then enter the DNS server you have determined in the dns= entry.
Restart the server to apply the changes. To do this, enter the following command:
[root@localhost ~]# systemctl reboot