Issue accessing container using hostname

russellhq

New Member
Dec 23, 2022
4
0
1
I'm trying to access my containers using their hostnames but I can't get it to work, I can only access them using their IP address. I've checked DNS and DHCP settings but don't see anything out of place: see below.

Also, I noticed in pfSense, which runs my DHCP server, the containers are listed in the DHCP leases but only show an IP address rather than a hostname like the other hosts in the DHCP leases list.

I've checked the settings in proxmox and I think I have them all set correctly but I still have this issue.

The container hostname
Bash:
root@docker ~# hostname -f
docker.local.lan

Code:
  GNU nano 5.4         /etc/hosts                   
127.0.0.1 localhost
127.0.1.1 core

#Required for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
# --- BEGIN PVE ---
127.0.1.1 docker.local.lan docker
# --- END PVE ---

/etc/resolv.conf
Code:
# --- BEGIN PVE ---
search local.lan
nameserver 192.168.1.2
# --- END PVE ---

In pfSense, I have the DNS resolver set with both the following options on which should pick up the hostnames of the containers when they request an IP:
Register DHCP static mappings in the DNS Resolver
Register DHCP leases in the DNS Resolver

The DHCP server on pfSense also has the "Domain Name" option set to local.lan

I can access proxmox using its hostname. But I think that's only because I've mapped it to a static IP in pfSense

The proxmox ve node hosts.
Code:
127.0.0.1 localhost.localdomain localhost
192.168.1.219 proxmoxve.local.lan proxmoxve

# The following lines are desirable for IPv6 capable hosts

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Any help getting this sorted would really be appreciated.
 
I normally set my CT/VM's up with static addresses in pfsense DHCP server settings, that way I know where they will land. You need to add the mac address of the CT/VM and pair it with an IP address, fill out host name and ensure you tick ARP Table Static Entry
 
  • Like
Reactions: russellhq
Thanks, I did that with my proxmox node, but wanted to avoid having to do that for the containers. Thanks for the suggestion though.
 
I'm getting a bit closer to getting this working,
I added 127.0.1.1 to the DNS servers in the proxmox node AND i turned off the proxmox node firewall. This allowed me to connect to the container using its hostname (but not its FQDN). Either of these changes on their own didn't work.

I turned the firewall back on but set up 2 rules to allow DHCP traffic, following the post below. I was still able to connect to the container using the hostname (but still not the FQDN).
https://forum.proxmox.com/threads/firewall-dhcp-enabled.41143/
 
OK, I don't need to set up the firewall rules in the proxmode node. I can delete those rules and just change the firewall option in the container. Under the containers firewall options, changing the DHCP setting to No allows the container to be accessed using its hostname. Still can't access it with FQDN yet.
 
As this thread was my Google search top result, here is what I learned:

For the Container/VM hostname to be resolved, you have two options:
  1. configure the CT/VM to use DHCP instead of static. This way, the DHCP server will return the IP when queried via DNS
  2. If you want to use static IP, you need to add a manual DHCP reservation and give a hostname. The downside is that if you change the CT/VM hostname, it will not reflect in the DHCP server until you manually update it there.
I don't agree this is ideal, but I guess it makes sense in a way because when you use DHCP, you don't need to worry about anything else as the CT/VM will advertise its name and be available.
The problem is that sometimes you want static IPs, (for a DNS server for example), that you might also want to be able to access via lan name. Or maybe you have a NFS client that needs a specific IP to access a more restricted NFS share.

On my Asus RT-AX58U which acts as DHCP server (and LAN-only DNS), I could not get IP address reservation in DHCP without hardcoding the hostname while unreserved DHCP Ubuntu VMs, are resolvable by name.