Skip to content

Instantly share code, notes, and snippets.

@bsmithyman
Last active August 29, 2015 14:07
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 bsmithyman/16b1da27445df54e76da to your computer and use it in GitHub Desktop.
Save bsmithyman/16b1da27445df54e76da to your computer and use it in GitHub Desktop.
Dictate a routing table for a hostname on the network
#!/bin/bash
HOST=$1
TABLE=$2
IP=$(getent hosts $HOST | cut -d \ -f 1)
CURRENT=$(ip rule | grep $IP | cut -d \ -f 4)
PRIORITY=1000
if [ $CURRENT ]; then
echo Resetting rule for $HOST with IP $IP
ip rule del from $IP
fi
if [ $TABLE ]; then
echo Setting rule for $HOST with IP $IP to table $TABLE
ip rule add from $IP table $TABLE prio $PRIORITY
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment