Managing IP addresses in Debian/Ubuntu
This applies to Ubuntu 18.04 and 20.04, Debian 9 and 10.
Other versions may work, but I have not tested
Access the server via SSH
Edit the file /etc/network/interfaces
nano /etc/network/interfaces
Replace the contents with this:
# The loopback network interface
auto lo ens192
iface lo inet loopback
# The primary network interface
#Replace the letters with your IP. NOTE THE ZERO ON THE NETWORK LINE!!!
auto ens192
allow-hotplug ens192
iface ens192 inet static
address ABC.DEF.GHI.JKL
network ABC.DEF.GHI.0
netmask 255.255.255.255
broadcast ABC.DEF.GHI.JKL
gateway 10.255.255.1
#Enable the next few lines to add extra IPs. The UP and DOWN go in pairs
# up ip addr add 77.68.127.176/32 dev ens192 label ens192:0
# down ip addr del 77.68.127.176/32 dev ens192 label ens192:0
# up ip addr add 109.228.36.59/32 dev ens192 label ens192:1
# down ip addr del 109.228.36.59/32 dev ens192 label ens192:1
#enable the following section for ipv6
#iface ens192 inet6 static
# address 2a00:da00:1800:81e8::1/128
# netmask 128
# gateway fe80::1
# accept_ra 0
#
#Enable the next few lines to add extra IPs. The UP and DOWN go in pairs
# up ip -6 addr add 2a00:da00:1800:81e8::2/128 dev ens192 label ens192:2
# down ip -6 addr del 2a00:da00:1800:81e8::2/128 dev ens192 label ens192:2
# up ip -6 addr add 2a00:da00:1800:81e8::3/128 dev ens192 label ens192:3
# down ip -6 addr del 2a00:da00:1800:81e8::3/128 dev ens192 label ens192:3
Save (Ctrl-X then Y)
Check your /etc/resolv.conf file to establish where to place your DNS
A file that contains one or more IPs, is a normal resolv.conf file and you can leave it alone or add ipv6 DNS as you wish
nameserver 8.8.8.8
nameserver 2001:4860:4860::8888
A file that contains 127.0.0.X indicates your DNS is managed by systemd. Leave this alone and edit as follows:
nano /etc/systemd/resolved.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details
[Resolve]
DNS=2001:4860:4860::8844 2001:4860:4860::8888 8.8.8.8 8.8.4.4
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
Don't add the Ipv6 addresses unless you have an ipv6 address to use.
Run:
systemctrl restart networking
Check with:
ip a #List assigned IPs
ping google.com #ensure you can reach google
ping6 google.com #ensure you can reach google over ipv6