How to set a static IP address on Debian server

Jack Wallen walks you through the process of giving a standard user sudo privileges so they can set a static IP address on Debian server.

Image: iinspiration/Adobe Stock

Debian is one of the most reliable operating systems on the planet. Its slower release cycle means each iteration gets plenty of attention before each release. And Debian isn’t just for desktops. In fact, Debian has been deployed as a server for years.

The one thing many new admins might find with deploying Debian as a server is that setting an IP address isn’t exactly as intuitive as other distributions. RHEL-based Linux distributions have the nmtui ncurses tools for configuring network connections, and Ubuntu-based distributions have netplan. With Debian, setting a static IP address is a bit more old-school, so I’m going to show you how it’s done.

SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)

What you need

To set the IP address on Debian server, you’ll need a running instance of the OS and either a user with sudo privileges or access to the root user account. I’ll show you first how to give a standard user sudo privileges.

How to give a standard user sudo privileges

Let’s create a new user first. I’ll demonstrate by creating the user olivia (you can name the user whatever you like). To do that, log into Debian server as the root user and issue the command:

adduser olivia

Once you’ve added the new user, add that user to the sudo group with:

sudo usermod -aG sudo olivia

Exit from the root user and log in with the new user account.

How to set a static IP address

The first thing you must do is locate the name of your network device. For that, issue the command:

ip -c link show

You should at least see two devices, lo (for loopback) and another named device (such as enp0s3).

Next, let’s back up the current network configuration file with the command:

sudo cp /etc/network/interfaces ~/

Open the configuration file for editing with the command:

sudo nano /etc/network/interfaces

If you find nano isn’t installed, add it with the command:

sudo apt-get install nano -y

With the interfaces file open for editing, you should see a DHCP configuration that looks like this:

# The primary network interface

allow-hotplug enp0s3

iface enp0s3 inet dhcp

Comment that block out so it looks like this:

# The primary network interface

# allow-hotplug enp0s3

# iface enp0s3 inet dhcp

Now, we can add the necessary configuration for a static IP address. Let’s configure enp0s3 to use the address 192.168.1.97, with a gateway of 192.168.1.1, and a DNS nameserver of 1.1.1.1. That configuration will look like this:

# The primary network interface

auto enp0s3

iface enp0s3  inet static

address 192.168.1.97

netmask 255.255.255.0

gateway 192.168.1.1

dns-domain example.com

dns-nameservers 1.1.1.1

Make sure to edit the above configuration to match your network scheme. Save and close the file.

Finally, restart the networking service with the command:

sudo systemctl restart networking

Make sure the networking configuration is correct, by issuing the command:

ip a

You should see the static IP address you configured. You’re good to go.

And that’s all there is to configure a static IP address in Debian server. Of course, if you installed your instance of Debian server with a desktop environment, you could simply use the GUI tool for this process. But for those who prefer to keep their servers sans GUI, this is the way to go.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.