OpenBSD route via different gateways which have same IP but on different interfaces
Solution 1:
Use the -ifp modifier to route. From the man page:
In a change or add command where the destination and gateway are not
sufficient to specify the route, the -ifp or -ifa modifiers may be
used to determine the interface name or interface address.
So something like this works:
# for arg in tun0 tun1 tun2; do ifconfig $arg 192.168.11.1/24; done
# route add 10/8 -iface 192.168.11.1 -ifp tun0
add net 10/8: gateway 192.168.11.1
# route add 172.16/12 -iface 192.168.11.1 -ifp tun1
add net 172.16/12: gateway 192.168.11.1
# route add 192.168.254/24 -iface 192.168.11.1 -ifp tun2
add net 192.168.254/24: gateway 192.168.11.1
# route show -inet
Routing tables
Internet:
Destination Gateway Flags Refs Use Mtu Prio
Iface
10/8 192.168.11.1 GS 0 0 - 8 tun0
localhost localhost UHl 0 22 32768 1 lo0
172.16/12 192.168.11.1 S 0 0 - 8 tun1
192.168.11.1 192.168.11.1 UHhl 1 4 - 1 tun0
[...my real routes omitted...]
192.168.254/24 192.168.11.1 S 0 0 - 8 tun2
If your destination routes are overlapping then you can use pf and route labels to match, or routing domains.