No DNS resolution in chroot + qemu

Hi, I’m trying to chroot into a Raspbian image, but there’s not domain name resolution inside the chroot.

  • I’m 100% sure to have the correct bind mounts
  • the correct /etc/resolv.conf (i tried several)
  • ping an IP works (ipv4, ipv6)
  • I tried adding a domain in /etc/hosts, and resolution works for this domain only.
  • I tried using systemd-nspawn instead of chroot as it’s supposed to be more solid.

Still, I get :

root@latitude5400:~# ping google.com
ping: google.com: Temporary failure in name resolution

Do you have any idea ?
Thanks !

Hi and welcome to the forum :+1:

Check:

  • systemctl status systemd-resolved
  • resolvectl status

Thanks :smiley:

Here are the status :

~ ❯❯❯ resolvectl status
Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found.
~ ❯❯❯ systemctl status systemd-resolved
● systemd-resolved.service - Network Name Resolution
     Loaded: loaded (/usr/lib/systemd/system/systemd-resolved.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:systemd-resolved.service(8)
             man:org.freedesktop.resolve1(5)
             https://www.freedesktop.org/wiki/Software/systemd/writing-network-configuration-managers
             https://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients

Looks like none are used. That’s weird, I never customized the DNS config and I installed Manjaro less than 2 months ago.

Yea commands like ping need that service enabled (and started)…
But the service needs manual intervention for it’s correct operation maybe that’s why they didn’t enable it by default.
See: systemd-resolved.service

In short you just need to symbolic link /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf before starting it :wink:

Just to be sure : ping and such WORK in the host. They just don’t work in the chroot/systemd-nspawn “guest”.
I tried symlinking the resolv.conf and starting systemd-resolved, that did not help :frowning:

I have the exact same issue as @Salamandar: network and DNS work on host, only network works in chroot (DNS do not work).

I think the issue is that Manjaro uses NetworkManager and not resolvctl to handle DNS by default, whereas Raspian/Ubuntu uses resolvctl. I assume the incompatibility is causing the issue, but I haven’t found a solution yet.

Hi,

I had the same issue and found a solution.

To have dns resolving to work inside the chroot you need to mount /run into your chroot.
And start the systemd-resolved.service service.

On your host system mount the required filesystems

# mount -t proc none /mnt/chroot/proc
# mount -t sysfs none /mnt/chroot/sys
# mount -o bind /dev /mnt/chroot/dev
# mount -o bind /dev/pts /mnt/chroot/dev/pts
# mount -o bind /run /mnt/chroot/run/

Start the systemd-resolved.service

# systemctl start systemd-resolved.service

Go into the chroot

LANG=C chroot /mnt/chroot/

Test it

# LANG=C chroot /mnt/chroot/
[root@vicky /]# uname -a
Linux vicky 5.12.19-hardened1-1-hardened #1 SMP PREEMPT Tue, 20 Jul 2021 17:48:41 +0000 aarch64 GNU/Linux
[root@vicky /]# ping manjaro.org
PING manjaro.org (116.203.91.91) 56(84) bytes of data.
64 bytes from mail.manjaro.org (116.203.91.91): icmp_seq=1 ttl=53 time=30.2 ms

Hope this helps…


staf

try running systemd-nspawn with --resolv-conf=copy-host.
That works in our ARM tools.