1

Last time when I chrooted from Live USB to my old broken system, I couldn't connect to Internet. In this tutorial, I read I should add OpenDNS to my /etc/resolv.conf if I use DHCP.

How does DHCP (or chroot) influence my DNS?

Isn't DHCP only a way for my router to give me an IP? Why can I connect from Live USB to Internet normally, while in chroot I have to add new DNS?

4

Isn't DHCP only the way my router gives me IP?

No, it's also the way your router gives you extra information – gateway IP, DNS server IP, default domain name, time server IP, et cetera.

Why I can connect from Live USB to Internet normally, while in chroot I have to add new DNS?

Linux stores the DNS server address in a file. Since chroot alters how programs see file paths, it means they'll find a different file at the /etc/resolv.conf path, which means they'll possibly find a different address stored there.

(Your DHCP client doesn't know anything about your chroots, and only updates the main /etc/resolv.conf file – it cannot search and update all possible files.)


A common workaround is to link (bind) the "inside" path so that it refers to the same "outside" file. For example, you can do this before chrooting to /mnt:

mount --bind /etc/resolv.conf /mnt/etc/resolv.conf

(Of course, later you'll have to unmount this before the system will let you unmount /mnt.)

  • 1
    If your resolv.conf is a symlink (or you don't want it to muck with the original), use cp -L /etc/resolv.conf /path/to/etc. – ErikF Jun 9 '18 at 2:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.