Skip to content

Instantly share code, notes, and snippets.

@johnskopis
Created March 18, 2014 21:36
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 johnskopis/9630266 to your computer and use it in GitHub Desktop.
Save johnskopis/9630266 to your computer and use it in GitHub Desktop.
#!/bin/bash
interfaces() {
ip addr list | egrep '^[0-9]' | awk '{print $2}' | sed -e "s/://g" | grep -v lo | sort -g
}
is_default() {
local int=$1
local default_int=$(ip route show | grep default | awk '{print $5}')
[ "x$int" == "x$default_int" ]
}
cfg_for() {
local int=$1
ifconfig $int | grep 'inet addr' | sed -e "s/[^0-9\. ]//g" | while read ip bcast netmask; do
cat << EOF
auto $int
iface $int inet static
address $ip
broadcast $bcast
netmask $netmask
EOF
if is_default $int; then
echo "gateway 74.201.193.1"
echo "dns-nameservers 172.29.11.26 172.29.11.25"
fi
done
}
loopback() {
cat << EOF
auto lo
iface lo inet loopback
EOF
}
routes() {
route -n | egrep -v '\b0\.0\.0\.0\b' | egrep '^[0-9]' | while read pfx gw netmask _; do
echo "post-up route add -net $pfx netmask $netmask gw $gw"
done
}
loopback
for i in $(interfaces); do
cfg_for $i
done
routes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment