Skip to content

Instantly share code, notes, and snippets.

@scalp42
Forked from j3tm0t0/add_policy_route.sh
Created March 19, 2014 22:57
Show Gist options
  • Select an option

  • Save scalp42/9653236 to your computer and use it in GitHub Desktop.

Select an option

Save scalp42/9653236 to your computer and use it in GitHub Desktop.
#!/bin/sh
perl -v > /dev/null || exit 1
m()
{
curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$1
}
for mac in `m`
do
dev=`m $mac/device-number`
subnet=`m $mac/subnet-ipv4-cidr-block`
gw=`echo $subnet | perl -pe 's#/.+##; @ip=split(/\./); $ip[3]++ ; $_=join(".",@ip)'`
ip route flush table 100$dev
ip route add table 100$dev to $subnet dev eth$dev
ip route add table 100$dev to default via $gw dev eth$dev
ip rule add from $subnet table 100$dev priority 100$dev
done
ip route flush cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment