These instructions are for Ubuntu 16 and older. If you have another operating system, please consult documentation to learn how to adjust those to a static IP address.
Please note that this guide does not allow you to just arbitrarily set any public IP address on the Internet, you can’t just pick and choose an IP address on the Internet. It has to be assigned to you by your service provider and has to be available for use before you can use it. And on cloud environments, generally you are not supposed to touch the operating system network configuration at all, since attaching and assigning a public IP address is generally handled in the cloud management web portal, and not in the OS itself, in most cases. But for deployments on a local network or a private network, and you need to set a static IP for the operating system that runs the Access Server software, this guide will be useful.
We also assume that you do not use the Ubuntu program NetworkManager. If you do, and you have a GUI on your server, you may want to instead do it via the GUI. But if you have a headless server running on a physical server, or on HyperV, ESXi, and so on, you can use this guide to set a static IP address. The process is relatively straightforward, there is a text file that contains the configuration for your network interfaces. Adjust it to look like the sample below and adjust the addresses to match your network and your desired static IP. We assume an IPv4 address because at the moment this documentation section was written the Access Server only supported incoming OpenVPN tunnel connections on IPv4.
Changing the network interface settings could mean you lose network access to this system if you make a mistake. So be aware of this and either beforehand make a backup of your Access Server settings or make a snapshot if possible in your hypervisor or cloud environment, or see if can get access to the (virtual) console to make corrections afterwards.
It is also important to note that if you have a DHCP server in your network you can also choose to use the DHCP reservation option there (if present) to always assign the same DHCP IP address to this server. But not all DHCP servers have this option. In such a case you can still do the static IP address assignment in the Linux server operating system itself with the instructions below, but please then do not configure the static IP to one inside of the DHCP range, but outside of it. Otherwise the DHCP server may consider the IP address you have chosen for your server suitable for assignment to a DHCP client, and that can cause an IP address conflict. Some networks have no DHCP server at all, and in that case you can pick any free IP you want with the instructions below.
Open the file /etc/network/interfaces in the nano text editor:
If you see in the contents of that file a message like “ifupdown has been replaced by netplan on this system, see /etc/netplan for current configuration" then your system is apparently using netplan for configuration instead. We have another guide to cover that type of configuration and you should then instead use this guide:
Example contents of the interfaces file:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto ens192 iface ens192 inet static address 192.168.70.2 netmask 255.255.255.0 network 192.168.70.0 broadcast 192.168.70.255 gateway 192.168.70.254 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 192.168.70.254
Press ctrl+x, then press y, and then press enter, to save and exit the file. You should reboot to allow the changes to take effect.
In the example above, the IP address is set to 192.168.70.2 and it is in the 192.168.70.0/24 network with an Internet gateway and DNS server at 192.168.70.254. In some situations if the DNS server needs to be changed and you have things set statically you’ll need to edit /etc/resolv.conf and update it to have the correct DNS server. Without a working DNS server you’ll be able to ping IP addresses like 184.108.40.206 on the Internet, but not be able to resolve and ping addresses like www.openvpn.net. In the resolv.conf file you can fix that. Another important thing to note here is that in our situation shown above we have only one network interface and it is called ens192. If it is called something else in your system, obviously make allowances for this and adjust things as necessary.
If you have successfully changed the IP address, and you can gain access via SSH to the server, but the Access Server web services are not responding, it is possible you had your Access Server configured to listen to a very specific IP address, and if you have changed this, then the Access Server web services won’t start. We have a guide to reset the web services and daemon ports here to resolve that issue.