How to Configure a Static IP Address on Debian 13

How to Configure a Static IP Address on Debian 13

Devices or machines connected to your router typically have a dynamic IP address. The DHCP server assigns a dynamic IP address to devices connected to the network. As a result, the same device will probably acquire a different IP address when it reconnects to the network later. To secure a static IP address for your machine, a configuration is required. In this article, we will guide you through configuring a static IP address on Debian 13.

Prerequisites

  • A Debian 13 VPS
  • SSH root access, or a user with sudo privileges.

Conventions

# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user

Ifupdown is a classic tool for network configuration in Linux. It utilizes the /etc/network/interfaces file, which is composed in a straightforward text format. Unlike Netplan, ifupdown does not use YAML. It presents a simple approach to defining network interfaces, IP addresses, and other settings. Generally, changes to the configurations require either a restart of the networking service or a system reboot. People use ifupdown because of its simplicity, and ifupdown is commonly found in Debian-based systems, providing a familiar setup for those accustomed to traditional network configuration techniques. To configure network interfaces with ifupdown, users edit the /etc/network/interfaces file and then execute commands such as ifup and ifdown to apply the changes or bring the interfaces up or down.

Before making changes to our network configuration, we need to check the current IP address using this command:

# ip a

The command will show you this information:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:39:a6:cb brd ff:ff:ff:ff:ff:ff
altname enp2s1
altname enx000c2939a6cb
inet 192.168.93.131/24 brd 192.168.93.255 scope global dynamic noprefixroute ens33
valid_lft 1773sec preferred_lft 1548sec
inet6 fe80::8ca3:7134:e935:374d/64 scope link
valid_lft forever preferred_lft forever

As you can see above, the server IP address is 192.168.93.131 and the broadcast address is 192.168.93.255.

First, let’s make a backup of the configuration. Run this command:

# cp -a /etc/network/interfaces{,.bkp}

Now, let’s see the existing configuration:

# cat /etc/network/interfaces

It will print the content of the interfaces file.

# 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 ens33
iface ens33 inet dhcp

According to the configuration above, the DHCP server assigned the IP address 192.168.93.131 to you. The DHCP server could be your modem, access point, or wifi.

Let’s edit it to use a static IP address.

# nano /etc/network/interfaces

Comment on these lines:

allow-hotplug ens33
iface ens33 inet dhcp

It should look like this:

#allow-hotplug ens33
#iface ens33 inet dhcp

Then add the following lines to the file:

auto ens33
iface ens33 inet static
address 192.168.93.111
netmask 255.255.255.0
network 192.168.93.0
broadcast 192.168.93.255

As mentioned in the initial article, the ifupdown requires a service restart to apply the changes

# systemctl restart networking

Now, let’s check the new IP address.

# ip a

You will see this output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:39:a6:cb brd ff:ff:ff:ff:ff:ff
altname enp2s1
altname enx000c2939a6cb
inet 192.168.93.111/24 brd 192.168.93.255 scope global ens33
valid_lft forever preferred_lft forever

You’ve Configured a Static IP Address on Debian 13

That’s it all. You have learned how to configure a static IP address on Debian 13.

Please note that you must be cautious when making changes to the network configuration. If you follow this article and apply its instructions to your server, it may lose its networking capabilities. Therefore, follow the steps above with caution.

If you use Ubuntu as your operating system and want to modify your network configuration, please refer to our blog post on the topic here on our website.

If you liked this post on how to configure a static IP address on Ubuntu, please share it with your friends or leave a comment below.

Leave a Comment