Skip to content

Instantly share code, notes, and snippets.

@Jxck-S
Created December 9, 2024 02:37
Show Gist options
  • Save Jxck-S/8a069fb37a08f6c501bc90721e9be49f to your computer and use it in GitHub Desktop.
Save Jxck-S/8a069fb37a08f6c501bc90721e9be49f to your computer and use it in GitHub Desktop.
IPv6 Toggle Script, Disables or enables IPv6 system-wide
#!/bin/bash
# IPv6 Toggle Script
# Disables or enables IPv6 system-wide
function disable_ipv6() {
echo "Disabling IPv6..."
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
echo "net.ipv6.conf.all.disable_ipv6=1" | sudo tee -a /etc/sysctl.conf > /dev/null
echo "net.ipv6.conf.default.disable_ipv6=1" | sudo tee -a /etc/sysctl.conf > /dev/null
echo "net.ipv6.conf.lo.disable_ipv6=1" | sudo tee -a /etc/sysctl.conf > /dev/null
sudo sysctl -p
echo "IPv6 has been disabled."
}
function enable_ipv6() {
echo "Enabling IPv6..."
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0
sudo sed -i '/net.ipv6.conf.*.disable_ipv6/d' /etc/sysctl.conf
sudo sysctl -p
echo "IPv6 has been enabled."
}
# Main Script Execution
echo "Do you want to enable or disable IPv6? (enable/disable)"
read -r action
case "$action" in
disable)
disable_ipv6
;;
enable)
enable_ipv6
;;
*)
echo "Invalid option. Please type 'enable' or 'disable'."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment