How To Set a Static IP on a Headless Debian Server

Configuring a static IP Address on a headless Debian server post-installation is straightforward. Modern Debian releases since Debian 10 use ifupdown (/etc/network/interfaces) by default for networking.

I have a Debian server running, and I will connect to it via SSH.

Step 1: Identify Your Network Interface Name

Run the following command to list active interfaces:

ip link show

Look for your primary Ethernet device (for example, ens33). Ignore lo (loopback).

Step 2: Edit the Network Interfaces File

Open the network configuration file in your preferred text editor (like nano):

sudo nano /etc/network/interfaces

Find the entry for your interface (for example, ens33). It might currently look like this:

# The primary network interface

auto ens33

iface ens33 inet dhcp

Change dhcp to static and add your network details (replace the interface name, IP, gateway, and subnet mask with your actual network settings):

# The primary network interface

auto ens33

iface ens33 inet static

    address 192.168.1.170/24

    gateway 192.168.1.1

    dns-nameservers 1.1.1.1 1.0.0.1

Note: Modern syntax uses the CIDR format (/24 for 255.255.255.0). If you prefer explicit lines, you can write netmask 255.255.255.0 on its own line instead of /24.

Adjust the values to fit your local network.

Save and exit Control + O, Enter, then Control + X (or Control + X, Y, then Enter) in nano editor.

Reboot the system and log back in using your new static IP:

sudo reboot

Then connect again using SSH:

ssh username@192.168.1.170

Step 3: DNS Name Resolution

Standard Debian setups using ifupdown often require the resolvconf package to apply dns-nameservers entries directly to /etc/resolv.conf.

To configure DNS:

Edit /etc/resolv.conf directly (manual)

Set active DNS resolvers manually in your DNS configuration file:

sudo nano /etc/resolv.conf

Ensure the file contains the following lines (add or replace them):

nameserver 1.1.1.1

nameserver 1.0.0.1

Save and exit (Control + X, Y, then Enter) in nano editor.

Apply the changes, run:

sudo systemctl restart networking

Install the resolvconf Package

Install the resolvconf package so you don't have to manually edit /etc/resolv.conf every time or you can install the package as a first step so you don't have to manually edit /etc/resolv.conf for the first time:

sudo apt install resolvconf

Apply the changes, run:

sudo systemctl restart networking

or reboot the system:

sudo reboot

Step 4: Verify Your Configuration

Confirm that the IP address was assigned correctly:

ip addr show ens33

Verify internet routing and DNS resolution:

ping -c 3 1.1.1.1

ping -c 3 debian.org

Once these checks complete successfully, your headless Debian server should be using the configured static IP address, with network connectivity and DNS name resolution working as expected.

With a static IP configured, you can reliably connect to your headless Debian server over SSH without having to determine its new DHCP-assigned address after every reboot.

Post a Comment

Previous Post Next Post

Contact Form