Set a Static IP Address on Debian with ifupdown

In progress Linux Networking

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

  1. Find the interface name (enp… or eth0):
    ip link show
    
  2. In /etc/network/interfaces, replace the iface <name> inet dhcp line 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.8
    
    dns-nameservers only takes effect with the resolvconf package installed; otherwise set the servers in /etc/resolv.conf.
  3. Apply it:
    sudo systemctl restart networking
    

Verify

  • ip -br addr show <name> shows the new address.
  • ping -c 3 192.168.1.1 and ping -c 3 debian.org both answer.
  • The address is the same after a reboot.

Troubleshooting

  • No DNS resolution but pings to IPs work: resolvconf isn't installed, so dns-nameservers was 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