How to Configure Network Settings in Ubuntu 22.04

Properly configuring networking is vital for any Ubuntu desktop or server. In this introduction, we’ll cover the key topics involved in managing network settings on Ubuntu 22.04 systems.

We’ll discuss core networking concepts like:

  • Ethernet interfaces – Naming, logical mappings, and optimizing performance
  • IP addressing – Dynamic DHCP, static IPs, and name resolution with DNS
  • Bridging – Joining multiple interfaces together
  • Static IP configuration on Ubuntu desktops
  • ifconfig, nmcli: Command-line tools that can be used to configure Ubuntu network settings

Read: Virtual host configuration in Apache

Ubuntu 22.04 network configuration

Ubuntu 22.04 offers powerful tools for network configuration like Netplan, NetworkManager, systemd-networkd, and /etc/network/interfaces.

We’ll cover :

  • How to Set static or dynamic IP addresses
  • How to configure static IP address in Ubuntu 22.04 LTS
  • How to set network configuration in Ubuntu 
  • How to Define DNS servers for name resolution
  • How to Manage Ubuntu firewall settings policies with UFW
  • How to Configure bridging and VLANs
  • How to reset Ubuntu network settings

Whether you need to set up a simple DHCP client or optimize complex bonding with Netplan, this guide will help you master network settings in Ubuntu 22.04.

Read: What you need to do to secure Ubuntu

Ethernet Interface Management in Ubuntu 22.04

Ethernet is a wired networking technology that uses cables to connect devices to a network. In Ubuntu 22.04, Ethernet interfaces can be managed using a variety of tools and methods.

Checking Ethernet Interface Status

The first step in managing an Ethernet interface is to check its status. This can be done using the following commands:

 ip link show

This command will list all of the network interfaces on the system, including the Ethernet interfaces. The output of this command will show the status of each interface, such as whether it is up or down, and its MAC address.

ifconfig

This command is a legacy command that can also be used to check the status of network interfaces. The output of this command is similar to the output of the ip link show command.

If it is not installed on your system, execute the command below :

sudo apt install net-tools

Now , you will be able to invoke the ifconfig command:

Read: Guide to Linux Config Files

How to List All Network Interfaces in Ubuntu 22.04

In Ubuntu 22.04, there are two ways to list all network interfaces:

Using the ip a command: This command will list all network interfaces, including their logical names, IP addresses, and other settings.

ip a

command ip a

This output shows that there are two network interfaces on the system: lo and enp0s3. The lo interface is a loopback interface, which means that it is connected to itself. The enp0s3 interface is a physical interface that is connected to a network.

The inet entry for each interface shows the IP address and subnet mask for the interface. The valid_lft and preferred_lft entries show the lifetime of the IP address.

Using the sudo lshw -class network command: This command will list all network interfaces, as well as more detailed information about each interface, such as its bus information, capabilities, and driver details.

sudo lshw -class network

command lshw -class network

The ip a command is a quick and easy way to get a list of all network interfaces. However, the sudo lshw -class network command provides more detailed information that can be useful for troubleshooting or configuring Ubuntu etc network interfaces.

Configuring Ethernet Interfaces on Ubuntu 22.04

Ethernet interfaces can be configured in a variety of ways. Some of the most common configuration options include:

  • IP address: The IP address is a unique identifier for a device on a network.
  • Netmask: The netmask is used to mask part of the IP address, which allows the device to distinguish between different networks.
  • Gateway: The gateway is the address of the router that the device uses to connect to other networks.
  • DNS servers: The DNS servers are used to resolve hostnames to IP addresses.

Where is the network config file in Ubuntu?
These configuration options can be set using the netplan configuration file. The netplan file is located in the /etc/netplan directory.

Read: Configuring static and dynamic IP Addresses in Ubuntu using Netplan

Logican naming of Ethernet Interfaces

Ubuntu uses predictable naming for Ethernet interfaces based on device attributes. Common names like eno1 follow the pattern en (Ethernet) o (onboard) 1 (index).

Modifying Ethernet Interface Names

With netplan, we can configure custom logical interface names by matching on attributes like MAC address. Set the new name using set-name in the YAML config:

match:

macaddress: 11:22:33:44:55:66

set-name: mynic1

The process of “matching” involves utilizing specific criteria such as MAC address, driver, and other parameters to locate a corresponding adapter.

network:

version: 2

renderer: networkd

ethernets:

ethpn0:

dhcp4: true

match:

macaddress: 66:55:44:33:11:00

set-name: ethpn0

Viewing Ethernet Interface Settings

The ethtool utility displays configured settings and supported features of Ethernet adapters like speed, duplex mode, and Wake-on-LAN:

ethtool enp0s3

ethtool

If ethtool is not installed, run:

sudo apt-get install ethtool

command apt-get install ethtool

You can tune interface settings with ethtool (see next section):

ethtool -s enp0s3 speed 1000 duplex full autoneg off

You will also be able to view detailed interface statistics with:

ip -s link

And check operational state in /sys/class/net/enp0s3/operstate. This provides valuable telemetry for troubleshooting.

Read: How to display your sound card details using the terminal on Ubuntu 22.04

Configuring Ethernet Speed and Duplex

You can set appropriate Ethernet speed and duplex based on your network using the following command for instance:

ethtool -s enp0s3 speed 100 duplex full autoneg off

This disables auto-negotiation and forces 100Mbps full duplex. Auto-negotiation should be used when possible for maximum compatibility.

Check your switch port configuration to determine if auto-negotiation, speed, and duplex need to be hard-set. Mismatched settings can cause performance issues.

Setting the Ethernet MTU

The maximum transmission unit (MTU) limits the Ethernet frame size. Set your MTU to match network infrastructure:

ip link set mtu 9000 dev enp0s3

Larger MTUs improve performance with supported equipment. 1500 is standard.

Bringing Up and Down Ethernet Interfaces

Ethernet interfaces can be brought up and down using the following commands:

ip link set dev <interface> up

This command brings the specified interface up.

ip link set dev <interface> down

This command brings the specified interface down.

Tuning Ethernet Offloading and Segmentation

Advanced NICs support options like TCP segmentation offload (TSO), generic receive offload (GRO), and others to reduce CPU usage. Enable if supported:

ethtool -K eno1 tso on gro on gso on

Offloading is usually enabled by default but can be checked and tuned.

Persisting Ethernet Configuration

Changes made with ip and ethtool are temporary. To persist, edit Netplan YAML:

/etc/netplan/01-netcfg.yaml

network:

ethernets:

eno1:

mtu: 9000

dhcp4: no

addresses: [192.168.1.100/24]

gateway4: 192.168.1.1

nameservers:

addresses: [1.1.1.1, 8.8.8.8]

optional: true

Or use traditional interface files like /etc/network/interfaces.d var wpcf7 = {"apiSettings":{"root":"https:\/\/net2.com\/wp-json\/contact-form-7\/v1","namespace":"contact-form-7\/v1"},"cached":"1"};