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