OPNsense Forum

Archive => 20.1 Legacy Series => Topic started by: Amr on May 30, 2020, 09:13:52 am

Title: Help with Scripting (change default gateway)
Post by: Amr on May 30, 2020, 09:13:52 am
Hello guys,
I'm trying to write a script to switch between gateways (the machine has only 1 wan interface) when one goes down by pinging a remote host, triggered by a cron-job.
my problem is I can't change the default gateway when I type
Code: [Select]
route delete default
Code: [Select]
route add default 192.168.1.1and checking the gateway by typing
Code: [Select]
netstat -nrIt shows that the changes were made but going to the GUI nothing changed and by reloading the interface my changes are overwritten.

Also, I'd like to know the variable that holds the current gateway value.
Title: Re: Help with Scripting (change default gateway)
Post by: hbc on May 30, 2020, 03:32:56 pm
Why don't you just add a second gateway with a lower priority? As soon as first fails, the second is used. No need for scripting.

https://docs.opnsense.org/manual/gateways.html
Title: Re: Help with Scripting (change default gateway)
Post by: Amr on June 02, 2020, 07:57:55 am
hello hbc,

Quote
Why don't you just add a second gateway with a lower priority?
Well I tried it once, but it didn't work so I assumed that the gateway group functionality is limited to multiple wan interfaces setup, and since I have only one wan interface (right now) I thought of scripting, If you can confirm that gateway groups work in single wan interface might give it a try.

thanks for your help.
Title: Re: Help with Scripting (change default gateway)
Post by: hbc on June 02, 2020, 08:24:31 am
I did not mention gateway groups. Just multiple gateways with different priorities. But gateway group should work, too.