Setting the IP address in Debian¶
In this article
Note
Network interfaces in Debian (including Debian 12 and 13) are stored and configured through the configuration file /etc/network/interfaces (the ifupdown package). Additional configuration files can be placed in the /etc/network/interfaces.d/ directory.
Modern Debian versions use predictable network interface names, such as eno1, enp1s0 or ens18, rather than eth0. You can find the interface name on your server with the command:
The examples below use the name ens18 - replace it with the name of your interface.
How to configure DHCP¶
Attention
Active DHCP services on external Ethernet interfaces are forbidden by the Terms and Conditions of services and the use of the site.
How to set up a static IP address¶
The example of configuring a static IP address for an interface named ens18:
auto ens18
iface ens18 inet static
address 192.168.0.7/24
gateway 192.168.0.254
dns-nameservers 8.8.8.8 8.8.4.4
Attention
For the dns-nameservers parameter to work correctly, you need to install the resolvconf package. Without it, DNS servers are specified in the /etc/resolv.conf file.
Use of configuration¶
After changing the configuration file, you need to restart the interface. Run both commands in one line so that, when connected via SSH, the interface is brought up immediately after it goes down:
Attention
Restarting the main interface (as well as the systemctl restart networking command) while connected via SSH may drop the connection, and an error in the configuration may leave the server without network access. Check the file before applying it and keep the remote access console in Invapi at hand. If the IP address has changed, reconnect to the server using the new address.
You can check the network settings through the following command: