Skip to content

Instantly share code, notes, and snippets.

@samos123
Created April 3, 2014 02:07
Show Gist options
  • Save samos123/9947072 to your computer and use it in GitHub Desktop.
Save samos123/9947072 to your computer and use it in GitHub Desktop.
Playing around with bash, at the university I have to manually set my internet configuration on a specific network. Thought let's automate it
#!/bin/bash
set -xi
sudo ip addr add 172.16.4.99/22 dev eth0
GATEWAY=$(ip route show | grep default | awk '{ print $3}')
echo "Current default gateway: $GATEWAY"
if [ -z $GATEWAY ]
then
sudo ip route del default $GATEWAY
fi
sudo ip route add default via 172.16.4.1
echo "nameserver 166.111.8.28" | sudo tee -a /etc/resolv.conf
echo "Done.."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment