Display gateway for an interface

the ISP decides the addresses of their gateways. your machine finds this out by some mechanism, typically DHCP, or ipv6 router advertisements. Without information coming via DHCP or ipv6 RA, there is no way to know what the upstream gateway is. That's literally why DHCP was invented, to distribute this information without an administrator having to come and type in the data to the configuration file or dialog box...

So, you want to know what did DHCP tell your computer/router, but that information is not necessarily stored anywhere in the general case. I mean, the usual thing is DHCP happens and the information just gets shoved into the routing table... but there's typically just one default route in the routing table, so as soon as you activate say the wifi interface, it will overwrite the default route, so you don't remember the old one from the ethernet for example. That's why I suggested typing "ip route show"

openwrt stores info like this wherever ifstatus is getting it from, some database. But it's not in general stored by other operating systems.

2 Likes

Wait, no. I have my own static IPs. I'm only wanting to change routes to the local routers. The ISP is not in play at all in this. The routes I am changing are between my own local routes, not the ISP. The DHCP IPs are being handed out by my own local devices.

1 Like

Aha! Now we're getting somewhere!

Evidently you want to manually change the route on your device to route to another device you control, but you don't remember the IP addresses of your routers, so you want to find out what they are in some automatic way. Is that about it?

I'm assuming you have DHCP running on the device, why wouldn't you just take down the interface you don't want to use as your upstream, and restart the interface you do want to use? This would cause DHCP to go get the gateway and install it in the routing table.

The way to "find out what the upstream router IP is" is in fact DHCP.

1 Like

Close but we're past the first part. The info given earlier in this post told me how to get the gw IP so that is no longer the part I'm not clear about.

The only part I don't understand is how to make the wired connection default IF the wifi AP becomes unavailable.

Meaning, I want to manually change the route on the router so lets say to wireless.
Once it is using wifi, I'd like the router to keep using that as its default route until I either manually change it back to the wired route OR if wifi is not accessible for some reason.

You're talking about dynamic routing basically. I think OSPF is the way forward. To choose the route manually, you'd change the "weight" on the connection you want to prefer. Then it would become the route, unless it went down, in which case you'd fall back to the other route.

1 Like

Yes, that's exactly what I'm asking about, thank you. I'll do some searching to see if I can find some examples to help me learn how to set this up.

Don't look too far.

LOL, yes, I was looking at that but need to better understand it a little so I can implement it :).

The wired interface on the test router I'm using is br-wan and the wireless is wlan0. I'd like to test this so that I don't go locking myself out since I've never done it before.

I certainly appreciate all of the help and leads I've been given.

Hi,

I've been messing with this metric thing since I read the last comment. As I am understanding things, the metric is not doing what I am looking for. Metric does not do any sort of fail nor does changing the route survive a reboot. I've spent countless hours reading and trying and nothing seems to survive reboots and would fail over.

Having said that, I know it can be done because I keep reading about it so there are some things I am just not finding or understanding.

Changing the metric to a lower number causes the route to be preferred. Think of the "metric" as synonym for "cost" and the kernel is trying to minimize cost of sending a packet.

Anything you do at the command line with "ip" isn't going to survive a reboot... But it's kind of wishy washy whether you want this to be a temporary thing or not...NOTHING is going to failover unless you have some active process monitoring it and doing something about it... So that's basically MWAN3 but you seem to not want to use that... It's hard to give you help without knowing what you really want, especially if you refuse to use the tools that are built to do exactly what it sounds like you want (MWAN3)...

Maybe fail over is the wrong term. I mean on boot. If the wireless is up, the router should use the wireless route if it's been told to do so. If the wireless is not there, it should use the wired route.

Mainly, this is a sort of fall back since the router doesn't have a GUI to change anything so just want to make sure it doesn't hang and can be accessed.

In this case it should be enough to assign different metrics.

I tried that but it always defaults back to wired. I'm missing something. I'll give it another try.

config interface 'wan'
option metric '20'

config interface 'wwan'
option metric '10'

LOL, all this time, all these tests and I was doing only one small thing wrong.
I had the metric weights backwards. I used high for priority rather than low.

Works perfectly. I knew this should be simple :).

Thanks very much for responding and helping. I hope I can help someone else knowing this now.

1 Like

So, what exactly is the behavior now? I assume if the wifi is there at boot, it comes up and uses it... if the wifi is there at boot and it goes away... what happens? does the kernel figure out that it needs to use the other route? I would think if the interface itself goes down, then yes... but if the router just disappears while the wifi network link remains... it will hang. So for example if the router you connect to via wifi itself loses its uplink, you'll still hang.

In the test I ran, setting wifi to lower metric causes wifi to come up.
Changing wifi to disable and rebooting again causes wired to become default.

Exactly what I needed assuming the same thing happens even if I don't edit the wireless to be disabled but the wifi AP goes away.

I edited the wireless file and purposely put a typo in the SSID.
The router rebooted and eventually used the wired interface since it could not connect to wifi.

Perfect.

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