[SOLVED] Configure gateway and DNS for LXC

win9

New Member
May 6, 2024
14
1
3
Hi,

I'm setting up a Debian 12 lxc. It seems possible to configure both the gateway and DNS through UI. The setting of ip and gateway works, which can be checked in file /etc/network/interfaces. But the dns configs aren't reflected in /etc/resolv.conf. No matter what I set through UI (for example 8.8.8.8 for both DNS domain and DNS server), the content is nameserver fe80::1%eth0.
Anyone can help? Correct my misunderstanding if any.

Thanks!
 
I also observed this. Editing the network config of the LXC via webUI isn't always updating the config files of the Debian 12 LXC. Not even after stopping and starting the LXC. I then had to edit the LXCs /etc/network/interfaces, /etc/resolv.conf and /etc/hosts to match the changes done in the webUI.

This caused lots of headaches here when later changing IPs and wondering why services won't be availalble.
 
Last edited:
I just came across this too. I managed to get DNS to stick inside the LXC, when editing via pve UI. But first I had to setup static IP for all LXC network adapters (I have 2 on each). This I also did in gui.

You mention doing this too OP, so I can only say, did you do it for all lxc network interfaces?
 
You mention doing this too OP, so I can only say, did you do it for all lxc network interfaces?
I have only one network interface for my LXC, so yes.

I managed to get DNS to stick inside the LXC, when editing via pve UI.
Do you mean you managed to change internal DNS settings from GUI? From which file(s) in your LXC can you tell the settings become effective?
 
Last edited:
Not totally sure if it's the cause, but after I upgraded everything (e.g. pve-container/stable,now 5.1.10), it seems working now.
Settings on gateway and DNS are reflected in /etc/network/interfaces and /etc/resolv.conf respectively.
 
I'm glad it worked for you. It is not deterministic for me, but is now since I did below. I did update pve-container package to stable,now 5.1.10 - but the problem persists unless I setup static IP for the LXC in the PVE GUI. I am only having this issue on my Debian 12 LXCs. Debian 11 LXC , as well as Ubuntu LXC take PVEs DNS settings without issue.

So, I looked further into it - I suspect, during boot, PVE is updating /etc/resolv.conf, but then the changes get overridden by the dhclient daemon.

Following instruction in the link - the dhclient can be modified to prevent updating /etc/resolv.conf - which means the PVE settings remain.

From https://wiki.debian.org/resolv.conf

Stop dhclient from modifying /etc/resolv.conf

Another approach makes use of dhclient-script's hook scripts. According to dhclient-script(8):

  • When it starts, the client script first defines a shell function, make_resolv_conf , which is later used to create the /etc/resolv.conf file. To override the default behaviour, redefine this function in the enter hook script.
Therefore, we can stop dhclient from overwriting resolv.conf by doing the following:

echo 'make_resolv_conf() { :; }' > /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone
chmod 755 /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone
 
I did some further investigating as to reason why Debian 12 LXCs specifically had this issue (and not Deb 11 or Ubuntu LXCs) - and it turns out for Deb 12 bookworm systemd-resolved package is no longer included by default.

After seeing this post, I installed resolvconf inside each affected container (apt install resolvconf) - and now my ~8 Deb 12 LXCs DNS settings propagate to /etc/resolv.conf as per PVE gui. As this works, I reverted above post with rm /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone
 
  • Like
Reactions: McMarkis
I did some further investigating as to reason why Debian 12 LXCs specifically had this issue (and not Deb 11 or Ubuntu LXCs) - and it turns out for Deb 12 bookworm systemd-resolved package is no longer included by default.

After seeing this post, I installed resolvconf inside each affected container (apt install resolvconf) - and now my ~8 Deb 12 LXCs DNS settings propagate to /etc/resolv.conf as per PVE gui. As this works, I reverted above post with rm /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone
Thanks @esvee, this took a little while to figure out. For anyone using the "Proxmox VE Helper Scripts", installing resolvconf, fixes this problem.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!