Skip to content

Instantly share code, notes, and snippets.

@zaz
Created July 12, 2014 16:12
Show Gist options
  • Save zaz/2fb379f713c08677ec8c to your computer and use it in GitHub Desktop.
Save zaz/2fb379f713c08677ec8c to your computer and use it in GitHub Desktop.
Connect to a router by its MAC address (static IP).
#!/bin/bash
DEV="eth0"
ROUTER="192.168.0.1"
MAC="${1:-01:23:45:67:89:ab}"
IP="192.168.0.5/24"
if [[ "${UID}" != 0 ]]; then
exec sudo "$0" $@
fi
echo -n "Stopping NetworkManager: "
stop network-manager
echo "Bringing up interface '$DEV'"
ip link set "$DEV" up
echo "Setting IP address to $IP"
ip addr add "$IP" dev "$DEV"
echo "Adding ARP entry: $ROUTER -> $MAC"
ip neigh add "$ROUTER" lladdr "$MAC" dev "$DEV"
echo "Adding default route via $ROUTER"
ip route add default via "$ROUTER"
echo "Adding Google nameservers (8.8.8.8 and 8.8.4.4)"
echo "nameserver 8.8.8.8
nameserver 8.8.4.4" > /etc/resolv.conf
echo "Testing internet by pinging Google:"
ping google.com -I "$DEV" -c 6 -i 0.2 -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment