Static IP in Debian 9 Stretch

If you follow the instructions in the Debian wiki to set a static IP you will break your network until you reboot. For some odd reason you have to run ifup <interfaceName> when you’re done. Here are all the steps:

# Log in as root or su to root then
nano /etc/network/interfaces
# Should look like this:
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

Now edit it so the bottom looks like this but with your network configuration:

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.202
netmask 255.255.255.0
gateway 192.0.1.1

Now run:

service networking restart

Here is the important part. If you check your ip address it will not have updated to the static one you just configured and the network will be unreachable.

ip addr
# ...
inet 192.168.1.84/24 brd 192.168.1.255 global eth0
# ...
ping 8.8.8.8
connect: Network is unreachable

One command saves the day!

ifup eth0

Now if you check your address with ip addr you will see your static IP and be able to reach the network!

I was inspired by this tip: http://beerpla.net/2012/07/15/quick-tip-how-to-fix-network-is-unreachable-after-switching-from-dhcp-to-static-ip-configuration/