We have to configure name resolution with systemd. I will use this question to show how to use systemd-resolved for this. To match all your conditions (use-case 1 to 3) I will make robotBase the main access point (5) of your local network so robotNo7 and other devices can connect to it and communicate among each other and get access to the internet. To be a bit more generic I will name the uplink to the internet modem/router eth0. It shouldn't make a difference renaming it to usb0 if using usb tethering.
Tested with
Raspbian Buster Lite 2019-09-26 on a Raspberry Pi 4B updated at 2020-01-18.
Updates done with sudo apt update && sudo apt full-upgrade && sudo reboot.
systemd-resolved provides name services by Domain Name System (DNS) (including DNSSEC and DNS over TLS), Multicast DNS (mDNS) and Link-Local Multicast Name Resolution (LLMNR).(1)
systemd-resolved provides network name resolution to local applications via a D-Bus interface, the resolve NSS service (libnss-resolve
), and a local DNS stub listener on 127.0.0.53 (1), (2). For all three software interfaces there are also traditional services installed which may conflict with systemd-resolved. On my tests I have seen problems in the order of name resolution: long response time depending on the amount of DNS server to use, queries for the .local
domain going to DNS server, no responses to local host names if the internet connection was down and so on. So I will deinstall not needed services instead of only disable them. This should ensure that entries in common used static config files like /etc/nsswitch.conf
will also cleaned up.
♦ General setup
Enable systemd-networkd
For detailed information look at (6). Here only in short. Execute these commands:
# deinstall classic networking
rpi ~$ sudo -Es
rpi ~# apt --autoremove purge ifupdown
rpi ~# rm -r /etc/network
rpi ~# apt --autoremove purge dhcpcd5
rpi ~# apt --autoremove purge isc-dhcp-client isc-dhcp-common
rpi ~# rm -r /etc/dhcp
# enable systemd-networkd and systemd-resolved
rpi ~# systemctl enable systemd-networkd.service systemd-resolved.service
Check D-Bus software interface
I haven't found any conflicting issues. The D-Bus should be installed by default and running. Check with:
rpi:~ # systemctl status dbus.service
Configure NSS software interface
There is the avahi service together with the mdns service definitely conflicting, so we have to deinstall them. This will also clean up /etc/nsswitch.conf
:
rpi ~# apt --autoremove purge avahi-daemon
Now install the systemd-resolved software interface:
rpi ~# apt install libnss-resolve
Configure DNS stub listener interface
Here we have to symlink /etc/resolv.conf
to the stub listener:
rpi ~# ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
Finished General setup. Go back.
♦ Setup robotBase (access point)
Do ♦ General Setup to configure systemd-resolved name resolution. Then
Configure wpa_supplicant as access point
To configure wpa_supplicant as access point create this file with your settings for country=
, ssid=
, psk=
and maybe frequency=
. You can just copy and paste this in one block to your command line beginning with cat
and including both EOF (delimiter EOF will not get part of the file):
rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="RPiNet"
mode=2
frequency=2437
key_mgmt=WPA-PSK
proto=RSN WPA
psk="password"
}
EOF
rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# systemctl disable wpa_supplicant.service
rpi ~# systemctl enable wpa_supplicant@wlan0.service
Setup network interfaces
Create these two files:
rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
DHCP=yes
IPForward=yes
EOF
rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.4.1/24
MulticastDNS=yes
IPMasquerade=yes
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 1.1.1.1
EOF
The address 192.168.4.1/24 defines the subnet 192.168.4.0/24 for the WiFi network. Have attention that it is different from the subnet used by the internet modem/router given to eth0 by DHCP.
Reboot.
Check the status with:
rpi ~$ resolvectl status
Global
LLMNR setting: yes
MulticastDNS setting: yes
DNSOverTLS setting: no
DNSSEC setting: allow-downgrade
DNSSEC supported: yes
--- snip ---
Link 3 (wlan0)
Current Scopes: LLMNR/IPv4 LLMNR/IPv6 mDNS/IPv4 mDNS/IPv6
DefaultRoute setting: no
LLMNR setting: yes
MulticastDNS setting: yes
DNSOverTLS setting: no
DNSSEC setting: allow-downgrade
DNSSEC supported: yes
Link 2 (eth0)
Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
DefaultRoute setting: yes
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: allow-downgrade
DNSSEC supported: yes
Current DNS Server: 84.200.69.80
DNS Servers: 84.200.69.80
1.1.1.1
♦ Setup robotNo7 (station)
Do ♦ General Setup to configure systemd-resolved name resolution. Then
Configure WiFi client connection
Create these two files:
rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="RPiNet"
key_mgmt=WPA-PSK
proto=RSN WPA
psk="password"
}
EOF
rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# systemctl disable wpa_supplicant.service
rpi ~# systemctl enable wpa_supplicant@wlan0.service
rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
DHCP=yes
MulticastDNS=yes
EOF
Reboot.
♦ Check name services
Now from a network device, here on robotBase, you can check the three name services DNS, MulticastDNS and LLMNR with resolvectl
as follows:
rpi ~$ resolvectl query google.com
google.com: 172.217.169.14 -- link: eth0
-- Information acquired via protocol DNS in 79.9ms.
-- Data is authenticated: no
rpi ~$ resolvectl query robotNo7.local
robotNo7.local: fe80::217:9aff:feb9:6ea9%3 -- link: wlan0
-- Information acquired via protocol mDNS/IPv6 in 124.5ms.
-- Data is authenticated: no
rpi ~$ resolvectl -4 query robotNo7.local
robotNo7.local: 192.168.4.253 -- link: wlan0
-- Information acquired via protocol mDNS/IPv4 in 205.1ms.
-- Data is authenticated: no
rpi ~$ resolvectl query robotNo7
robotNo7: 192.168.4.253 -- link: wlan0
-- Information acquired via protocol LLMNR/IPv4 in 123.4ms.
-- Data is authenticated: no
rpi ~$ ping -c3 robotNo7
PING robotNo7 (192.168.4.253) 56(84) bytes of data.
64 bytes from robotNo7.local (192.168.4.253): icmp_seq=1 ttl=64 time=5.47 ms
64 bytes from robotNo7.local (192.168.4.253): icmp_seq=2 ttl=64 time=1.40 ms
64 bytes from robotNo7.local (192.168.4.253): icmp_seq=3 ttl=64 time=2.51 ms
rpi ~$ ssh pi@robotNo7.local hostname
pi@robotNo7.local's password:
robotNo7
rpi ~$
References:
(1) - archlinux - systemd-resolved
(2) - freedesktop - systemd-resolved — Network Name Resolution manager
(3) - freedesktop - What is D-Bus?
(4) - archlinux - Domain name resolution
(5) - Setting up a Raspberry Pi as an access point - the easy way
(6) - Howto migrate from networking to systemd-networkd with dynamic failover