Wednesday, October 19, 2022

Permanently set DNS in headless Debian or LXC/LXD container via CLI

 If you're like me and you've been through all those howto's that have you installing and using nmcli/resolvconf/network-manager and still don't have a permanent DNS, well you've come to the right place.

Again, I tried all that and then some. I even tried editing dhclient.conf and that didn't do anything either.

Forget installing whatever program that you don't need. 

All you need to do are three things.


1. Check if /etc/resolv.conf is a symlink to /run/systemd/resolve/stub-resolv.conf

    If it IS a symlink then ...

2. Delete the /etc/resolv.conf symlink and add a new /etc/resolv.conf

    rm /etc/resolv.conf; vi /etc/resolv.conf

    In the new /etc/resolv.conf add your nameserver

        nameserver 192.168.5.20

3. Restart your network or reboot.


The symlink is managed so anytime you edit the symlinked resolv.conf, the manager changes it back. But if you delete the symlink and create it again, the nameserver you add will be persistent.

No comments:

Post a Comment