Skip to content

Instantly share code, notes, and snippets.

@bmegli
Created March 17, 2024 13:18
Show Gist options
  • Save bmegli/44be43672cd4468b2274b73d194b3ba1 to your computer and use it in GitHub Desktop.
Save bmegli/44be43672cd4468b2274b73d194b3ba1 to your computer and use it in GitHub Desktop.
route traffic from A over B network interfaces to C

Scenario

# B has 2 network interaces, A reachable through one, C reachable through other
# We want A to C communiation (over B)
A----B----C

Ad-hoc solution

# on A 
ip route add C_SUBNET/24 via B_IP

# e.g. ip route add 192.168.1.0/24 via 192.168.0.B_ADDRESS
# on B
sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -s A_SUBNET/24 -j MASQUERADE

# e.g. sudo iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment