15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started
30.10.2024

How to Configure Networking in Ubuntu 16.04: A Complete Step-by-Step Guide

Networking is one of the most fundamental aspects of any Linux system. Whether you are managing a production server, spinning up a virtual machine, or configuring a desktop environment, getting your network settings right is essential for connectivity, security, and performance. In Ubuntu 16.04, networking is handled by the ifupdown utility, which reads its configuration from the /etc/network/interfaces file — a straightforward but powerful approach to network management.

This guide walks you through every step required to configure networking on Ubuntu 16.04, from opening the configuration file to verifying a live connection. Whether you are running Ubuntu on a local machine or on a VPS Hosting plan, these instructions apply directly to your environment.

Prerequisites

Before you begin, make sure you have:

  • A running Ubuntu 16.04 system (physical, virtual, or cloud-based)
  • Sudo or root access to the machine
  • Basic familiarity with the Linux terminal
  • Your network details ready: desired IP address, subnet mask, gateway, and DNS servers

Understanding How Ubuntu 16.04 Manages Networking

Unlike newer Ubuntu releases that use Netplan (introduced in Ubuntu 17.10), Ubuntu 16.04 relies on the classic ifupdown framework. The primary configuration file is:

/etc/network/interfaces

This file defines how each network interface behaves at boot time and when brought up or down manually. It supports both DHCP (automatic IP assignment) and static IP configurations, making it flexible for a wide range of use cases — from home labs to enterprise servers.

Step 1: Identify Your Network Interface Name

Before editing any configuration, you need to know the exact name of your network interface. Ubuntu 16.04 may use traditional names like eth0 or newer predictable names like enp0s3, depending on your hardware and system configuration.

Run the following command to list all available network interfaces:

ip link show

Sample output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
    link/ether 08:00:27:xx:xx:xx brd ff:ff:ff:ff:ff:ff

In this example, the active interface is enp0s3. Note down your interface name — you will need it throughout this guide.

Alternatively, you can use:

ifconfig -a

> Note: If ifconfig is not available, install it with sudo apt install net-tools.

Step 2: Open the Network Configuration File

The /etc/network/interfaces file is the central configuration point for networking in Ubuntu 16.04. Open it using a text editor with elevated privileges:

sudo nano /etc/network/interfaces

You will typically see a default configuration similar to this:

# 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 enp0s3
iface enp0s3 inet dhcp

The inet dhcp line means the interface is currently set to obtain an IP address automatically via DHCP. In the next steps, we will show you how to configure both DHCP and static IP setups.

Step 3: Configure a Static IP Address

A static IP address is essential for servers, network appliances, and any system that needs a consistent, predictable address. If you are hosting websites, databases, or services on a Dedicated Server or VPS, a static IP is strongly recommended.

3.1 Replace the DHCP Configuration

Locate the section for your primary interface and replace the dhcp line with a static configuration block. Here is the full syntax:

auto enp0s3
iface enp0s3 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4

3.2 Understanding Each Directive

