Skip to content

Instantly share code, notes, and snippets.

@chuckg
Created March 31, 2015 18:59
Show Gist options
  • Save chuckg/c2c18a9177e4ec70803c to your computer and use it in GitHub Desktop.
Save chuckg/c2c18a9177e4ec70803c to your computer and use it in GitHub Desktop.
Unfuck your Mac's networking after using VPN, changing WIFI, etc.
#!/bin/bash
sudo networksetup -setv4off Wi-Fi
sleep 1
sudo networksetup -setv6off Wi-Fi
sleep 1
sudo networksetup -setdhcp Wi-Fi
sleep 1
sudo networksetup -setv6automatic Wi-Fi
sleep 1
# Clear DNS
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist
sleep 1
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist
#!/bin/sh
IFS=$'\n'
for i in `networksetup -listallhardwareports | awk -F": " '/Hardware Port/ { print $2 }'`; do
echo "Fix $i"
networksetup -setv4off $i > /dev/null 2>&1
if [ "$?" = "0" ]; then
sleep 1
networksetup -setdhcp $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment