Setting a static IP for your headless server is a must. Here are the simple steps to accomplishing this.
navigate to the interfaces file /etc/netplan
sudo nano /etc/netplan
Here is an example of what mine looks like.
# This is the network config written by 'subiquity'
network:
ethernets:
ens18:
addresses: [192.168.1.204/24]
routes:
- to: default
via: 192.168.1.99
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
version: 2
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules
Save and close The last two lines pre-up and post-down is for iptables. remove those lines if you are not using the firewall.
To apply the changes:
sudo netplan apply
If you want to verify that you are using the correct DNS:
Use this command after you add/change your dns to restart systemd-resolved service.
sudo systemctl restart systemd-resolved
Use this command to verify the DNS routing.
sudo resolvectl status