Temporarily switch route/gateway from CLI

How can I switch the default route from the command line so that when the router restarts, it goes back to the wired interface as the default.

Router starts, default route is always wired Ethernet.
Enable wifi from command line.
Switch the route from wired gateway to wifi gateway.

Can it be done in a temporary way so that the default if I lose access would be to restart the router and have it use wired again. Or maybe I can set the default in rc.local?

# ip route help
ip route { add | del | change | append | replace } ROUTE

opposite of temporary... avoid

Thanks for the input, unfortunately, the very short replies don't explain things so that I can understand.

For example, my default route/gateway when wired is interface br-wan
Once I activate the wifi, its gateway is on interface wlan0.

Now I can change the default route using;

ip route change default via dev wlan0
And, if I wanted to change it back to wired,
ip route change default via dev br-wan

First, is this correct above?

Second, you said avoid rc.local. I think I read that there is an option I could put into the 'network' file which would make one of the interfaces the default on reboot.
However, I've yet to find such an option.

I'm asking for clarification so that I can understand rather than just trying things and not really learning how this works.

i'd suggest you add a hotplug condition matching your wireless interface up with two more specific routes, for example...;

ip route add via wlanNUM
ip route add via wlanNUM

Thanks for all the help. I'm using a simple bash script to switch between routes now.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.