Set a Static IP Address on Debian with ifupdown
Goal
A Debian server that always comes up with the same IP address, even if the router is replaced or its DHCP server fails: needed for cluster nodes that must find each other.
Prerequisites
- Debian using
ifupdown(/etc/network/interfaces), the default on a server install without NetworkManager. - An address outside the router's DHCP range, so nothing else can be given it.
- Console access, in case the network doesn't come back.
Steps
- Find the interface name (
enp…oreth0):ip link show - In
/etc/network/interfaces, replace theiface <name> inet dhcpline with:auto <name> iface <name> inet static address 192.168.1.50/24 gateway 192.168.1.1 dns-nameservers 1.1.1.1 8.8.8.8dns-nameserversonly takes effect with theresolvconfpackage installed; otherwise set the servers in/etc/resolv.conf. - Apply it:
sudo systemctl restart networking
Verify
-
ip -br addr show <name>shows the new address. -
ping -c 3 192.168.1.1andping -c 3 debian.orgboth answer. - The address is the same after a reboot.
Troubleshooting
- No DNS resolution but pings to IPs work:
resolvconfisn't installed, sodns-nameserverswas ignored. - Address conflict: another device got the same IP from DHCP; move the address outside the DHCP pool or reserve it on the router.
References
- Debian Reference: The network interface with the static IP -
ifupdownconfiguration. - interfaces(5) man page - the file format.
- Linux Administration MOC - hub for Linux notes.