Last active
August 29, 2015 14:07
-
-
Save bsmithyman/16b1da27445df54e76da to your computer and use it in GitHub Desktop.
Dictate a routing table for a hostname on the network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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