When you install a new OS, by default it is configured to obtain a dynamic IP address from the DHCP server.
However, sometimes you have to configure the static IP address on your machine.
It can be for various reasons like when a service needs to connect through an IP address instead of a domain name or when you are hosting a web server or to give someone remote access to your system.
Whatever the reason is, you must know how to configure a static IP in your system.
In this context, we shall look into how to set up a static IP in your Linux system.
How to Configure Static IP in Debian 10?
You can configure static IP in Debian 10 system using any of the following methods:
i. Configure Static IP via Command Line
ii. Configure Static IP via GUI
Now, Let's get started.
1. How to Configure Static IP via Command Line ?
You can configure the static IP through /etc/network/interfaces file from your command line.
However, for this, you first need to know the network interface name.
i. You can find the currently available network interface by running the below command in Terminal:
$ ip a
"ip a" command shows that there are two interfaces currently available.
We want to configure the static IP for the interface ens33.
Let's say that the current IP address of ens33 is 192.168.72.150 which is dynamically assigned by the DHCP.
Now we will open the interface configuration file and configure static IP for ens33.
ii. To open network interface configuration file, execute the following command:
$ sudo nano /etc/network/interfaces
iii. Then add lines in the following syntax replacing the interface with your network interface name and xxx.xxx.xxx.xxx with the relevant IP address:
iface interface inet static
address xxx.xxx.xxx.xxx #enter your IP address
gateway xxx.xxx.xxx.xxx #enter gateway ip address
iv. For our network interface ens33, we have modified the configuration lines as follows:
iface ens33 inet static
dns-nameservers 22.214.171.124 126.96.36.199
v. Once you have completed the configurations, save and close the file.
vi. Then restart the networking services. Use the below command to do so:
$ sudo systemctl restart networking.service
vii. You can also use the ifdown and ifup command to apply the configuration changes. First, run the ifdown command to bring down the interface:
$ ifdown ens33
viii. Then bring up the interface using ifup:
$ ifup ens33
ix. Now to verify if the IP address has been changed successfully, issue the below command in Terminal:
$ ip a
2. How to Configure Static IP via GUI ?
You can also change the static IP through the Settings utility in your Debian system.
i. To launch the Settings utility in your system, right-click the desktop and then click Settings.
ii. Then from the left pane in the Settings window, select the Network tab.
iii. On the right pane, click the cog icon in front of the network interface you want to configure.
iv. You will see a configuration window where you will see the current IP 192.168.72.150 which is the IP address obtained from DHCP server.
Go to IPv4 tab.
v. Then in the IPv4 Method, choose Manual.
Now the Addresses field will appear. Enter the IP address, Netmask, and Gateway for your interface. If you also want to set the DNS address manually, switch off the Automatic button and enter the DNS server address.
Here, we have specified 192.168.72.150 as our interface IP address, 255.255.255.0 as netmask, and the 192.168.72.2 ad the default gateway.
Then we have specified 188.8.131.52 and 184.108.40.206 as our DNS servers.
vi. Now click the Apply button to apply all the configuration changes.
vii. Now to confirm if the new IP address has been successfully configured, go to the Details tab.
Alternatively, you can also use the "ip a" command in Terminal to verify the IP address.