Debian

How to Assign a Fixed IP Adress on Debian 12 Desktop/Server

A fixed IP address is essential if you want to run any server software on your Debian 12 desktop/server operating system.

In this article, we will show you how to assign a fixed IP address on the Debian 12 desktop and Debian 12 server operating system. We will also show you how to check whether the internet is working on the Debian 12 desktop/server operating system after the network configuration changes.

Topic of Contents:

  1. Assigning a Fixed IP Address on the Debian 12 Desktop
  2. Assigning a Fixed IP Address on the Debian 12 Server
  3. Checking the DNS Nameservers/Search Domain and the Default Route/Gateway on Debian 12
  4. Checking the Internet Connectivity on the the Debian 12 Desktop/Server
  5. Conclusion

Assigning a Fixed IP Address on the Debian 12 Desktop

The Debian 12 desktop uses the Network Manager to manage the network interfaces by default. So, you can use the Network Manager “nmcli” management tool to assign a fixed IP address on your Debian 12 desktop operating system.

To list all the configured Network Manager connections, run the following command:

$ nmcli connection show

 

All the Network Manager connections should be listed. You can set a fixed IP address on any one of these Network Manager connections.

We set a fixed IP address on the Network Manager connection “Wired connection 1” for the demonstration. “Wired connection 1” uses the physical network interface “ens32” as you can see in the following screenshot:

If you want to find out the currently configured IP address of the Network Manager connection that you want to set as a fixed IP address, read this article.

To set a fixed IP address on the Network Manager connection “Wired connection 1” (let’s say), run the following command:

$ nmcli connection edit "Wired connection 1"

 

The Network Manager interactive connection editor should be opened.

To set an IPv4 address 192.168.189.150 and a 24-bit subnet mask (let’s say), run the following command:

$ set ipv4.addresses 192.168.189.150/24

 

Type in “yes” and press <Enter>.

To set a gateway address 192.168.189.2 (let’s say) for the Network Manager connection, run the following command:

$ set ipv4.gateway 192.168.189.2

 

To set a primary DNS server 1.1.1.1 and a secondary DNS server 8.8.8.8 for the Network Manager connection, run the following command:

$ set ipv4.dns 1.1.1.1,8.8.8.8

 

To set a default DNS search domain like “linuxhint” for the Network Manager connection, run the following command:

$ set ipv4.dns-search linuxhint

 

To permanently save the changes, run the following command:

$ save persistent

<img src="https://linuxhint.com/wp-content/uploads/2023/11/How-to-Assign-a-Fixed-IP-Adress-on-Debian-12-DesktopServer-7.png" alt="" width="624" height="95" class="alignnone size-full wp-image-393443" />

To apply the changes, run the following command and press <strong><Enter></strong> afterwards:
[cc lang="bash" width="100%" height="100%" escaped="true" theme="blackboard" nowrap="0"]
$ activate

 

Once you’re done configuring a fixed IP address for the Network Manager connection, run the following command to exit out of the Network Manager interactive connection editor program:

$ quit

 

To verify whether your desired IPv4 address is set for the Network Manager connection “Wired connection 1” (let’s say), run the following command:

$ nmcli connection show "Wired connection 1" | egrep 'ipv4.(addresses:|gateway:|dns:)'

 

As you can see, the desired IPv4 address, gateway address, and DNS server addresses are set for the Network Manager connection “Wired connection 1”.

Assigning a Fixed IP Address on the Debian 12 Server

The Debian 12 server operating system does not use the Network Manager to manage the network configurations by default. So, you have to use the “/etc/network/interfaces” file to configure the network on your Debian 12 server system.

You also need to install resolvconf on the Debian 12 server system to manage the DNS nameservers and DNS search domains using the “/etc/network/interfaces” configuration file.

To set up a fixed IP address on your Debian 12 system, you need to know the name of the network interface that you want to configure as a fixed IP address.

To list all the available network interfaces of your Debian 12 system, run the following command:

$ ip a

 

All the available network interfaces of your Debian 12 system should be listed. We configure a fixed IP address on the “ens32” network interface for the demonstration. The “ens32” network interface has the 192.168.189.145 IP address at the moment.

Open the “/etc/network/interfaces” file with the nano text editor as follows:

$ sudo nano /etc/network/interfaces

 

As you can see, the “ens32”[1] network interface is configured to use DHCP[2]. DHCP is a method for configuring a network interface automatically with IP information.

To set a fixed IP address of 192.168.189.150, a 24-bit subnet mask, gateway address of 192.168.189.2, primary and secondary DNS nameservers 1.1.1.1 and 8.8.8.8 respectively, and the DNS search domain which is “linuxhint” for the “ens32” network interface, type in the following lines in the “/etc/network/interfaces” file.

allow-hotplug ens32
iface ens32 inet static
    address 192.168.189.150/24
    gateway 192.168.189.2
    dns-nameservers 1.1.1.1 8.8.8.8
    dns-search linuxhint

 

Once you’re done, press <Ctrl> + X followed by “Y” and <Enter> to save the “/etc/network/interfaces” file.

For the changes to take effect, restart the networking service of your Debian 12 server system with the following command:

$ sudo systemctl restart networking.service

 

A fixed IP address (192.168.189.150 in this case) should be set for the desired network interface (ens32 in this case).

$ ip a

 

Checking the DNS Nameservers/Search Domain and the Default Route/Gateway on Debian 12

You can check whether your desired DNS nameservers, DNS search domain, and default route/gateway address are set on your Debian Desktop/Server operating system. If you need any assistance in checking the currently used DNS nameservers and DNS search domains of your Debian 12 system, read this article. If you need any assistance in checking the default route or gateway address of your Debian 12 system, read this article.

Checking the Internet Connectivity on the Debian 12 Desktop/Server

To check whether your internet connection is working after the network configuration changes, run the following command:

$ ping -c3 google.com

 

As you can see, we can ping “google.com”. So, the internet connection is working just fine after the network configuration changes.

Conclusion

In this article, we showed you how to assign a fixed IP address on the Debian 12 desktop operating system using the Network Manager “nmcli” tool from the command line. We also showed you how to assign a fixed IP address on the Debian 12 server operating system using the “/etc/network/interfaces” file. Finally, we showed you how to check whether the internet is working on the Debian 12 desktop/server operating system after the network configuration changes.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.