Created
February 24, 2023 12:58
-
-
Save larrasket/619df25883923979c2581629d3cb93bf to your computer and use it in GitHub Desktop.
Toggle internet connection but keep network
This file contains 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 | |
# Check if the internet connection is currently active | |
ping -q -c 1 -W 1 google.com > /dev/null | |
if [ $? -eq 0 ] | |
then | |
# If the internet connection is active, turn it off by removing the default gateway | |
echo "Turning off internet connection" | |
sudo ip route del default | |
else | |
# If the internet connection is not active, turn it on by adding the default gateway | |
echo "Turning on internet connection" | |
sudo ip route add default via <gateway_ip> # replace <gateway_ip> with your default gateway IP address | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment