John Todd
ErrthquakeHalo
← R&D
December 28, 2022

DHCP and Hostnames

DHCP (Dynamic Host Configuration Protocol) assigns IP addresses and hostnames to network interface cards (NICs) in home and cloud computing environments.

How DHCP Works

Multiple network interfaces on a single computer each receive their own IP address. Home computers typically have wifi, ethernet, and other connection options available simultaneously. DHCP enables network entry by having the network gateway assign an IP address to each NIC while the computer announces a hostname for that interface.

Ubuntu systems designate one NIC as primary for hostname announcement. Managing unique hostnames per interface is controlled via /etc/dhcp/dhclient.conf.

The Problem: Apollo's Two NICs

Apollo started with wifi only, then gained an ethernet connection:

  • Beforewlp3s0: 192.168.1.246

LanScan — before adding ethernet

  • After adding etherneteno1: 192.168.1.216; secondary hostnames appeared as apollo-75 and apollo-82

LanScan — after adding ethernet

The goal was to keep the primary hostname apollo on ethernet and name the wifi interface apollo-wifi.

The Solution

Edit /etc/dhcp/dhclient.conf to assign specific hostnames to specific NICs.

Comment out the default line:

# send host-name = gethostname();

Then add interface-specific blocks:

interface "eno1" {
  send host-name "apollo";
}

interface "wlp3s0" {
  send host-name "apollo-wifi";
}

dhclient.conf configuration

Reset DHCP leases to apply:

sudo dhclient -v -r
sudo dhclient -v -r eno1

Apollo with ethernet — dhclient eno1

Apollo without wifi — clean state

Apollo — dhclient eno1 result

Apollo — dhclient both NICs

After applying, LanScan shows apollo on ethernet and apollo-wifi on the wireless interface — exactly as intended.