What is 'IPv4 gateway' for in 'Interfaces >> interface_name'?

As per the title, in Luci, what is the IPv4 gateway textbox for on the modal for an Interface?

For clarity, suppose I have an interface called LAN

When I visit Network > Interfaces in Luci, if I click the Edit button next to the interface called LAN, a modal pops up with the title Interfaces >> LAN
In that modal, between IPv4 netmask and IPv4 broadcast, is a textbox for IPv4 gateway.
By default, it is populated with the default gateway, but it appears that I could specify a different gateway here.

I have 2 gateways, 1 from my ISP and 1 which is a VPN.
In a previous question on the forum, I asked how to have all traffic from 1 internal subnet go out over the VPN gateway and was instructed on the use of static routes and a table. This solution works. However, it would appear to me that I should just be able to specify the VPN gateway in the textbox I described above and that interface would then use the VPN as its gateway. I would not therefore need the static route rule. If this is incorrect, what is the IPv4 gateway textbox for?

It is for default route. Empty means we are the default route and give our IP via DHCP. If filled that address is fed to DHCP and used to reach internet.

So that would be for an upstream gateway on a different device?

It doesn't work that way. If you don't set up conditional routing (pbr or manually declared rules and tables), there is only one routing table in the kernel. That table applies to all networks, and only one default route (gateway) can be active in it. So you should leave all the Gateway boxes blank except possibly for one, and that will be in the network that leads to the Internet. If the wan is configured by DHCP or pppoe the default route will be automatically installed, though you can tell it not to.

Thank you for this explanation!

So by default, OpenWrt has 1 routing table and therefore 1 gateway.

Adding a VPN (or second WAN link via 5G for example) doesn't add a new routing table and gateway, so it must be done manually in Network > Routing, by creating a new table.

The textbox I asked about therefore, is for telling DHCP clients to use an upstream gateway, rather than this device.

What would be the downside of automatically creating a routing table when adding a new route? If that was the case, couldn't the IPv4 gateway textbox be used to configure that interface to use the newly added gateway? It could become a dropdown option for possible routes, rather than the textbox?

Any valid IP on that subnet could be the gateway. Why would a drop down be a good idea?

When you create the new route, be it a VPN, different router somewhere else, or 4/5G for example, that new interface will have a gateway address (allocated by the provider for example). These addresses could be used to populate the dropdown.
As in other areas of Luci, e.g. the Device dropdown on an Interface modal, you would be free to enter an IP of your choosing as well.

So, I have for example

WAN 1.2.3.4 (allocated by ISP)
VPN 2.2.3.4 (allocated by VPN provider)
LTE 4.3.2.1 (allocated by cellular provider)

When each of these routes is created, a routing table is also created.
But the IPv4 gateway textbox on each Interface, is now a dropdown with WAN, VPN and LTE as options and another free textbox for entering a custom gateway address. Selecting LTE, WAN or VPN would result in that interface using that gateway from then on.

That is not gateway for LAN network.

1 Like

Why would the interface list invalid gateways (of other interfaces) in a dropdown?

Are you describing some kind of Feature Request?

Wait till he hears about IPv6 and slaac and that you can have multiple routers per network segment... And boom goes the easy solution.

1 Like

@brada4
I don't understand. Why is that option there on a LAN interface then?

@lleachii
There are WAN interfaces and LAN interfaces.
My proposal is that, when a new WAN interface is created, a routing table for that new gateway is also created.
Subsequently, the new WAN interface's gateway address is available to any of the LAN interfaces as a gateway.

So, we have interfaces that lead to other network and interfaces that lead to our internal devices; this would be a simple way of plumbing them?

I suppose this could be a Feature Request. I was checking its feasibility and rationality.

You do realise this project is deployed on a lot of ISP provided common or garden routers in a domestic environment right?

I fear you believe in the former, while missing that you're making little sense in the latter.

Because it's a router. In some environments, it makes sense (e.g. you have another roued network connected to the LAN interface). You confuse "WAN" and "gateway" to be synonymous - they're not.

You missed his point about routers and gateways.

I suspect you may be right :rofl:

Perhaps a better proposal is that we create a bootstrap skin for Luci that hides a lot of stuff that is completely irrelevant in a (edit: the majority of?) home environment(s) and improve the tooltips for options that remain.

And of course, that I learn more!

DHCP server advertising an IP other than this router to be the gateway is done with a DHCP option, not that gateway box.

1 Like

Thanks to IANA we have 3 dedicated ipv4 networks used for documentation. See https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml

And nowadays we have 2 for IPv6 x see here https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml

It was also pointed out that a gateway however how many they are in a subnet musst be part of that subnet to be a gateway for that subnet. This is one of the fundamental results of OSI and how we do interpret and follow it.

If you are bored and want to learn more I can recommend this free and public book https://book.systemsapproach.org/

2 Likes

Thanks for the reply.

In the IPv4 gateway textbox that is the subject of my original question, it has the pre-populated value of a public IP address which is most certainly not in the same subnet as the interface, so I don't know how to interpret your statement?

Then don't listen to the GUI and think for yourself. No computer is yet able to read your or another users mind. OpenWrt can not make a prediction what the user maybe has in mind or what its intentions are. I don't know the Lua code of Luci because I have never used it.
You can however use under certain circumstances use "recursive routing", which means the nexthop for a route is not directly reachable but you have a route in your table for that nexthop. Maybe the GUI is just flexible enough to support such usecases. I'm only know this from routing daemons but most of the time people say stay away from such features and just do proper network designs.

Actually, it's greyed-out and shows the gateway obtained by DHCP, whichis generally WAN.

Hence, no need to enter.

I understand your concern and perhaps there's a better way, but all IP-based Ethernet connections have the IP and gateway configuration available for entering. You'll see this generally on all networking equipment ans OSes. OpenWrt isn't an exception in that regard.

1 Like