Applies to: Debian 13 (trixie) and Debian 12 servers that use ifupdown; tested with ifupdown 0.8.44 on Debian 13

On a Debian server without a desktop, the network is set in /etc/network/interfaces (the ifupdown package). To give the server a static IP address, change the interface from dhcp to static and add the address and gateway. Keep a console (VNC or IPMI) open while you do this: a typo can cut off your SSH session.

1. Find the interface name and current settings

ip -br addr
ip route
cat /etc/network/interfaces

Interface names depend on the hardware, for example eth0, ens3 or enp1s0. Use the name from ip -br addr everywhere below. If the file contains source /etc/network/interfaces.d/*, settings can also be in that folder, so check it too.

If the server uses NetworkManager (the Debian default when a desktop is installed) or netplan instead, this file is not the one in charge. Look for /etc/netplan/*.yaml or run nmcli connection show.

2. Back up the file

sudo cp /etc/network/interfaces /etc/network/interfaces.bak

3. Write the static configuration

Use the address, prefix length and gateway your provider gave you. This example sets IPv4 and IPv6 with documentation addresses:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
    address 203.0.113.10/24
    gateway 203.0.113.1
    dns-nameservers 1.1.1.1 9.9.9.9

iface eth0 inet6 static
    address 2001:db8::10/64
    gateway 2001:db8::1
  • auto eth0 brings the interface up at boot. According to the interfaces(5) manual, allow-hotplug instead brings it up when udev detects it.
  • address takes the prefix length after the slash, so you don’t need a separate netmask line. Not sure which prefix you have? See the subnet mask cheat sheet.
  • dns-nameservers is only used when the resolvconf package is installed. Without it, put the DNS servers in /etc/resolv.conf as nameserver 1.1.1.1 lines.

4. Check the file before applying it

ifquery reads the file and shows how it understood it; ifup -n prints the commands it would run without running them:

$ ifquery eth0
address: 203.0.113.10
gateway: 203.0.113.1
dns-nameservers: 1.1.1.1 9.9.9.9
broadcast: 203.0.113.255
netmask: 255.255.255.0
...
$ sudo ifup -n -v eth0
ifup: configuring interface eth0=eth0 (inet)
ip addr add 203.0.113.10/255.255.255.0 broadcast 203.0.113.255 	  dev eth0 label eth0
ip link set dev eth0   up
 ip route add default via 203.0.113.1  dev eth0 onlink
...

A mistake shows up here instead of taking the server offline. When we typed inet statik, both commands stopped with:

ifquery: /etc/network/interfaces:7: unknown or no method and no inherits keyword specified
ifquery: couldn't read interfaces file "/etc/network/interfaces"

5. Apply the change

From the console, restart the interface:

sudo ifdown eth0 && sudo ifup eth0

Or simply reboot. The Debian wiki notes that systemctl restart networking, which many older guides use, doesn’t restart every interface. Then check with ip -br addr, ip route and a ping to the gateway and to an outside address.

Going back to DHCP

Change the line to iface eth0 inet dhcp and remove the address lines. On Debian 13 the release notes say ifupdown should use dhcpcd-base as its DHCP client, because ISC DHCP is deprecated.

Related: static IP on other Linux distributions, extra IP addresses with netplan, ifconfig compared with ip and what changed in Debian 13.

Official documentation: Debian wiki: network configuration and interfaces(5).

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)