How to configure network settings in Ubuntu

Knowing how to configure and display network settings is required when installing an Ubuntu server or desktop. This is also useful for troubleshooting Internet connectivity issues. The basic network configuration includes setting the IP address, subnet mask for internal communications and a gateway for connecting to external networks. In this article, I will give examples of the basic configuration that is required to configure a network in Ubuntu using the command line or the graphical interface of Ubuntu Network Manager. The steps were tested on TLS Ubuntu 18.04, but will work on newer versions of Ubuntu.

Basic network setup requires:

  1. Setting / changing IP address
  2. Configure / change host name
  3. Editing the hosts file

Setting / changing IP address

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

Method number 1: Configure the network on the command line

In Ubuntu, you can set the IP address using terminal commands.

First type netstat –I find the name of the interface. Then enter the following command:

sudo ifconfig eth0 netmask

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

sudo route add default gw eth0

Set default gateway in Ubuntu network configuration

Method # 2: Configuring a Network Using the GUI

You can set the IP address through the graphical user interface in Ubuntu. On the desktop, click the Start menu and search settings, In the settings window, click on network tab, Then, in the right pane, select an interface and click the gear icon to open the settings for that interface.

Network Configuration Using Ubuntu GUI

From IPv4 tab you can choose Automatic (DHCP) A switch that allows the system to dynamically obtain an IP address.

Get IP Address Using DHCP

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

Manual IPv4 Address Setting

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

Here is another method you can use to configure the IP address. To set the IP address dynamically, you must edit / Etc. / networks / interfaces. IN / etc. / network / interfacesThe basic configuration of the interfaces is preserved.

Edit / etc. / network / interfaces by entering the following command in the 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 the network services using the command below.

sudo systemctl restart networking

To set a static IP, you must edit / etc. / network / interfaces

 sudo nano /etc/network/interfaces

Add the following lines to / etc. / network / interfaces,

auto eth1
  iface eth1 inet static

Static IP configuration in / etc / interfaces

Save the file and restart the network services.

sudo systemctl restart networking

Configure / change host name

Ubuntu OS hostname is configured in the file / Etc. / hostname,

Edit / Etc. / hostnameenter the following command:

sudo nano /etc/hostname

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

Change Ubuntu Host Name

Editing the hosts file

The host file maps the host name to the IP address locally. For example, you have a server on the local network, instead of remembering its IP, you can map its IP to the name in your hosts file. This will allow you to access this machine with a name instead of IP.

To edit the hosts file, enter:

sudo nano /etc/hosts

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

Set the host name in the / etc / hosts file

Save the file and reboot the system for the changes to take effect.

This is all you need to configure your network in Ubuntu. These were basic configurations, there are much more complex settings that you can configure on your Ubuntu computer.

How to configure network settings in Ubuntu