DHCP and Hostnames

In a simple model of a computer in a network, the computer boots, connects, and gets an IP address. But the actual component that has the IP address is the network interface card, and a computer can have more than one.

A cloud computer with default configuration has one IP address and one active network interface for it. Cloud computers can be configured with multiple active network interfaces too -- for example when hosting firewall servers that will apply the same firewall to network traffic going to computers in multiple networks.

Home computers usually have multiple network interfaces available:

  • wifi connection

  • ethernet port

  • technologies like Thunderbolt that connect USB to a network cable

Multiple IP addresses for a home computer

If a home computer is connected to wifi and ethernet, both of those network interaces have their own IP address on the home network.

Testing here, DNS for a home network only returns one of them for that computer's hostname. That leads to some interesting questions

  • Which IP address (which NIC) will DNS return for that host?

  • Is there a hostname in DNS for the other NIC?

DHCP - Dynamic Host Configuration Protocol

DHCP is the protocol that facilitates a computer's entry into its network. The relevant components for this summary are:

  • The network gateway gives the NIC an IP address

  • The computer announces a hostname for the NIC

After that exchange, there is a hostname and an IP address for the NIC, and DNS for your home network will return them when you look them up.

Ubuntu - dhclient.conf

An Ubuntu PC will choose one NIC to be the primary and announce its hostname on that NIC. Any others will get a derivative of the hostname.

The /etc/dhcp/dhclient.conf file can declare a configuration that puts this under your control. Stackexchange link with good detail:

https://unix.stackexchange.com/questions/595307/specify-unique-dhcp-hostnames-for-multiple-network-interfaces

Controlling hostnames for each NIC with dhcp.conf

1. Apollo was set up by wifi until we could clear a place to cable it

  • eno1 is the ethernet NIC. No cable is plugged in and it has no IP address
  • lo is the loopback interace for connections to localhost. It is always 127.0.0.1
  • wlp3s0 is the WiFi NIC. It has been assigned 192.168.1.246 on the home network

2. Plug in an ethernet cable and two NICs are active

  • eno1 has address 192.168.1.216
  • wlp3s0 has kept address 192.168.1.246

2a. The eno1 NIC is broadcasting hostname apollo-75

Network scan screenshots from the excellent LanScan

3. Attempt to reassign the "apollo" hostname by deactivating the WiFi network interface

  • eno1 has kept 192.168.1.216
  • wlp3s0 has no IP address

A network scan shows eno1 is still apollo-75 in DNS

4. Cycling the eno1 ethernet connection only leads to DNS incrementing its hostname every time it reactivates. We're on "apollo-82" in this screenshot

We have also configured a DNS name for the wlp3s0 interface - "apollo-wifi". More details next ...

5. Success! Editing the interface entries in /etc/dhcp/dhclient.conf directs them to broadcast specific names to the DHCP service.

This was the only way to reassign the "apollo" name to the eno1 network interface.

Very important: commenting out the send host-name= gethostname(); directive, which broadcast the computer's hostname on its choice of primary interface.

Commands to reset DHCP after editing dhclient.conf:

# reset all network interfaces,
# -v for verbose, -r for "reset"
sudo dhclient -v -r
# reset a specific network interface
sudo dhclient -v -r eno1