29. June 2021

Set Up Static IP Debian

By H. Cemre Günay

In this basic tutorial I show you how to assign a static IP address to a Debian VM.

The /etc/network/interfaces contains network interface configuration information for our Debian VM. We need to edit this File with vim or nano (preferred) editor. Login into your Debian virtual machine as User or Root. If you are root, you don’t need to use sudo:

# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
allow-hotplug enp0s5
iface enp0s5  inet static

We need to edit this part of the file:

allow-hotplug enp0s5
iface enp0s5  inet static

Now replace allow-hotplug with auto and dhcp with static in the lines. Add the following configuration to set up/add new static IP on Debian. Here is my sample config file:

auto enp0s5
iface enp0s5  inet static
 address 192.168.2.236
 netmask 255.255.255.0
 gateway 192.168.2.254
 dns-domain irg.net
 dns-nameservers 192.168.2.254

Please use your own IP Adresses, not the same like in my sample. Work with spacebar not tab button!

Last but not least – we restart the networking service of our Debian VM to change the configuration from DHCP to Static:

systemctl restart networking.service

Make sure the networking service restarted without any errors with following command:

systemctl status networking.service

Sample Output:

● networking.service - Raise network interfaces
   Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
   Active: active (exited) since Wed 2021-10-06 14:57:00 IST; 1min 38s ago
     Docs: man:interfaces(5)
  Process: 1104 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=0/SUCCESS)
 Main PID: 1104 (code=exited, status=0/SUCCESS)

If you have any questions, please leave a comment. 🙂