Ubuntu networking DNS

Posted on Sep 3, 2023
tl;dr: Cheat sheet DNS on Ubuntu

Objective

Simple cheat sheet or quick notes follwing some recent Ubuntu deployment. The resolved part changes a bit the old habits.

Prerequisites

A working Ubuntu server or instance with SSH connectivity and internet access, that’s it.

Packages

No specific package required here.

Actions/Config

Resolved

Create specific folder sudo mkdir /etc/systemd/resolved.conf.d/

Fill in the file dns_servers.conf

sudo vim /etc/systemd/resolved.conf.d/dns_servers.conf

With your servers of choice

[Resolve]
DNS=8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844
Domains=~.

Here we need to restart the service sudo systemctl restart systemd-resolved

Netplan

Let’s keep evolving here, switching to netplan configuration as fixed ip.

Edit sudo vim /etc/netplan/00-installer-config.yaml

Here is the default DHCP config

# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      dhcp4: true
  version: 2

Switch the content to something like this

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
 version: 2
 renderer: networkd
 ethernets:
   ens33:
     dhcp4: no
     dhcp6: no
     addresses: [192.168.0.100/24]
     routes:
      - to: default
        via: 192.168.0.1
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]

After that, need to check and apply

sudo netplan generate 
sudo netplan apply

The official Netplan

Some documentation Netplan

Resolvctl man page

What’s next

We’ll see.