Skip to main content
  1. Linux Articles/
  2. Ubuntu 26.04 LTS Server/

Configuring the Network on Ubuntu 26.04 LTS Server

Table of Contents

This article introduces the network configuration procedure for Ubuntu 26.04 LTS Server. The configuration method differs from Desktop — the steps shown here are for Server. In addition to IPv4, this article also covers IPv6 configuration.

How to Check the Current Network Configuration

You can check the current network configuration with the ip command.

Command to Check the IP Address
ip a
Example Output of the IP Address Check Command
ubuntu@ubuntu2604:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:0e:cf:b9 brd ff:ff:ff:ff:ff:ff
    altname enx5254000ecfb9
    inet 10.100.41.128/22 brd 10.100.43.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe0e:cfb9/64 scope link proto kernel_ll
       valid_lft forever preferred_lft forever
ubuntu@ubuntu2604:~$

Check the default gateway with ip route, and the DNS server with resolvectl status.

Example Output of the Default Gateway Check Command
ubuntu@ubuntu2604:~$ ip route
default via 10.100.40.1 dev enp1s0 proto static
10.100.40.0/22 dev enp1s0 proto kernel scope link src 10.100.41.128
ubuntu@ubuntu2604:~$
Example Output of the DNS Server Check Command
ubuntu@ubuntu2604:~$ resolvectl status
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 2 (enp1s0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 10.1.0.1
       DNS Servers: 10.1.0.1 10.1.0.2
     Default Route: yes
ubuntu@ubuntu2604:~$

About Netplan

Unlike Desktop, which uses NetworkManager, Ubuntu Server configures the network using a mechanism called Netplan. Netplan reads YAML configuration files placed under /etc/netplan/ and applies the network configuration through its backend, systemd-networkd.

You can check the contents of the configuration file that is generated automatically during installation with the following commands.

Example of Checking the Netplan Configuration File
root@ubuntu2604:/etc/netplan# pwd
/etc/netplan
root@ubuntu2604:/etc/netplan# cat 00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    enp1s0:
      addresses:
      - 10.100.41.128/22
      match:
        macaddress: 52:54:00:0e:cf:b9
      nameservers:
        addresses:
        - 10.1.0.1
        - 10.1.0.2
        search: []
      routes:
      - to: default
        via: 10.100.40.1
      set-name: enp1s0
  version: 2
root@ubuntu2604:/etc/netplan#

The main items in the configuration file above are as follows.

ItemDescription
ethernetsSection specifying the type of interface being configured (wired LAN)
enp1s0Name of the interface being configured
addressesIP address and subnet mask to assign (CIDR notation)
match.macaddressSpecification used to identify the interface by its MAC address
nameservers.addressesIP addresses of the DNS servers
nameservers.searchList of DNS search domains (domains automatically appended when resolving hostnames)
routesRouting information (to: default specifies the default route)
set-nameName assigned to the interface identified by match
versionFormat version of the Netplan configuration file

How to Configure a Static IPv4 Address

Edit the configuration file to change the IP address, DNS servers, and default gateway.

Command to Edit the Netplan Configuration File
sudo vi /etc/netplan/00-installer-config.yaml
Example of a Static IP Address Configuration
network:
  ethernets:
    enp1s0:
      addresses:
      - 10.100.41.200/22
      nameservers:
        addresses:
        - 10.1.0.1
        - 10.1.0.2
        search:
        - kazulog.info
      routes:
      - to: default
        via: 10.100.40.1
  version: 2

The example above changes the IP address to 10.100.41.200/22. match and set-name are not needed when you specify the interface name directly.

search specifies the DNS search domain. If you set kazulog.info, resolving a hostname alone — for example ping www — will automatically attempt to resolve it as www.kazulog.info.

How to Obtain an IPv4 Address via DHCP

If you want to obtain an IPv4 address automatically from a DHCP server instead of using a fixed IP, set dhcp4 to true.

Example DHCPv4 Configuration
network:
  ethernets:
    enp1s0:
      dhcp4: true
  version: 2

How to Configure an IPv6 Address

With Netplan, you can configure IPv6 addresses by adding IPv6-related items under the ethernets section. As with IPv4, you can either specify a static address directly or configure it automatically via DHCPv6 or Router Advertisement (RA).

ItemDescription
addressesIPv6 addresses can be listed in the same addresses item as IPv4 (specified with a prefix length)
routesThe IPv6 default route is specified with to: ::/0
nameservers.addressesIPv6 DNS server addresses can be listed in the same item as IPv4
dhcp6Set to true to obtain an address automatically via DHCPv6
accept-raSet to true to accept Router Advertisements (RA) and configure an address automatically (enabled by default)

How to Configure a Static IPv6 Address

Example of a Static IPv6 Address Configuration
network:
  ethernets:
    enp1s0:
      addresses:
      - 10.100.41.200/22
      - "2001:db8:41::200/64"
      nameservers:
        addresses:
        - 10.1.0.1
        - 10.1.0.2
        - "2001:db8:1::1"
        search:
        - kazulog.info
      routes:
      - to: default
        via: 10.100.40.1
      - to: "::/0"
        via: "2001:db8:41::1"
  version: 2

The example above configures the static IPv6 address 2001:db8:41::200/64 in addition to the IPv4 address (10.100.41.200/22). The IPv6 default route is specified with to: ::/0, with via set to the IPv6 gateway address.

In the example above, on-link: true is not required because the gateway address specified in via (2001:db8:41::1) falls within the prefix configured on the interface (2001:db8:41::/64), so it is recognized as a valid route without issue. However, when your ISP provides a link-local address (fe80::~) as the gateway, or in other cases where the via address falls outside the interface’s directly connected prefix, you need to add on-link: true to the route.

Example Configuration When the Gateway Is Outside the Prefix
routes:
- to: "::/0"
  via: "fe80::1"
  on-link: true

Automatic IPv6 Address Configuration via DHCPv6 / RA (Router Advertisement)

In environments where the upstream router distributes prefixes via RA (Router Advertisement), simply setting accept-ra to true will configure the IPv6 address automatically (this is often enabled by default, so specifying it explicitly may not be necessary).

Example Automatic IPv6 Configuration via RA
network:
  ethernets:
    enp1s0:
      dhcp4: true
      accept-ra: true
  version: 2

In environments that obtain an address from a DHCPv6 server, set dhcp6 to true.

Example DHCPv6 Configuration
network:
  ethernets:
    enp1s0:
      dhcp4: true
      dhcp6: true
  version: 2

Checking the Configuration File Syntax

Before applying the configuration, you can check the YAML file for syntax errors.

Command to Check the Netplan Configuration File Syntax
sudo netplan generate

If there is an indentation error or similar issue, an error message is displayed when the command is run.

How to Apply the Configuration

Apply the edited configuration file with netplan apply.

Command to Apply the Netplan Configuration
sudo netplan apply
If you are working remotely, an incorrect IP address change could disconnect your session and leave you unable to reconnect. It is recommended to verify the change beforehand with netplan try.
Command to Temporarily Apply the Netplan Configuration (for Verification)
sudo netplan try

When you run netplan try, the configuration automatically rolls back to the previous settings unless you confirm it with a key press within a set amount of time. Verify that the connection is not disconnected, then press Enter to confirm the configuration.

Example of Running the Netplan Temporary Apply (Verification) Command
ubuntu@ubuntu2604:~$ sudo netplan try
Do you want to keep these settings?


Press ENTER before the timeout to accept the new configuration


Changes will revert in 118 seconds
Configuration accepted.
ubuntu@ubuntu2604:~$

Checking After Applying the Configuration

After running netplan apply, confirm that the new IPv4 address is applied with the ip a command.

Example Output of the IPv4 Address Check Command
ubuntu@ubuntu2604:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:0e:cf:b9 brd ff:ff:ff:ff:ff:ff
    altname enx5254000ecfb9
    inet 10.100.41.200/22 brd 10.100.43.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe0e:cfb9/64 scope link proto kernel_ll
       valid_lft forever preferred_lft forever
ubuntu@ubuntu2604:~$

The above is an example confirming that the IP address has been changed to 10.100.41.200/22.

Check the IPv6 address with the ip -6 a command.

Example Output of the IPv6 Address Check Command
ubuntu@ubuntu2604:/etc/netplan$ ip -6 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 state UNKNOWN qlen 1000
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 2001:db8:41::200/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe0e:cfb9/64 scope link proto kernel_ll
       valid_lft forever preferred_lft forever
ubuntu@ubuntu2604:/etc/netplan$

Check the IPv6 default route with the ip -6 route command.

Example Output of the IPv6 Default Route Check Command
ubuntu@ubuntu2604:/etc/netplan$ ip -6 route
2001:db8:41::/64 dev enp1s0 proto kernel metric 256 pref medium
fe80::/64 dev enp1s0 proto kernel metric 256 pref medium
default via 2001:db8:41::1 dev enp1s0 proto static metric 1024 pref medium
ubuntu@ubuntu2604:/etc/netplan$

The above is an example confirming that the IPv6 address is set to 2001:db8:41::200/64, and the default route is via 2001:db8:41::1.

Related Articles

Reference Sites

Related Articles