However, the route is not showing up in the routing table. Using this command works:
ip route add 10.111.226.0/23 dev wg0 proto static scope link
Any idea why it does not work with UCI? Already tried rebooting, using another interface (just to test it), another table, ... Looks like it randomly works sometimes, but doesn't most of the time. Also cannot find an error in the system log.
I doubt you want this for a Wireguard link. Remove it.
This is generally used for encapsulations where a "gateway" config would be the Layer 3 endpoint to reach that subnet (e.g. with IPENCAP/IP Protocol No. 4). In some, protocols it has another meaning. Obviously, such is not used in Wireguard and it should be omitted.
Before trying to manually add the static route, I checked what OpenWrt does when ticking the Route Allowed IPs box. The output of ip route list contains e.g.:
10.111.225.20 dev wg0 proto static scope link
I thought to have the scope link part in a static route, I would have to add option onlink '1'. So this is not what it is doing?
Anyway, I also tried adding the static route without option onlink '1', but the route still does not show up in the routing table. IPv6 static routes do work. Any ideas about this? Is this a known bug?
I got a similar issue when I tried to let an IP address bypass the default VPN routing rules.
The route add command did work, but the rules added in LuCI didn't, which is also equal to writing configurations in /etc/config/network.
The most wired thing was that the route command didn't show any rules in LuCI at all. It meant that the rules added in LuCI did not generate a corresponding rule for the routing table after I clicked Save & Apply. Then I checked the official document on setting up static routes, and I was sure there were no mistakes.
After many attempts of different option combinations, I finally found that it would work if I gave METRIC a whatever number. Although it is not a mandatory option, as long as I left METRIC blank, the rule would not show up in the routing table and, of course, won't work.
Luckily I found this trick, but I don't know why this happened. Or maybe it's a bug or something. I hope somebody can explain it to me.