Set a Static IP on Debian 11 - How to do it ?

On a DHCP network, your Linux system will usually receive an IP address automatically from the DHCP server which, in most cases, is the router. The IP configuration will usually comprise the IPv4 address, the netmask, gateway, and the DNS settings. This is usually convenient for desktop or client PCs which only need to access the internet or network resources.

However, the case is different when you want to set up a server. In this case, you would need to configure a static IP to make the server always available via the same IP address. With DHCP, the IP address is bound to change once the lease time is over leading to the unavailability of the server.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux system DHCP queries.

In this context, we shall look into how to set a static IP on Debian 11. This also entails how you can configure a static IP on both the desktop GUI and server instances.


How to Set a Static IP on Debian ?

There are two ways of configuring a static IP on Debian. This can be implemented via GUI or on command-line. Before proceeding with this configuration task, ensure that you have configured a sudo user.


1. Steps to Configure Static IP Address using the Graphical User Interface ( GUI )

  • If you are running a Debian 11 desktop instance, log in using your username and password. Before we configure the static IP, first confirm the IP address assigned to your system. In our case, we had a Debian PC with an IP address of 192.168.2.100 in a DHCP network.
  • Now to verify this, simply execute the below command: $ ip addr show
  • From the output of the above command, you will see that enp0s3 interface (Which could be something else in your case) is the active link that is assigned the IP address.
  • To get started with setting the static IP, click on 'Activities' on the left far corner. Search for and click on the 'Settings' icon.
  • On the 'Settings' page, select the 'Network' tab. Next, head over to the 'Wired' section and click on the small gear wheel.
  • Next, you will see the current IP address configuration. 
  • Now, you will see that the system IP address has been dynamically allocated to the active interface using the DHCP service.
  • To override the DHCP settings and manually set a static IP which will persist even upon a reboot, follow the below process.
  • Click the IPv4 tab. Switch from 'Automatic' to 'Manual' in the IPv4 method section. Thereafter, specify your desired IP address, netmask, and default gateway. Be sure to also provide the preferred DNS settings.
  • To apply the changes made, click the 'Apply' button.
  • You need to restart the networking daemon or service for the Debian system to implement the new static IP settings. So, turn the toggle button off and then on.
  • Click on the gear icon once more to verify that the static IP settings have been applied.
  • On the terminal, verify that the network interface has acquired the newly configured IP address by running the below command: $ ip addr show 
  • The output is a confirmation that the system was successfully configured using a static IP. 


2. How to Configure Static IP Address using the terminal ?

If you are running a headless server, or are connecting to a remote server via SSH, the only option available is to configure the static IP on the command line.

The network configuration settings are stored in the /etc/network/interfaces file. You can edit this file by running the below command:

$ sudo vim /etc/network/interfaces

By default, only the loopback settings are specified.

Now, specify the IP settings for our active network interface. But before making any changes, make a backup of the configuration file with the below command:

$ sudo cp /etc/network/interfaces /etc/network/interface.bak

In this file, You can Specify the IP settings as provided below. Also Ensure that your settings is in accordance with your network subnet:

auto enp0s3
iface enp0s3 inet static
 address 192.168.2.150
 netmask 255.255.255.0
 gateway 192.168.2.1
 dns-nameservers 8.8.8.8 192.168.2.1

Finally, To apply the changes, restart the networking service:

$ sudo systemctl restart networking

NOTE: This will disconnect you from the server if you are connected via SSH. Reconnect using the newly set static IP address.


[Need assistance in configuring Static IP address on your Linux system ? We can help you. ]

This article covers the different ways of assigning a static IP on your Debian 11 system which could either be via GUI or the terminal. In fact, DHCP or Dynamic Host Control Protocol dynamically assigns an IP address to an interface. It requires a DHCP server running in the network. In the static IP assignment, we manually assign the IP address, routing gateway, and DNS resolvers. Static IP assignment gives to more control on assigning an IP address and setting the DNS resolvers.

Related Posts