No DNS resolution in chroot + qemu

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

1 Like