Skip to content

Instantly share code, notes, and snippets.

@kntyskw
Created April 16, 2013 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kntyskw/5394696 to your computer and use it in GitHub Desktop.
Save kntyskw/5394696 to your computer and use it in GitHub Desktop.
Add a routing table and iptables rule to route specified packets via LVS
#!/bin/sh
LVS_IP=172.31.24.1
TABLE=1
ip route flush table $TABLE
ip route show | grep -Ev ^default | while read ROUTE; do
ip route add table $TABLE $ROUTE
done
ip route add table $TABLE default via $LVS_IP
ip rule del from all fwmark 1
ip rule add fwmark 1 lookup $TABLE
iptables -F -t mangle
iptables -A OUTPUT -t mangle -p tcp --sport 80 -j MARK --set-mark 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment