setting a static route

Kernels & Hardware, configuring network, installing services

setting a static route

Postby morgon » 2021-01-21 23:33

Hi,

I am running testing and would like to configure a static route that should always be available.

Currrently I have this in my /etc/network/interfaces:

Code: Select all
iface enp2s0 inet dhcp
      dns-nameserver 8.8.8.8
      up ip route add 10.10.10.0/24 via 192.168.0.10
      down ip route del 10.10.10.0/24 via 192.168.0.10


And this sets the route when I bring the interface up, however (for reasons that are beyond me) the routing table does not seem to survive a hibernation...

So do I need an extra script that is triggered when I resume from hibernation or how to do properly set such a route that should not be destroyed by hibernation?

Many thanks!
morgon
 
Posts: 189
Joined: 2010-08-28 03:04

Re: setting a static route

Postby Head_on_a_Stick » 2021-01-23 09:41

Try this script at /lib/systemd/system-sleep/fix-routes:
Code: Select all
#!/bin/sh
case "$1" in
   post) /sbin/ifup enp2s0;;
esac

For more on this see systemd-sleep(8).

But this is _very_ hacky and I don't really understand what you are trying to achieve with your routing.

How are you suspending the system? I would try systemd-networkd instead of ifupdown to see if that behaves any better.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 13262
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: setting a static route

Postby morgon » 2021-01-24 02:49

I suspend with "systemctl hibernate" and I am baffled that the routing tables are gone when I resume.

However the interface is up when I resume so I guess in a systemd-script I simply have to set the route again - it's easy enough to do but I was just wondering if you really need this...

As to what I am trying to achieve:

I used to have a router at 10.10.10.10 (handing out 10.10.10.x ips via dhcp). This little box is my own I run some services on it, all my mobile devices connect to it.

Then I got internet via cable and my provider handed me a cable-modem that is not my own. I cannot change the network it uses - it's 192.168.0.x.

My PC is connected via an ethernet-cable to the cable-modem because this way I get the fastest speed - but I also what to access all the devices that connect to my box from my pc.

So I connected the my own box to the cable-modem with an ethernet-cable (it's 192.168.0.10).

So if I want to access one of my mobile devices (connecting to my box) from my pc I need to set this route.
morgon
 
Posts: 189
Joined: 2010-08-28 03:04

Re: setting a static route

Postby shep » 2021-01-24 14:16

The Debian Network Configuration wiki uses different syntax:

https://wiki.debian.org/NetworkConfigur ... e_manually

It also uses /etc/resolv.conf for nameserver setup

https://wiki.debian.org/NetworkConfigur ... ameservers
shep
 
Posts: 407
Joined: 2011-03-15 15:22

Re: setting a static route

Postby Head_on_a_Stick » 2021-01-26 15:30

@OP: can you provide an ASCII diagram of your network layout? It might just be me being a bit thick but I can't quite grasp what you're describing.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 13262
Joined: 2014-06-01 17:46
Location: /dev/chair


Return to System configuration

Who is online

Users browsing this forum: No registered users and 12 guests

fashionable