This document is intended to support Ubuntu server administrators and aims to help you manage your network using the command line.
In order to identify the list of all network interfaces that are attached on your system, issue the command below :
It is also possible to list all network interfaces available by running the command :
sudo lshw -class network
The command lshw yields more details around specific adapters hardware capabilities. In the snapshot above for instance, we can see only one single Ethernet interface having the logical name of enp0s3 as well as the bus information and all the supported capabilities along with the driver details.
It is also possible to configure Interface logical names via a netplan configuration. In order to assign a specific logical name to a network interface, you would have to use the match and set-name keys. The latter is used to change the logical name of the device whereas the former key(match) relies on some criteria like MAC address, driver…in order to find an adapter.
ethtool is a utility used to change and display Ethernet card settings like for instance port speed, duplex mode, auto-negotiation and Wake-on-LAN. The snapshot below shows some configured settings and supported features of an Ethernet interface.
If ethtool is not installed then issue the command below :
sudo apt-get install ethtool
In order to manage communication on a network(LAN or the Internet ), you will need to configure your systems IP address and default gateway.
In order to configure a network on a temporary manner, you can rely on the ip command which is also installed on most other GNU/Linux distros. The settings configured with the ip command are immediate but they are not persistent since they will be lost after a system reboot.
For temporary IP Address configuration, proceed as follows. Remember to modify the IP address and subnet mask according to your needs :
sudo ip addr add 10.0.32.15/24 dev enp0s3
Now in order to check the IP address configuration of enp0s3, proceed as follows:
ip address show dev enp0s3
You can also configure a default gateway in the following manner. Remember to alter the default gateway address as per your network requirements :
sudo ip route add default via 10.0.2.1
Your default gateway configuration can now be checked by issuing the ip command below :.
ip route show
In case you need DNS for your temporary network configuration, you can edit the file /etc/resolv.conf and insert DNS server IP addresses.
As a good practice, it is not recommended to edit /etc/resolv.conf directly, but this is a non-persistent and temporary configuration. You can for instance enter two DNS servers to /etc/resolv.conf like :
In case you want to undo all your changes or if you do not need this configuration any longer, you can issue the ip command below which will purge the temporary IP configuration from the network interface :
ip addr flush enp0s3
You must either reboot or remove or alter manually the entries of /etc/resolv.conf since the flushing operation above does not clear the contents of /etc/resolv.conf.
You may be interested to read: How to install Apache web server on Ubuntu ?
In order to configure and manage network interfaces, Ubuntu relies on a command line based utility called Netplan which was introduced in Ubuntu 17.10.
Netplan, which works in tandem with Network Manager and systemd-networkd daemons (as interfaces to the kernel), is based on the YAML files making therefore the configuration of network interfaces very easy.
Netplan no longer relies on the configuration file /etc/network/interfaces but uses instead the /etc/netplan/*.yaml to read the network configuration. This is used as a location to save all your network interface configurations.
In order to enable DHCP for dynamic (non static) address assignment in your server, create a netplan configuration in the file within the directory /etc/netplan/ , mine has the name shown below, i.e. 01-network-manager-all.yaml :
Which is used to configure the first interface. If you have more than one interface however, use 02-network-manager-all.yaml for instance for the second interface. Note that Netplan uses the numerical order when it applies the configurations which means that the 02 file will be applied after the 01 file.
Your configuration should look like the example below in which it is assumed that you are configuring the second Ethernet interface enp3s1 (therefore file 02-network-manager-all.yaml).
In order to apply the configuration using netplan, issue the command below :
sudo netplan apply
Now for static address assignment configuration, you can create a netplan configuration in the file /etc/netplan/01-network-manager-all.yaml. If for instance you would like to configure your first Ethernet interface then you can follow the example shown below. Recall to alter the addresses, gateway4, and nameservers values according to your network needs :
search: [mydomain, otherdomain]
addresses: [10.0.12.1, 18.104.22.168]
Once again apply the configuration using the command :
sudo netplan apply
You may be interested to read: Configuring static and dynamic IP Addresses in Ubuntu using Netplan
The process of mapping IP addresses to hostnames is called name resolution (in relation to IP networking). It makes resources identification on a network quite easy. You will see how to set up your system for name resolution with the help of DNS.
The file /etc/resolv.conf used to store static configurations that were almost never altered nor automatically changed via DCHP. Name server configuration is handled via Systemd-resolved through the systemd-resolve command. Netplan uses systemd-resolved daemon in order to generate nameservers and domains to be stored in /etc/resolv.conf, which is a symlink:
Insert the nameservers IP addresses to the netplan configuration file, in order to configure the resolver,. To match your network domain names, you can also include a DNS search-lists optional suffix. The file obtained should look like the output below :
In multiple scenarios, Bridging multiple interfaces is an advanced configuration which is very useful. One scenario would be to configure a bridge with multiple network interfaces. Then in order to filter the traffic between two network segments, a firewall is used. Another example use case would be to use bridge on a 1-interface system in order to enable VMs to access the outside world or network directly. Here is an example of the latter use case :
Now enable the bridge by issuing the command:
sudo netplan apply
The bridge interface created should now be active . The state of the bridge can be controlled via the brctl which. Use man brctl for more .
Ubuntu offers an easy-to-use graphical interface which allows you to set up a static IP address.
1 – On the top right screen, click on the network icon :
2 – Now click on the tools icon on the bottom left corner of the black window.
3 – The Network configuration window will show up. Click on the cog icon in the Wired section next to the ON button.
4. This will display the Network interface settings window :
5 . In “IPv4 Method” enter your static IP address after selecting “Manual”. Enter also the Netmask and Gateway according to your network needs.Then click on the “Apply” button.
Once your static IP Address is set up, open up your terminal and verify the changes by running the command :