Ubuntu 16.04 Server / How to configure a static IP address

On Ubuntu 16.04 Server, a static IPv4 (Internet Protocol version 4) address managed by the ifupdown network tool is configured in /etc/network/interfaces or a file it includes. Confirm the real interface, address, netmask, gateway and DNS, back up the configuration and secure recovery-console access before applying it.

Check whether this procedure fits your server

This guide maintains a typical single wired interface in an existing Ubuntu 16.04 ifupdown setup. Do not add the same configuration unchanged to a server managed by Netplan, NetworkManager or a cloud initialization tool. Identify the current network manager and configuration source first.

Ubuntu 16.04 is an old release. Standard support ended in 2021, and regular ESM (Expanded Security Maintenance) ended in 2026. For continued operation, check Legacy add-on coverage and a migration plan using Canonical’s Ubuntu 16.04 support information. This is not the default networking procedure for current Ubuntu releases.

Interface names vary between servers. Use these commands to identify the distribution, devices, current IPv4 addresses and default route. Find the device actually carrying your connection rather than copying the example enp0s3.

lsb_release -ds
ip -o link show
ip -4 addr show
ip -4 route
cat /etc/network/interfaces
dpkg -l ifupdown resolvconf

In ip -4 route, default via identifies the default gateway and dev identifies its interface. Compare this with the configuration. Check package installation status in dpkg -l. If the file is absent or another manager is responsible, stop and use that environment’s procedure.

Choose the address, gateway and DNS

A static address is not an arbitrary value to choose on the server. Use an administrator-assigned address and check DHCP (Dynamic Host Configuration Protocol) reservations or exclusions to avoid the allocation pool. An address that does not respond is not necessarily unused.

  • Address and netmask: the example uses 192.168.10.50 and 255.255.255.0, equivalent to 192.168.10.50/24. Do not assign this subnet’s network address 192.168.10.0 or broadcast address 192.168.10.255 to a host.
  • Gateway: the example is 192.168.10.1, directly reachable on the same network. This single-interface example uses one default route. Servers with multiple networks or routing policies need a separate design.
  • DNS: choose a DNS (Domain Name System) server that resolves names to addresses. The example 192.168.10.1 works only if that device also answers DNS queries. For internal domains, use your organization’s DNS that can resolve them.

These values describe one private-network example. Adapt them to the VM’s NAT, bridged or host-only network and the cloud provider’s allocation rules. Fixing a guest’s private IP can be different from reserving an external public IP.

Back up the configuration and replace DHCP with static

  1. First verify physical-console, virtualization-console or cloud recovery access. Changing an address over SSH (Secure Shell) alone may leave you unable to recover after disconnection. Schedule downtime and record the old addresses, routes and DNS.
  2. Back up network configuration to a separate location. If the backup name already exists, choose another.
sudo cp -a /etc/network /etc/network.before-static-ip
sudoedit /etc/network/interfaces

Inspect included files when source or source-directory is present. If the actual interface is defined under /etc/network/interfaces.d/, edit that file rather than duplicate the definition in the main file. For cloud-generated files, check whether boot will overwrite them and follow the provider’s supported method.

  1. Locate the DHCP stanza below. Modify the existing IPv4 stanza for the actual interface; do not create a different device name.
auto enp0s3
iface enp0s3 inet dhcp
  1. Replace only that stanza as follows. Preserve other interfaces, IPv6 settings, include directives and loopback configuration.
auto enp0s3
iface enp0s3 inet static
    address 192.168.10.50
    netmask 255.255.255.0
    gateway 192.168.10.1
    dns-nameservers 192.168.10.1

This block does not replace the whole file. Preserve existing entries such as auto lo and iface lo inet loopback. auto selects interfaces brought up automatically at boot; inet static selects static IPv4 configuration. See the ifupdown interfaces manual for syntax.

Understand when dns-nameservers takes effect

dns-nameservers serves a different role from the IP address and default route. On Ubuntu 16.04, resolvconf and its ifupdown integration scripts must operate to pass this value into DNS configuration. The Ubuntu 16.04 resolvconf manual describes that integration and space-separated multiple DNS addresses.

If /etc/resolv.conf is generated automatically, direct edits can be overwritten. Inspect its actual target and contents with these commands, and list registered DNS information if resolvconf is available.

readlink -f /etc/resolv.conf
cat /etc/resolv.conf
if command -v resolvconf >/dev/null 2>&1; then
    resolvconf -l
fi

Without the package or integration, adding dns-nameservers alone does not change DNS. Identify and adjust the active DNS manager first. Some setups show a local caching resolver in resolv.conf; the absence of an external DNS address there does not itself indicate failure.

Apply the saved configuration and verify it

  1. After saving, inspect the interface settings read by ifupdown. The name, address, netmask and gateway must match your plan. This command reads configuration without applying it to the network.
ifquery enp0s3

A successful ifquery does not test address conflicts or real connectivity. Fix include files, interface names and syntax first if it reports errors or an undefined interface. See the ifupdown ifquery and ifup manual for its scope.

  1. With recovery-console access and downtime arranged, reboot to apply the boot configuration. The following restarts the entire server; run it only when preparations are complete.
sudo reboot

Restarting the network service alone does not guarantee that old addresses and DHCP state are cleared. Repeatedly rebooting because the IP has not changed does not fix configuration errors either. After boot, inspect addresses and routes at the console, then reconnect to the new IP.

ip -4 addr show dev enp0s3
ip -4 route
ping -c 3 192.168.10.1
getent ahostsv4 ubuntu.com

For the example, the interface should show 192.168.10.50/24 and the route should include default via 192.168.10.1 dev enp0s3. Check gateway connectivity separately from name resolution. If ICMP replies are blocked, do not infer an outage from ping failure alone; test the required services and access from another client.

Diagnose failures and restore the old configuration

If no address appears, check the device name, file location, manager and syntax. If an address exists but other networks are unreachable, check netmask, gateway and routes. If IP connectivity works but names fail, check DNS and internal-domain policies. Wrong addresses, overlapping DHCP allocations and duplicate definitions in other files can also cause trouble.

Inspect service errors with sudo systemctl status networking.service and sudo journalctl -u networking.service -b --no-pager. A healthy service status does not establish correct addressing or connectivity; compare the checks above.

If rollback is needed, use the recovery console to restore only the files changed in this operation. The example below assumes only /etc/network/interfaces was modified. If you edited a snippet, restore its corresponding backup to its proper location. Do not overwrite unrelated changes made since the backup by copying the whole directory back.

sudo cp -a /etc/network.before-static-ip/interfaces /etc/network/interfaces
sudo reboot

If the old configuration used DHCP, the same address is not guaranteed after reboot. Check the assigned address and default route at the console, then confirm DNS and management access are restored before finishing.