Skip to content

Instantly share code, notes, and snippets.

@ilian
Last active December 19, 2021 18:49
Show Gist options
  • Save ilian/dec050b63070af5ff8b114e4d362c0c8 to your computer and use it in GitHub Desktop.
Save ilian/dec050b63070af5ff8b114e4d362c0c8 to your computer and use it in GitHub Desktop.
Notes on source-based routing

Our goal is to route a packet from a particular interface or source address range to the desired interface, even if that interface is not our default interface.

Source based routing with ip rule

We have virtual machines bridged to the virbr1 interface and we want to route trafic of these VMs to a virtual network that is accessible via tun0. Assuming default NAT routing has been set up for the VM instances, we can route the traffic as follows:

ip rule add dev virbr1 table 100
ip route add default dev tun0 table 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment