Created
January 27, 2021 21:12
-
-
Save sbliven/5e546a248455e2f5e150202988ac9107 to your computer and use it in GitHub Desktop.
Restart the network (Ubuntu 20.04)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes after restarting my server uses the ISP's DNS server rather than its own internal bind9 service. This fixes it sometimes.