I send all the traffic through a Wireguard VPN, but I need to setup an exception. Packets directed to my own public IP have to go through the default gateway of the system.
It works as intended if I add this to the kernel routes:
route add X.X.X.X gw 192.168.1.254
.
But, of course, here I'm hardcoding my router's gateway and it won't work if I'm connected to any other network. How can I generalize this behaviour so that I always send packets directed to X.X.X.X through the default gateway? Perhaps using iptables rather than adding kernel routes would be better?