April 6, 2020

soltveit.org

..Geekish..

Debian 10 Static IP

Debian 10 Static IP

Debian 10 static IP works just like the previous version. They changed the naming of the network interfaces in Debian 9. However if you have upgraded from Debian 8 or older, your LAN port is probably still named ETH0. These instructions require sudo or root.

Debian 10 static IP

Debian 10 static IP

This is how you set a Debian 10 static IP. First, you need to open /etc/network/interfaces with your favorite text editor. Nano is always installed so you can use that. I often use Vim since that is the editor I’m used to. If your Debian 10 is set up with a Dynamic IP, it probably looks something like this.

Debian 10 Static IP
Debian 10 with dynamic IP

Your interface might have a different name than enp1s0. What we need to do here is to change DHCP to static, and add the address, gateway, and netmask. Also, your network settings are most likely different from the settings on my network. I use the 192.168.2.0/24. Let’s look at an example from one of my servers at home.

ronny@db2:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug enp1s0
iface enp1s0 inet static
address 192.168.2.82
netmask 255.255.255.0
gateway 192.168.2.1

Apply the changes

A restart of the network service is required to apply any new settings to the network interfaces. So if you are connected with SSH, you need to restart the computer to apply the settings. Because the connection will be lost when you restart the network service. 

To restart the network service, run this: /etc/init.d/networking restart

This will restart the network service, but will not work because the network interface will be down. So you need to get it up again by running this command: ifup enp1s0 (your actual interface instead of enp1s0)

To verify that the new IP address working, run this command: ip addr

You might see now that you have two inet addresses. You can actually use both. To get rid of your old dynamic IP address, you can just reboot your computer.

You can probably use your router to assign static IP addresses too. Check your router documentation on how to do this.

If you have Debian 9, here is how to set static IP.

A link to the Debian documentation.