Network Interfaces File Cheatsheet
This is just a cheatsheet for the /etc/network/interfaces file that I can quickly refer to when I forget things like how to specify the mac address against an interface etc.
Related Posts
Cheats
Basic DHCP Example
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug ens18
iface ens18 inet dhcp
Basic Static IP Example
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
allow-hotplug ens19
iface ens19 inet static
address 192.168.0.2/24
gateway 192.168.0.1
dns-nameserver 8.8.8.8
dns-nameserver 8.8.4.4
dns-search programster.org
kube1
in tools like ping, then it would use kube1.programster.org
since search is set to programster.org
.
Matching MAC Address
When you have two network interfaces attached to a server, it is usually important to specify the mac address against the name of the interface. That way you can be sure you are applying the settings to the physical hardware you intend. E.g. one of the network pipes might need to be configured to use DHCP, whilst the other might need a static IP. It would be bad if the server booted up with these configurations assigned the wrong way around.
This is easily achieved by adding hwaddress ether XX:XX:XX:XX:XX:XX
to the bottom of your configuration block like so:
allow-hotplug enp0s19
iface enp0s19 inet static
address 192.168.0.2
netmask 255.255.255.0
hwaddress ether BC:24:11:A9:6E:EB
Names And Alt Names
When you look at the output of ip addr
, you may see two names for an interface.
In the example below, it has the name ens19
and enp0s19
.
3: ens19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether bc:24:11:a9:6e:eb brd ff:ff:ff:ff:ff:ff
altname enp0s19
inet 192.168.0.2/24 brd 192.168.0.255 scope global enp0s19
valid_lft forever preferred_lft forever
inet6 fe80::be24:11ff:fea9:6eeb/64 scope link
valid_lft forever preferred_lft forever
Whichever name you use for configuring the interface in the */etc/network/interfacesfile, that
is the name you will need to use when performing operations like
ifupand
ifdown`.
First published: 14th January 2025