inspire1
Posts: 16
Joined: Thu Feb 12, 2015 8:47 pm

Add an addition persistent route on eth0

Tue Jul 03, 2018 5:47 pm

Hi All

Hi have a pi server running on my lan which also runs a hotspot on the wlan. Lan address is dynamically assigned but has.a reservation on the dhcp server so always has the same address. All this works fine, but I need to access clients in the VPN subnet as I have a Pi-camera at a remote sited want to grab some images to this server for the web page it hosts.

My eth0 is in a private range 10.x.y.0/23 and always has the address 10.x.y.15 the default gateway is obviously 10.x.y.1 and the VPN server sits at 10.x.y.7 and is running TUN mode so issues clients with addresses in the range 10.x.z.0//24. From the client end all is good as the connection sets up routing to access the local lan and the internet via the local gateway. The issue comes with accessing those clients from the home network.

On a PC or I would just say 'route add -p 10.x.z.0/24 10.x.z.7' and on my Mac I use something similar although it is much harder to make it persistent. I cannot get this to work with my Pi server though. The above command (minus the -p) yields and error "route: netmask 000000ff doesn't make sense with host route"

I have tried adding a route command to dhcpcd.conf in a section called interface eth0 but as that interface is assigned dynamically I don't think it is read.

I would be happy to find a simple command line solution as I can script it to run when I want.

epoch1970
Posts: 3873
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Add an addition persistent route on eth0

Tue Jul 03, 2018 6:38 pm

The Arch documentation shows how to:
- set a static route from dhcpcd
- use the "ip" command to specify your route ("route", "ifconfig", "brctl" etc are deprecated)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
topguy
Posts: 5951
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Add an addition persistent route on eth0

Tue Jul 03, 2018 6:45 pm

'route add -p 10.x.z.0/24 10.x.z.7'
Would have been so much simpler to read if you actually used numbers.
The error here is that the VPN is 10.x.y.7 and not 10.x.z.7 but most likely a slip of your finger when writing this post.

This is me adding a route to network 192.168.0.0 from my pi on 192.168.10.103

Code: Select all

[email protected]:~ $ ip route list
default via 192.168.10.1 dev wlan0 src 192.168.10.103 metric 303 
192.168.10.0/24 dev wlan0 proto kernel scope link src 192.168.10.103 metric 303 

[email protected]:~ $ sudo ip route add 192.168.0.0/24 via 192.168.10.98 dev wlan0

[email protected]:~ $ ip route list
default via 192.168.10.1 dev wlan0 src 192.168.10.103 metric 303 
192.168.0.0/24 via 192.168.10.98 dev wlan0 
192.168.10.0/24 dev wlan0 proto kernel scope link src 192.168.10.103 metric 303

User avatar
topguy
Posts: 5951
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Add an addition persistent route on eth0

Tue Jul 03, 2018 6:51 pm

The Arch documentation shows how to:
Its actually uncanny how often googling for something asked for in the Pi forums leads you to the Arch Linux Wiki.

epoch1970
Posts: 3873
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Add an addition persistent route on eth0

Tue Jul 03, 2018 6:58 pm

topguy wrote:
Tue Jul 03, 2018 6:51 pm
The Arch documentation shows how to:
Its actually uncanny how often googling for something asked for in the Pi forums leads you to the Arch Linux Wiki.
Unfortunately it also leads to a ton of ill-informed or obsolete howtos... But with Arch you rarely can go wrong.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

hlev80
Posts: 4
Joined: Thu Oct 12, 2017 9:21 pm

Re: Add an addition persistent route on eth0

Tue Jul 03, 2018 8:38 pm

topguy wrote:
Tue Jul 03, 2018 6:45 pm

Code: Select all

[email protected]:~ $ sudo ip route add 192.168.0.0/24 via 192.168.10.98 dev wlan0
[email protected]:~ $ ip route list
default via 192.168.10.1 dev wlan0 src 192.168.10.103 metric 303 
192.168.0.0/24 via 192.168.10.98 dev wlan0 
192.168.10.0/24 dev wlan0 proto kernel scope link src 192.168.10.103 metric 303
It is good practice to add a protocol as well to arbitrary routes you introduce by hand or with a script. Just in case a routing daemon kicks in later and purges them leaving you puzzled why they are gone.

Code: Select all

[email protected]:~ $ sudo ip route add 192.168.0.0/24 via 192.168.10.98 dev wlan0 proto static
From the ip-route(8) man page:
protocol RTPROTO
the routing protocol identifier of this route. RTPROTO may be a number or a string from the file
/etc/iproute2/rt_protos. If the routing protocol ID is not given, ip assumes protocol boot (i.e. it
assumes the route was added by someone who doesn't understand what they are doing).
Several protocol val‐
ues have a fixed interpretation. Namely:

redirect - the route was installed due to an ICMP redirect.

kernel - the route was installed by the kernel during autoconfiguration.

boot - the route was installed during the bootup sequence. If a routing daemon starts, it will
purge all of them.

static - the route was installed by the administrator to override dynamic routing. Routing daemon
will respect them and, probably, even advertise them to its peers.

ra - the route was installed by Router Discovery protocol.

The rest of the values are not reserved and the administrator is free to assign (or not to assign) proto‐
col tags.

inspire1
Posts: 16
Joined: Thu Feb 12, 2015 8:47 pm

Re: Add an addition persistent route on eth0

Wed Jul 04, 2018 8:45 am

Thanks for all the replies. Seems all I was missing was the IP command rather than going straight for route.seems to be working fine.

Return to “Advanced users”