how to setup a container with IPV4 DHCP and custom DNS???

wolframio

Member
Dec 15, 2021
79
13
13
42
Hi,
I'm unable to configure a container that has network information via DHCP, but uses custom DNS...
I already tried doing it from the web interface (where you enter custom DNS, but it doesn't use it).

Any suggestions?

Thanks!
 
I have seen you deleted your last comment. I also use from time to time claude as my Budy AI.
But as always it needs a good description ;-) and also never ever trust it in the first place.

when you execute certain commands, ask yourself what it does.

You have heard about hook scripts ?
1. Connect to Proxmox host:
Bash:
ssh root@your-proxmox-host
# Or use the Proxmox console from GUI

2. Navigate to snippets directory:
Bash:
cd /var/lib/vz/snippets/
3. Create the hook script:
Bash:
nano lxc-hookscript.pl
4. Add the script content:
Perl:
#!/usr/bin/perl
use strict;
use warnings;

print "GUEST HOOK: " . join(' ', @ARGV). "\n";

my $vmid = shift;
my $phase = shift;

print "STARTING PHASE '$phase' for CT $vmid\n";

if ($phase eq 'post-start') {
    print "Configuring DNS for container $vmid\n";
  
    # Configure DNS servers
    system("pct exec $vmid -- bash -c 'echo \"nameserver 1.1.1.1\" > /etc/resolv.conf'");
    system("pct exec $vmid -- bash -c 'echo \"nameserver 8.8.8.8\" >> /etc/resolv.conf'");
    system("pct exec $vmid -- bash -c 'echo \"search local\" >> /etc/resolv.conf'");
  
    print "DNS configuration completed for container $vmid\n";
}

print "END PHASE '$phase' for CT $vmid\n";

5. Make it executable:
Bash:
chmod +x lxc-hookscript.pl

Test the Hook:
1. Apply hook to container:
Bash:
pct set 100 --hookscript local:snippets/lxc-hookscript.pl
2. Test by restarting container:
Bash:
pct stop 100
pct start 100
3. Check if DNS was configured:
Bash:
pct exec 100 -- cat /etc/resolv.conf
4. View hook execution logs:
Bash:
journalctl -u pve-container@100.service -f

I just added other NS on my side, the ct 108 is an dhcp conatainer ;-)

1757239536951.png

1757239562570.png

1757239699137.png
 
Last edited:
I have seen you deleted your last comment. I also use from time to time claude as my Budy AI.
But as always it needs a good description ;-) and also never ever trust it in the first place.

when you execute certain commands, ask yourself what it does.

You have heard about hook scripts ?
1. Connect to Proxmox host:
Bash:
ssh root@your-proxmox-host
# Or use the Proxmox console from GUI

2. Navigate to snippets directory:
Bash:
cd /var/lib/vz/snippets/
3. Create the hook script:
Bash:
nano lxc-hookscript.pl
4. Add the script content:
Perl:
#!/usr/bin/perl
use strict;
use warnings;

print "GUEST HOOK: " . join(' ', @ARGV). "\n";

my $vmid = shift;
my $phase = shift;

print "STARTING PHASE '$phase' for CT $vmid\n";

if ($phase eq 'post-start') {
    print "Configuring DNS for container $vmid\n";
 
    # Configure DNS servers
    system("pct exec $vmid -- bash -c 'echo \"nameserver 1.1.1.1\" > /etc/resolv.conf'");
    system("pct exec $vmid -- bash -c 'echo \"nameserver 8.8.8.8\" >> /etc/resolv.conf'");
    system("pct exec $vmid -- bash -c 'echo \"search local\" >> /etc/resolv.conf'");
 
    print "DNS configuration completed for container $vmid\n";
}

print "END PHASE '$phase' for CT $vmid\n";

5. Make it executable:
Bash:
chmod +x lxc-hookscript.pl

Test the Hook:
1. Apply hook to container:
Bash:
pct set 100 --hookscript local:snippets/lxc-hookscript.pl
2. Test by restarting container:
Bash:
pct stop 100
pct start 100
3. Check if DNS was configured:
Bash:
pct exec 100 -- cat /etc/resolv.conf
4. View hook execution logs:
Bash:
journalctl -u pve-container@100.service -f

I just added other NS on my side, the ct 108 is an dhcp conatainer ;-)

View attachment 90369

View attachment 90370

View attachment 90371
Hi, thank for your reply with a workarround, i will test it and report back.

I've now run a CT of Ubuntu 24.04 and everything works as it should from the start (no modifications or additions).

I think it could be a PVE9 issue with the Debian 12 CT, or the Debian 12 CT itself.