How to set up static IP address on Debian Linux 10/11

I have Debian 10 Linux cloud server, and it is configured to get IP addresses via DHCP. How do I convert DHCP address to static IP address settings?

Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements Debian Linux
Time 5m
By default, the DHCP server will provide IP information in your network. Your DHCP client on Debian Linux will obtain an IP address, subnet, default route, DNS server/resolvers IP address, and other information configured on the DHCP server. Let us see how to add, configure and set up a static IP address on Debian Linux version 9/10/11.

How to static IP address on Debian Linux

The procedure is as follows to set up and configure a static IP information:

  1. Open the terminal application.
  2. Log in to remote or server using ssh command.
  3. Backup /etc/network/interfaces file running sudo cp /etc/network/interfaces /root/
  4. Edit the /etc/network/interfaces
  5. Configure static IP address for enp0s5 Ethernet interface: address 192.168.2.249
  6. Add subnet mask: netmask 255.255.255.0
  7. Set up default gateway IP: gateway 192.168.2.254
  8. Finally add DNS resolver IP: dns-nameservers 192.168.2.254 8.8.8.8 1.1.1.1

Let us see all commands and examples in details.

Finding your network interfaces name on Debian Linux

Use the ip command as follows to show/display available Ethernet network interfaces:
ip -c link show
Also, we can try the following Linux command to show a list of network cards:
sudo lshw -class network -short
lspci | egrep -i --color 'network|ethernet|wireless|wi-fi'
ip -br -c link show

Note down the Debian Linux interface name and type the following ip command to see the current IP address assinged to that network interface:
ip -c addr show enp0s5

Finding NIC name and IP assigned by the DHCP server on Debian Linux

Configuring Static IP on Debian 10 or 11

The /etc/network/interfaces[/file] contains network interface configuration information for Debian Linux. Hence, edit the file:
sudo vim /etc/network/interfaces
## OR ##
sudo nano /etc/network/interfaces

Look for the primary network interface enp0s5:

allow-hotplug enp0s5
iface enp0s5 inet dhcp

Remove dhcp and allow-hotplug lines. Append the following configuration to set up/add new static IP on Debian Linux 10/11. Here is my sample config file:

# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
auto enp0s5
iface enp0s5  inet static
 address 192.168.2.236
 netmask 255.255.255.0
 gateway 192.168.2.254
 dns-domain sweet.home
 dns-nameservers 192.168.2.254

Save and close the file when using vim/vi text editor.

Restart networking service on Debian Linux to switch from DHCP to static IP config

Warning: Do not run the following over ssh based session as you will disconnect.

Use the systemctl command as follows:
sudo systemctl restart networking.service
Make sure service restarted without any errors. Hence, type the following command:
sudo systemctl status networking.service
Sample session:

 networking.service - Raise network interfaces
   Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
   Active: active (exited) since Wed 2021-01-27 23:10:00 IST; 1min 38s ago
     Docs: man:interfaces(5)
  Process: 1104 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=0/SUCCESS)
 Main PID: 1104 (code=exited, status=0/SUCCESS)

See your new IP address assigned on Debian Linux

Again type the following ip command:
ip -c addr show
ip -c addr show enp0s5


When you change your IP address, you need to restart other services such as Nginx, SSH, etc. It all depends upon how you configured those services with IP binding. Make sure you adjust the firewall settings too.

Conclusion

You learned how to convert the existing DHCP to static IP address settings on Debian Linux version 9/10/11. See Debian Linux man page online or type the following command:
man interfaces


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • Clownfeuer Jan 27, 2021 @ 18:42

    auto not audo

    • 🐧 Vivek Gite Jan 27, 2021 @ 19:12

      Opps. Fixed it. Thanks kind stranger.

      • Mhe Jan 28, 2021 @ 10:15

        default gateway 192.168.0.1 is not a good example in your list. This would not reachable, right?

        • 🐧 Vivek Gite Jan 28, 2021 @ 12:05

          Oh no. My tired eyes. Fixed it. Thank you very much!

  • Slinus02 Jan 28, 2021 @ 12:35

    While I respect the existence of the IP Commands, I’d rather use ifconfig because it’s so much simpler and I really don’t understand why you have to Install net-tools after the fact.

  • Robert Derochette Jan 29, 2021 @ 10:47

    To make sure you don’t choose a static IP that is already assigned, scan your network first using nmap. For example, if your network is 192.168.1.0/24 then do

    nmap -sP 192.168.1.*

    This will list all the machines connected to the network. If you perform the command as root you will often get enough information to know which address corresponds to each machine.

Leave a Reply

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

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz