How to resolve hostnames in chroot?

Solution 1:

On newer Ubuntu systems, name resolution is handled by the resolvconf service, and /etc/resolv.conf is a symbolic link to /run/resolvconf/resolv.conf. You can either add a bind mount to the /run filesystem along with your other bind mounts before executing the chroot command

sudo mount -o bind /run /mnt/run

so that the chroot system picks up the host system's DNS settings or, once you're in the chrooted system, temporarily create a static /etc/resolv.conf with nameserver(s) of your choice e.g.

echo 'nameserver 8.8.4.4' | sudo tee -a /etc/resolv.conf