I am running raspbian and I can access anything on my lan through ethO but cannot ping an internet address. route -n says the following:

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 eth0

then I run sudo /sbin/route add -net gw eth0 followed by route -n and get

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 eth0   U     0      0        0 eth0

And everything works. So, how do I make this permanent so I don't have to run the route command everytime I boot the PI?

  • please paste the content of /etc/network/interfaces file. Commented Nov 22, 2013 at 20:19
  • 1
    How can i do that in the file dhcpcd.conf?
    – user40889
    Commented Feb 2, 2016 at 8:09
  • 1
    @winnie you should type sudo nano /etc/dhcpcd.conf and then: interface eth0, static ip_address = "the address", static routers = "the router address", static domain_name_servers = "the DNS address". Put this 4 lines one below the other and skip he commas. Substitute the text between quotes by your real numbers
    – VMMF
    Commented Jun 23, 2016 at 18:41

4 Answers 4


Adding to /etc/network/interfaces didn't work for me in Raspbian/Jessie. I was adding a second route to a VPN subnet so already had used VMMF's method to add the default route; but adding

ip route add 192.168.[othersubnet].0/24 via

to a new file created at


hooked on to /etc/dhcpcd.conf and added the route persistently.

Ref:https://wiki.archlinux.org/index.php/dhcpcd#DHCP_static_route.28s.29 and thx VMMF for the pointers in your comments.

  • Nice. At first I disliked the usage of dhcpcd for everything, but I'm really starting to like it. Thanks for this tidbit.
    – Mr. B
    Commented Mar 23, 2020 at 23:02
  • Since I only needed this for my wlan0, I just added the line to the existing file /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant. It works on Buster (2021-01-11).
    – GChuf
    Commented Jun 15, 2021 at 6:54

To make the Static Route persistent or you must add the route entries to /etc/network/interfaces

Add the static routes in the following format:

ip route add [-net|-host] <host/net>/<mask> gw <host/IP> dev <Interface>

Note This is no longer valid for Raspbian Jessie, as of June 2016 you should edit the /etc/dhcpcd.conf file instead.

  • 3
    Attention this is no longer valid for raspbian Jessie, you should edit the /etc/dhcpcd.conf file instead (June 2016)
    – VMMF
    Commented Jun 23, 2016 at 18:38

It should be noted that the up entry should be put against the iface entry (stanza as it is called in the man pages). So a more complete example for the file /etc/network/interfaces would look like this

iface eth0 inet dhcp
   up route add -net netmask gw metric 1

The indent is apparently not required but usually added for clarity.


the problem is, you have a class A ip local address, great you have an ip address but you have the default gateway as your broadcast address you might want to change that in dhcpcd by using

sudo nano /etc/dhcpcd.conf

then you type this next part

interface wlan0
static ip_address=192.168.x.xxx # the x's mean your own ip address
static routers=(your routers ip address)
static domain_name_servers=

i would recommend you use localhost( for you dns (if you have one)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.