Configuring a Static IP and Static Routes on a Raspberry Pi running Raspbian Jessie using the CLI

Since the release of Raspbian Jessie a few things have changed regarding configuration of the network stack from the CLI. I got stuck on this today and it took me a while to sort out so I figured it was worth a quick post.

Previous to Raspbian Jessie, network parameters could be adjusted by editing /etc/network/interfaces. This functionality has now been moved to /etc/dhcpcd.conf, the reasons why are beyond the scope of this post.

To enter a static IP, fire up your favourite text editor and open /etc/dhcpcd.conf

The syntax is as per below

nohook lookup-hostname
interface eth0
static ip_address=192.168.0.1/24
static routers=192.168.0.254
static domain_name_servers=8.8.8.8

To add a persistent static route, create or edit the following file

/lib/dhcpcd/dhcpcd-hooks/40-route

and use the following syntax

ip route add 192.168.100.0/24 via 192.168.0.2

Enjoy!

 

3 Comments on "Configuring a Static IP and Static Routes on a Raspberry Pi running Raspbian Jessie using the CLI"


  1. Thanks so much Kirin !!!
    There is so much misleading info out there, eventually this one really helped me on Pi 3 and Pi running Debian 10 (buster)

    Reply

Leave a Reply

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