Linux Lite Forums

Hardware - Support => Network => Topic started by: arun jayapal on April 04, 2020, 11:30:18 AM

Title: How to persist changes to the routing table?
Post by: arun jayapal on April 04, 2020, 11:30:18 AM
I am running linux lite 4.6 inside virtualbox. The machine has two network interfaces. I face the issue where the machine isn't able to connect to the internet. After investigation I found the issue to be with my routing table. No idea why this routing table got persisted in the first place.

Code: [Select]
$ ip route
default via 192.168.175.1 dev enp0s8 onlink
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
192.168.175.0/24 dev enp0s8 proto kernel scope link src 192.168.175.18

After a bit of tinkering, I have a workaround. I modify the routing table as follows:

Code: [Select]
$ ip route
default via 10.0.2.2 dev enp0s3
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
10.0.2.2 via 10.0.2.15 dev enp0s3
192.168.175.0/24 dev enp0s8 proto kernel scope link src 192.168.175.18

I am not sure why the above works.

However, I have to manually issue commands to setup the routing table to the state as shown above, after every reboot.

I have tried some ways to persist using the /etc/network/interfaces file. The below file is an attempt at that:

Code: [Select]
auto lo
iface lo inet loopback

auto enp0s3
iface enp0s3 inet dhcp

up /sbin/ip route add 10.0.2.2 via 10.0.2.15
up /sbin/ip route add default via 10.0.2.2

auto enp0s8
iface enp0s8 inet static
address 192.168.175.18
netmask 255.255.255.0
gateway 192.168.175.1

down /sbin/ip route del default

# up /sbin/ip route add 10.0.2.2 via 10.0.2.15
# down /sbin/ip route del default
# up /sbin/ip route add default via 10.0.2.2


But nothing worked.

Next I tried putting the commands in /etc/rc.local that didn't work too.

What is the correct way to persist this?
Title: Re: How to persist changes to the routing table?
Post by: supergamer on April 04, 2020, 08:49:35 PM
I am not familiar with crontab but you can setup a cronjob to start at every reboot. How to get exactly what you need is you will have to create a script then just put the script somewhere like in the /usr/scripts folder and use a sudo crontab -e to run the script with @reboot then path to your script. Just an off the wall suggestion.
Title: Re: How to persist changes to the routing table?
Post by: arun jayapal on April 17, 2020, 12:15:09 PM
Sounds great. However, if there were errors in the script, how can I know what it was...?
Title: Re: How to persist changes to the routing table?
Post by: supergamer on April 17, 2020, 06:29:52 PM
Make the script, test the script out after a reboot by using the terminal to execute it then see if it works. Always test first before blindly doing anything that is automatic. If there are errors you should see the errors and if it worked or not.