There are two basic ways to set up a static IP address on Debian 10. The simplest for desktops is through NetworkManager’s graphical interface. For servers or systems without NetworkManager, you can use a configuration file too.
In this tutorial you will learn:
- How to Configure a Static IP with NetworkManager
- How to Configure a Static IP From the CLI
Software Requirements and Conventions Used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Debian 10 Buster |
Software | NetworkManager |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Configure a Static IP with NetworkManager
To start, right click on the NetworkManager applet in your system tray. This will work with the applet regardless of whether is on GNOME, XFCE, MATE, or something else. When the menu pops up, select Edit Connections….
A new window will open up, listing all the connections on your system. Select the connection that you want to switch to a static IP, and press the gear icon button in the bottom left of the window.
Yet another window will open with the settings for your connection. Click the IPv4 Settings tab. Near the top of the IPv4 settings, you’ll see a drop down menu labeled Method, and it’ll be set to DHCP. Use the menu to select Manual instead.
Below that, there’s a blank table of addresses. Press the Add button next to it to set up a new static address. A new row will open up on the table. Enter your desired IP address in the Address cell and the IP of your router in the Gateway. The default Netmask is 255.255.255.0
. If you didn’t set anything different yourself, use that.
Be sure to set up a DNS server. Enter its IP address in the DNS servers section too. If you don’t have anything specific, enter your router’s IP there too. When you’re done, press Save.
The changes may take effect automatically, but more than likely, you’ll need to disconnect from that interface, and reconnect first.
Configure a Static IP From the CLI
For the command line, you’re going to need to make a few changes. First, disable and stop NetworkManager.
# systemctl stop NetworkManager # systemctl disable NetworkManager
This next part isn’t strictly necessary, but it’s helpful. Install resolvconf
.
# apt install resolvconf
Now, use your favorite text editor to open /etc/network/interfaces
. By default, this file is really sparse. That’s because it really isn’t used in conjunction with NetworkManager.
Begin a new line with, iface eth0 inet static
to set your interface to static. Substitute your actual interface instead of eth0
. If you aren’t sure what it is, use ip a
to find out.
Below the iface
line, start a new line indented by one tab. Every subsequent line in this block will also be tabbed in. Assign an address
to your computer.
address 192.168.1.110
Next, set the broadcast address and netmask. If you haven’t set anything custom, it should look like the example below.
broadcast 192.168.1.255 netmask 255.255.255.0
Below that, set your router’s IP address as the gateway.
gateway 192.168.1.1
Finally, set your DNS nameservers. You only need to specify one, and if you don’t have a specific choice, use your router’s IP.
dns-nameservers 192.168.1.5
Altogether, it should look something like this:
source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback iface eth0 inet static address 192.168.1.110 broadcast 192.168.1.255 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 192.168.1.5
Restart both networking
and resolvconf
to see the change take effect. If it doesn’t, you’ll need to restart the machine.
# systemctl restart networking # systemctl restart resolvconf
Conclusion
Whichever way you went about it, your computer should now be using the static IP address that you provided for it. These configurations are both set up to stay in effect indefinitely, unless you manually change them, so there shouldn’t be any surprises, once you’re set up.