5

I'm setting up a 4 x RPi Cluster with the following simple network topology:

enter image description here

All 4 RPi nodes have the latest Ubuntu Server LTS 20.04 OS. rpi1 is my primary/gateway node. I did the following on rpi1:

  • Assigned a static IP Address on eth0 of 10.0.0.1 using netplan
  • Disabled systemd-resolved and manually created /etc/resolv.conf with value nameserver 127.0.0.1
  • Setup dnsmasq with the following /etc/dnsmasq.conf:
# Basics:
interface=eth0
listen-address=127.0.0.1

DHCP Settings (MAC Addresses removed)

dhcp-range=10.0.0.1,10.0.0.128,12h

dhcp-host=XX:XX:XX:XX:XX:XX,rpi1,10.0.0.1 dhcp-host=XX:XX:XX:XX:XX:XX,rpi2,10.0.0.2 dhcp-host=XX:XX:XX:XX:XX:XX,rpi3,10.0.0.3 dhcp-host=XX:XX:XX:XX:XX:XX,rpi4,10.0.0.4

dhcp-option=option:router,10.0.0.1 dhcp-option=option:dns-server,10.0.0.1 dhcp-option=option:netmask,255.255.255.0

Forward to nameservers:

server=8.8.8.8 server=8.8.4.4

Misc

bind-interfaces domain-needed bogus-priv expand-hosts

  • Added identities to the /etc/hosts file:
10.0.0.1 rpi1
10.0.0.2 rpi2
10.0.0.3 rpi3
10.0.0.4 rpi4

This setup seems to work successfully as a DHCP server as it correctly assigns the desired IP Addresses to the eth0 devices of the remaining "minor" nodes (rpi2, rpi3, rpi4) based on their MAC address.

HOWEVER, I can't figure out how to use Netplan on the minor nodes to register the nameserver being broadcast by the dnsmasq-DHCP server running on rpi1. I've tried all sorts of settings in the /etc/netplan/50-cloud-init.yaml file on a minor node, but when I run sudo netplan apply, it ALWAYS creates a /etc/resolv.conf file with the following nameserver-location info:

nameserver 127.0.0.53
options edns0

If I manually edit /etc/resolv.conf to point to rpi1 (nameserver 10.0.0.1) then it works (e.g. I can then ping rpi3 from rpi2), but I would like to understand why running netplan apply doesn't set this automatically based on info coming from the dnsmasq broadcast. I've tried various settings in my /etc/netplan/50-cloud-init.yaml, but nothing seems to affect the resultant /etc/resolv.conf file.

Here's where I got to last on the /etc/netplan/50-cloud-init.yaml file on rpi2 before giving up (note: I also enable direct Wi-Fi access here for initial setup/debugging):

network:
    version: 2    
    ethernets:
        eth0:
            dhcp4: true
            optional: true
            dhcp4-overrides:
                use-dns: false
            nameservers:
                addresses: [10.0.0.1]
    wifis:
        wlan0:
            optional: true
            access-points:
                "my-wifi-signal":
                    password: "mypassword"
            dhcp4: no
            addresses: [192.168.0.52/24]
            gateway4: 192.168.0.1
            nameservers:
                addresses: [8.8.8.8,8.8.4.4]

It's also odd to me that when I run systemd-resolve --status after applying Netplan with this config, it seems to indicate that it DOES now recognize the location of the desired DNS nameserver on rpi1:

$ systemd-resolve --status
...

Link 2 (eth0) Current Scopes: DNS DefaultRoute setting: yes LLMNR setting: yes MulticastDNS setting: no DNSOverTLS setting: no DNSSEC setting: no DNSSEC supported: no Current DNS Server: 10.0.0.1 DNS Servers: 10.0.0.1

But, as I said, when I try to e.g. ping rpi4 from rpi3 it doesn't work (I get the message "ping: rpi4: Temporary failure in name resolution").

In summary:

How can I make it so that running sudo netplan apply will consult the DHCP server for a DNS Nameserver and use that to set the content of /etc/resolv.conf?

Dave M
  • 4,494
Magnus
  • 205

2 Answers2

10

The same issue I faced too. Netplan uses systemd-resolvd for name resolution and most of time I found the /etc/resolve.conf file is a symlink to /run/systemd/resolve/stub-resolv.conf and which uses 127.0.0.53 for loopback interfaces and the nameservers defined in /etc/netplan/00-cloud-init.yaml file are written in /run/systemd/resolve/resolv.conf.

Following steps worked for me.

$ sudo unlink /etc/resolv.conf
$ sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

and restart systemd-resolved service

$ sudo systemctl restart systemd-resolved.service 

Hope it will help you too.

Gerald Schneider
  • 26,582
  • 8
  • 65
  • 97
2

Do you have the service resolvconf installed ?

if not run

sudo apt install resolvconf  
sudo netplan apply  
sudo service resolvconf restart  
sudo service resolvconf status  

I had a workstation with fix ip where DNS resolution was going ON and OFF this solved my problem.

Baldeante
  • 21
  • 3