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 Ibmi Media, 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.
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 )
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:
iface enp0s3 inet static
dns-nameservers 184.108.40.206 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.
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.