Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[Solved] Persistent routes in interfaces file

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
bakerjw
Posts: 9
Joined: 2022-05-10 18:55
Has thanked: 2 times
Been thanked: 1 time

[Solved] Persistent routes in interfaces file

#1 Post by bakerjw »

Good day, all. I have been around Linux off and on for many years but would still consider myself a newbie. I have been poking around and have not been able to find anything that works for this.
I have a Debian core loaded on a VM that resides on 2 different networks.
Network 1 is the primary network (ens192) and is on a firewalled segment of our corporate network that is routed to corporate assets.
Network 2 is a network that is connected to multiple test networks that we use for testing purposes using public IP ranges. i.e. 10.0.x.x, 172.16.x.x, 192.168.x.x etc... There is routing between all of these subnets.

This Debian installation serves as an SMTP gateway to our secure corporate SMTP servers and works well from devices attached to the Network 1 and Network 2 subnets. For test subnets, I am needing to add route tables to the Debian machine.

Network 2 is on a 192.168.0.0/20 supernet and the Debian address is 192.168.0.6.
Normally, I cannot ping 192.168.16.32 as ICMP response packets the sent out the network 1 - the default.
If I enter ip route add 192.168.16.0/24 via 192.168.0.1
I can then ping a device at 192.168.16.32
Great. But it is static and I need it to be persistent.

I am editing /etc/network/interfaces as shown here. I blocked the corporate IP address with ###.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto ens192
iface ens192 inet static
address ###.###.133.31/24
gateway ###.###.133.1
dns-nameservers ###.###.133.18 ###.###.133.19

# The secondary network interface
auto ens224
iface ens224 inet static
address 192.168.0.6/20
gateway 192.168.0.1

#This has not worked to add a persistent route.
up ip route add 192.168.16.0/24 via 192.168.0.1



I am not sure of what I am missing.
Should the route be deleted from ens192?
Last edited by bakerjw on 2022-07-22 13:16, edited 1 time in total.

User avatar
fabien
Forum Helper
Forum Helper
Posts: 621
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 146 times

Re: Persistent routes in interfaces file

#2 Post by fabien »

I think you want this: https://www.cyberciti.biz/faq/ip-route- ... explained/
(/etc/network/interfaces snippet at the end)

bakerjw
Posts: 9
Joined: 2022-05-10 18:55
Has thanked: 2 times
Been thanked: 1 time

Re: Persistent routes in interfaces file

#3 Post by bakerjw »

Thank you for the link. There is a section entitled A note about ip command and persistence static routing on a Debian/Ubuntu
It references editing /etc/network/interfaces which is what I've been doing.

With this interfaces file, systemctl restart networking.service completes without errors.
# This file describes the network interfaces available on your system and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto ens192
iface ens192 inet static
address ###.218.133.31/24
gateway ###.218.133.1
dns-nameservers ###.218.133.18 ###.218.133.19

# The secondary network interface
# A Supernet with a subnet mask of 255.255.240.0
auto ens224
iface ens224 inet static
address 192.168.0.6/20


One thing to note, there can be only 1 gateway. Having a gateway for both interfaces produces an error.

Under the ens224 part, I've tried adding different combinations such as

down ip del route 192.168.16.0/24 via 192.168.0.1 dev ens224
up ip add route 192.168.16.0/24 via 192.168.0.1 dev ens224

and

down ip del route 192.168.16.0/24 via 192.168.0.6 dev ens224
up ip add route 192.168.16.0/24 via 192.168.0.6 dev ens224

and they both cause the interface to not come up properly. I'm at a loss.
Last edited by bakerjw on 2022-07-22 13:16, edited 1 time in total.

bakerjw
Posts: 9
Joined: 2022-05-10 18:55
Has thanked: 2 times
Been thanked: 1 time

Re: Persistent routes in interfaces file

#4 Post by bakerjw »

Alrighty... Here is the deal.

What does NOT work...
# The secondary network interface
auto ens224
iface ens224 inet static
address 192.168.0.6/20
up ip route add 192.168.16.0/24 via 192.168.0.1

What does work
# The secondary network interface
auto ens224
iface ens224 inet static
address 192.168.0.6/20
post-up ip route add 192.168.16.0/24 via 192.168.0.1

ip route now shows persistent routes after a reboot.

Post Reply