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!

 

Leave a Reply

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