Knowing how to configure and display network settings is essential when installing an Ubuntu server or desktop. It is also useful for troubleshooting problems with your Internet connection. The basic network configuration includes setting the IP address, the subnet mask for internal communication and a gateway for connecting to external networks. In this article, I will give you examples of the basic configuration you need to set up a network in Ubuntu by either using the Command line or the Ubuntu Network Manager GUI. The steps have been tested on Ubuntu 18.04 TLS but will work on newer Ubuntu versions too.

Basic network setup requires:

  1. Setting/Changing an IP address
  2. Setting up/Changing Hostname
  3. Editing a hosts file

Setting/Changing an IP address

There are several ways to set an IP address in Ubuntu. You can configure the network interface to use dynamic IP using DHCP server or you can manually set a static IP address.

Method #1: Network configuration on the command line

In Ubuntu, you can set IP address through terminal commands.

First type netstat –I to find the interface name. Then type the below command:

sudo ifconfig eth0 192.168.72.6 netmask 255.255.255.0

Configure network address using ifconfig command

Then to add a default gateway, add the below command:

sudo route add default gw 192.168.72.1 eth0

Set default gateway in Ubuntu Network config

Method #2: Network configuration using the GUI

You can set an IP address via the graphical user interface in Ubuntu. From the desktop, click on the start menu and search for Settings. From the Settings window, click on the Network tab. Then from the right pane, select the interface and click on the gear icon to open settings for that interface.

Network configuration using Ubuntu GUI

From the IPv4 tab, you can select the Automatic (DHCP) radio button to allow the system to dynamically obtain the IP address.

Get IP address using DHCP

If you want to set a static IP address, click on the Manual radio button. Enter the IP address, subnet mask, and a default gateway. Then click on Apply to save the current changes.

Manual IPv4 address configuration

Method #3: Configure the network by editing /etc/interfaces file

Here is another method which you can use to configure the IP address. To set IP address dynamically, you have to edit /etc/network/interfaces. In /etc/network/interfaces, the basic configuration of interfaces is stored.

Edit the /etc/network/interfaces by entering the following command in terminal.

sudo nano /etc/network/interfaces

Then add the following lines:

auto eth1
  iface eth1 inet dhcp

Add new eth1 interface

Save the file and restart networking services using the below command.

sudo systemctl restart networking

To set a Static IP address, you have to edit /etc/network/interfaces

 sudo nano /etc/network/interfaces

Add the below lines to /etc/network/interfaces.

auto eth1
  iface eth1 inet static
  address 192.168.72.8
  netmask 255.255.255.0
  gateway 192.168.72.1
  dns-nameservers 8.8.8.8 4.4.2.2

Static IP address configuration in /etc/interfaces file

Save the file and restart networking services.

sudo systemctl restart networking

Setting up/Changing Hostname

The hostname of Ubuntu OS is configured in the file /etc/hostname.

To edit /etc/hostname, enter the below command:

sudo nano /etc/hostname

This file contains only the hostname of the file, change the name, and then save it.

Edit Ubuntu hostname

Editing the hosts file

Hosts file maps hostname to IP address locally. For instance, you have a server in your local network, instead of remembering its IP, you can map its IP with a name in your hosts file. It will allow you to access that machine with a name instead of the IP.

To edit a hosts file, enter:

sudo nano /etc/hosts

Add the server IP address and name in the hosts file in the following format.

192.168.72.10 fileserver

Set hostname in /etc/hosts file

Save the file and reboot the system to apply changes.

That’s all you need to set up a network in Ubuntu to start with. These were the basic configurations, there are a lot more advanced options you can configure within your Ubuntu machine.

How to Configure Network Settings in Ubuntu