Setting a static IP address on Debian 11

If you wish to set a static IP address on your Debian 11 serverthen you've come to the right place! By default, the network card of a Debian machine is configured as DHCP. How can I switch to a fixed IP so that the IP address doesn't change over time? That's what we're going to find out.

A very simple but essential operation: if you're here, it's probably because you'd like to learn how to perform it, or that you've forgotten how. That's okay, this article is here to guide you.

1. View current IP configuration

I remind you that the command below allows you to view its current network configuration on a Debian 11 machine. It's also a way of viewing the various interfaces and interface names. It's a new command which, for some years now, has replaced the "ifconfig" command you may be familiar with if you've been using Linux for several years.

ip address

The example below, on a Debian 11 machine, shows the configuration of each network card, with IP address, subnet mask, MAC address of the network card, link status, etc....

Setting a static IP address on Debian 11

The "lo" card is the network card for the local loop (localhost). While the second card, for example "ens192" or "eth0This is your machine's card for accessing the local network. In my case, the name is "ens192". Depending on the type of Debian 11 machine, whether it's a VM or a physical server, the name may vary.

To display the current DNS servers :

cat /etc/resolv.conf

To display the default route :

ip route show

2. Configure IP address in /etc/network/interfaces

Network configuration is carried out in the " interfaces "which we must change without delay.

sudo nano /etc/network/interfaces

When indicated " inet dhcp" means that the board is currently using dynamic IP addressing via DHCP. To use a static IP address, here's an example of how to set the IP address ". 10.10.10.100/24 "on my machine, with the gateway". 10.10.10.1 "and the DNS server " 8.8.8.8" . I remind you that the DNS server is required for DNS resolution to work, which allows you to access the Internet and download packages from the official Debian repositories.

In the example below, don't forget to replace "ens192" with the name of your card if it's not the same on your machine. Entering " inet static "allows you to set a static IP address.

allow-hotplug ens192
iface ens192 inet static
address 10.10.10.100/24
gateway 10.10.10.1
dns-nameservers 8.8.8.8
dns-domain tutobox.local

Save the file to save your changes. Next, restart the "networking.service" service to put this new configuration into production. Two commands are followed to mount the network card (adapt the card name if necessary).

sudo systemctl restart networking.service ; sudo ifup ens192

This last step is important, otherwise the new IP address will not be supported. Be careful if you are connected via SSH with PuTTY, WinSCP, etc... You risk losing the connection. In this case, you'll need to reconnect to your machine using the new IP address you've just defined in Debian 11's "interfaces" file.

Alternatively, you can directly restart the Debian 11 server to apply the new IP address.

How can I check that the new IP address is supported? You can replay the previous commands, in particular "ip address", which can be shortened to "ip a", and the other two commands to check the default gateway and the DNS part.

Thanks to this article in the tutorial box, you have now defined a fixed IP address on your Debian 11 machine. (Linux).

Additional resources :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *