Container set hostname per interface?

nathanc1

New Member
Sep 9, 2020
8
0
1
48
Hello all. I'm not sure if I am confused by general dhcp behavior or this a proxmox/container specific behavior, but I thought I'd ask here as I seem to be at an impasse.

Context of the problem:

I wish to use a container (debian buster) to simulate a system that is connected to multiple physical networks, let us say 3, using 3 interfaces and vlan tags instead of physical networks. I used the gui to create the container, adding each interface/vlan manually.

My dhcp server is setup to serve a different address range on each vlan, all within the subnet, i.e. vlanid1 gets 192.168.2.xxx, vlanid2 gets 192.168.3.xxx, ...

If I start the container, indeed, I can see dhcp leases on every range for the container, each having the same host name. This obviously causes problems trying to specify connections from other systems using hostname/dns.

So the problem is: How do I assign a different hostname per interface? I do not see an option on the gui to specify this, nor in the pct tool.

Possible answer 1:
Edit /etc/network/interfaces and add a hostname option to the dhcp method.
Observation:
It seems on reboot that the container's interfaces file get overwritten back to original without the hostname option.

Possible answer 2:
Edit /etc/network/interfaces to include a source line pointing to interfaces.d, add the hostname options there.
Observation:
The source line seems to survive reboot, but didn't seem to change anything. What I put in each stanza file is:

auto <interface name>
iface <interface name> inet dhcp
hostname <desired hostname>

Possibly this is not the correct stanza?

Possible answer 3:
Edit /etc/dhcp/dhclient.conf to specify a hostname for each interface.
Observation:
This partially worked, as I can see the different hostnames on each subnet, but it seems to get called once for every interface, and I wind up with duplicate leases, in this case 3x.

Here are the directives I placed in dhclient.conf (and I commented out the general send host-name = gethostname()):

interface "public" {
send host-name = gethostname();
}

interface "data" {
send host-name = concat(gethostname(), "-data");
}

interface "control" {
send host-name = concat(gethostname(), "-control");
}

Looking through the dhclient manpages I can't seem to find a way to 'skip' a directive if the interface is already assigned, but perhaps I just haven't deciphered it yet.


If anyone has any ideas thanks in advance. Perhaps I have gone down the wrong path or it is beyond the scope of containers and I will have to simulate the networks with some other method.
 
Have you found a solution to this problem ?

Your proposed method of having multiple interface segments in /etc/dhcp/dhclient.conf wouldn't work. Because for each interface in /etc/network/interfaces, dhclient is called. It will then execute DHCP request on *every* interface listed in the dhclient.conf file. So if you have 2 interfaces in /etc/network/interfaces, you will obtain a total of 2x2=4 IP addresses, 2 per each MAC address.
 
You could try it with the method as in answer 1 and tell Proxmox to not touch the network interface file in the container as described in this thread.