Skip to content

Instantly share code, notes, and snippets.

@sbliven
Created January 27, 2021 21:12
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 sbliven/5e546a248455e2f5e150202988ac9107 to your computer and use it in GitHub Desktop.
Save sbliven/5e546a248455e2f5e150202988ac9107 to your computer and use it in GitHub Desktop.
Restart the network (Ubuntu 20.04)
#!/bin/bash
# Restart the network
# usage: sudo restartnet [iface]
# Requires root
# Guess interface for outgoing traffic
TARGET=8.8.8.8 # known IP. Could also be 192.168.0.1 or similar for local networks
function guess_iface {
ip route get $TARGET | grep -Po '(?<=dev\s)\w+' | cut -f1 -d ' '
}
IFACE="${1:-$(guess_iface)}"
echo "Restarting $IFACE"
ifconfig "$IFACE" down
ifconfig "$IFACE" up
@sbliven
Copy link
Author

sbliven commented Jan 27, 2021

Sometimes after restarting my server uses the ISP's DNS server rather than its own internal bind9 service. This fixes it sometimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment