what I want to achieve in the end: I have to internal networks int1 (192.168.64.0/24) and int2 (192.168.96.0/24). I have two upstream interfaces: wan (192.168.203.100) and one openvpn client interface with dynamic ips. The openvpn client interface is the default route, but int1 should routed over wan in the internet.
openvpn client works fine and the route from int2 via openvpn in the internet works fine. I don't want to use "PBR app" or "mwan3". I wan't to use PBR with netifd (https://openwrt.org/docs/guide-user/network/routing/pbr).
# ip route show table int1
192.168.64.0/24 dev br-lan.40 scope link
But the default route is missing! Also when I set up an extra static default route for this table in /etc/config/network it is not added to the table. There is no hint in the logs.
My only idea is: openwrt doesn't add the default route to this custom table, because there is the same default route in the main table:
# ip route show table main
...
default via 192.168.203.254 dev wan
...
Is this the problem? If so: How to solve? If not: Any other ideas?
Yes I know, but I think it's working fine, because I can ping through the tun0 interface (and the wan interface) and int2 is routed via openvpn in the internet.
int1 should be routed via wan (no openvpn) in the internet.
Well, it works for me and I reproduced this setup multiple times over the years including the latest stable OpenWrt release, so just try co carefully follow the instructions:
Thanks again. But also again: The routing of int2 via openvpn works fine!
The routing of int1 via wan is not working. wan is not a openvpn interface. It is normal ethernet.
Is there any option to debug openwrt? There must be a reason why openwrt doesn't use the config option gateway '192.168.203.254'. Adding this manually with ip route add default via 192.168.203.254 table int1 works! So the problem is that openwrt ignores for some reason the option gateway '192.168.203.254'.
Yes, I know this script. I don't want to use at the moment, because I don't want an extra table for every interface. But I used the script to check my setup.
I can understand that it would be much easier for you to say something about my problem if I would post this information. But I'm sorry. I can't do this. There is much to much information in the output to post to the internet.
Well two outputs are possible:
# ip -4 rule show
0: from all lookup local
10000: from 192.168.64.254 lookup int1
20000: from all to 192.168.64.254/24 lookup int1
32766: from all lookup main
32767: from all lookup default
90020: from all iif lo lookup int1
and
# grep -v -e "^#" -e "^$" /etc/iproute2/rt_tables
128 prelocal
255 local
254 main
253 default
0 unspec
1 int1
Please tell me what information you need from the other commands. I'll try to cut things together then.
Some more information: If I change this option to an address inside the 192.168.64.0/24 network, then the default route in the int1 table is created! I can't understand, why this route is created for (useless) default routes in 192.168.64.0/24 but not for useful routes to an upstream interface.
Yes, of course I know that if I configure a linux network interface the gateway has to be on the same subnet. (Otherwise the machine don't know where to send packages by default.) But (at least for me) it is completely unclear what openwrt does with the configuration parameters from /etc/config/network.
Ok, I deleted option ip4table 'int1' in the interface definition (see my first post), because this leads only to:
# ip rule show
0: from all lookup local
10000: from 192.168.64.254 lookup int1
20000: from all to 192.168.64.254/24 lookup int1
32766: from all lookup main
32767: from all lookup default
90014: from all iif lo lookup int1
So int1 is only looked up if there is a packet from 192.168.64.254 (openwrt itself) but not from 192.168.64.0/24. Instead I created rule:
This works so far, but now only the routes from table int1 are used! Not from main! I need the other routes from main and only the default route should be used from the table int1 for the packets arriving from int1.
To explain a little bit more: I have set up a routing from int2 to int1 via the Firewall-Web-Gui. This works fine without the rule from my last post. But with this rule enabled this doesn't work anymore. Because of this I think that only the table for int1 is read and not the main table anymore.
This is what I have been trying to explain to you from the very beginning and what the PBR extras script is designed to solve.
To allow using the main table, lower the priority of the custom routing rules to about 40000 and assign each upstream interface including the VPN to own separate tables.