DirectiveDescription
auto enp0s3Automatically brings up the interface at boot
iface enp0s3 inet staticDeclares a static IPv4 configuration
addressThe static IP address you want to assign
netmaskDefines the subnet mask (e.g., /24 = 255.255.255.0)
gatewayThe default gateway (usually your router's IP)
dns-nameserversSpace-separated list of DNS resolver addresses

3.3 Example with Custom Values

Replace the example values with your actual network details:

auto enp0s3
iface enp0s3 inet static
    address 203.0.113.50
    netmask 255.255.255.0
    gateway 203.0.113.1
    dns-nameservers 1.1.1.1 8.8.8.8

> Tip: Use Google's public DNS (8.8.8.8, 8.8.4.4) or Cloudflare's (1.1.1.1, 1.0.0.1) for reliable name resolution. Proper DNS configuration is especially important if you are managing Domain Registration or running mail servers.

Once you have made your changes, save the file by pressing Ctrl + O, then Enter, and exit with Ctrl + X.

Step 4: Configure DHCP (Optional)

If you prefer automatic IP assignment — common in development environments or desktop setups — configure the interface to use DHCP instead:

auto enp0s3
iface enp0s3 inet dhcp

This is the default configuration in most Ubuntu 16.04 installations. DHCP is convenient but not suitable for servers or systems that need a fixed address.

Step 5: Configure Multiple Network Interfaces (Optional)

If your system has more than one network interface — for example, a public-facing interface and a private internal one — you can define both in the same file:

# Public interface (static)
auto enp0s3
iface enp0s3 inet static
    address 203.0.113.50
    netmask 255.255.255.0
    gateway 203.0.113.1
    dns-nameservers 8.8.8.8 8.8.4.4

# Private/internal interface (static)
auto enp0s8
iface enp0s8 inet static
    address 10.0.0.10
    netmask 255.255.255.0

This configuration is particularly useful in cloud and virtualized environments where a server may have both a public IP and a private network IP for internal communication.

Step 6: Restart the Networking Service

After saving your changes to /etc/network/interfaces, you must restart the networking service for the new configuration to take effect.

sudo systemctl restart networking

Method 2: Bringing the Interface Down and Up

For a more targeted approach that avoids disrupting other interfaces:

sudo ifdown enp0s3 && sudo ifup enp0s3

> Warning: If you are connected to the server remotely via SSH, restarting networking may temporarily drop your connection — especially if you are changing from DHCP to a static IP. Make sure you have console or out-of-band access available, or use a terminal multiplexer like tmux or screen to protect your session.

Step 7: Verify the Network Configuration

Once the networking service has restarted, verify that your settings have been applied correctly.

7.1 Check the Assigned IP Address

ip addr show enp0s3

Expected output (static IP example):

2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
    inet 192.168.1.100/24 brd 192.168.1.255 scope global enp0s3

7.2 Verify the Default Gateway

ip route show

You should see a line like:

default via 192.168.1.1 dev enp0s3

7.3 Test DNS Resolution

ping -c 4 google.com

A successful response confirms that both your network connectivity and DNS resolution are functioning correctly:

PING google.com (142.250.185.46) 56(84) bytes of data.
64 bytes from lga34s32-in-f14.1e100.net: icmp_seq=1 ttl=117 time=12.3 ms

7.4 Test Connectivity to the Gateway

ping -c 4 192.168.1.1

If this succeeds but ping google.com fails, the issue is likely with DNS configuration rather than network connectivity itself.

Troubleshooting Common Networking Issues

Even with a correct configuration, issues can arise. Here are the most common problems and how to resolve them:

Interface Not Coming Up After Reboot

  • Double-check that the auto directive is present before the iface line
  • Verify there are no typos in the interface name (use ip link show to confirm)
  • Check system logs: sudo journalctl -u networking

This error occurs when trying to bring up an interface that is already configured. Bring it down first:

sudo ifdown enp0s3
sudo ifup enp0s3

DNS Not Resolving

  • Confirm dns-nameservers is correctly set in /etc/network/interfaces
  • Check /etc/resolv.conf to see if it contains the correct nameserver entries
  • Install resolvconf if DNS entries are not being applied: sudo apt install resolvconf

Cannot Ping the Gateway

  • Verify the gateway IP is correct for your network
  • Ensure the interface is UP: ip link show enp0s3
  • Check for IP address conflicts on the network

Advanced Configuration: Adding a Secondary IP Address

Ubuntu 16.04 supports interface aliases, which allow you to assign multiple IP addresses to a single physical interface. This is useful for hosting multiple websites or services on one machine — a common scenario when using Shared Web Hosting or managing your own server.

# Primary IP
auto enp0s3
iface enp0s3 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4

# Secondary IP (alias)
auto enp0s3:0
iface enp0s3:0 inet static
    address 192.168.1.101
    netmask 255.255.255.0

Security Considerations for Network Configuration

Proper network configuration goes hand in hand with security. Here are a few best practices to keep in mind:

  1. Use a firewall: Install and configure ufw (Uncomplicated Firewall) to restrict inbound and outbound traffic.
  2. Disable unused interfaces: If an interface is not needed, comment it out or remove it from the configuration file.
  3. Secure your DNS: Consider using encrypted DNS (DNS-over-HTTPS or DNS-over-TLS) for sensitive environments.
  4. Use SSL/TLS for services: Any web service or application running on your server should be protected with a valid certificate. AlexHost offers affordable SSL Certificates to secure your domains and services.
  5. Monitor network activity: Use tools like netstat, ss, or iftop to monitor active connections and bandwidth usage.

Conclusion

Configuring networking in Ubuntu 16.04 using the /etc/network/interfaces file is a reliable and well-documented process. By following this guide, you can:

  • Assign static IP addresses to your network interfaces
  • Configure DNS resolvers for reliable name resolution
  • Set up multiple interfaces or IP aliases
  • Verify and troubleshoot your network configuration with confidence

Whether you are managing a home lab, a development environment, or a production server, mastering network configuration is a foundational skill for any Linux administrator. If you are looking for a robust hosting environment to deploy your Ubuntu servers, explore AlexHost's VPS Hosting plans — built for performance, reliability, and full root access so you can configure your network exactly the way you need it.

15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started