A script to disable IPv6 on your Linux machine
Simply create a file using the following command:
sudo nano ipv6_disable.sh
Copy and paste the following commands into the file:
# INSTALLING AND CONFIGURING IPTABLES PERSISTENT AND DISABLING IPV6
echo “”
echo “INSTALLING IPTABLES PERSISTENT…………………”
sleep 1
sudo apt install iptables-persistent -y
echo “IPTABLES PERSISTENT INSTALLED!”
sleep 1
echo “”
echo “DISABLING IPV6 VIA IPTABLES…………………”
sleep 1
sudo ip6tables -P INPUT DROP
sudo ip6tables -P FORWARD DROP
sudo ip6tables-save | sudo tee /etc/iptables/rules.v6
echo “IPV6 RULES SAVED!”
sleep 1
echo “”
echo “MODIFYING /etc/sysctl.conf TO DISABLE IPV6…………………”
sleep 1
sudo sed -i ‘/^net.ipv6.conf.all.disable_ipv6/d’ /etc/sysctl.conf
sudo sed -i ‘/^net.ipv6.conf.default.disable_ipv6/d’ /etc/sysctl.conf
sudo sed -i ‘/^net.ipv6.conf.lo.disable_ipv6/d’ /etc/sysctl.conf
echo “net.ipv6.conf.all.disable_ipv6 = 1” | sudo tee -a /etc/sysctl.conf
echo “net.ipv6.conf.default.disable_ipv6 = 1” | sudo tee -a /etc/sysctl.conf
echo “net.ipv6.conf.lo.disable_ipv6 = 1” | sudo tee -a /etc/sysctl.conf
echo “CHANGES TO /etc/sysctl.conf SAVED!”
sleep 1
echo “”
echo “MODIFYING /etc/ufw/sysctl.conf…………………”
sleep 1
sudo sed -i ‘s/^net\/ipv6\/conf\/all\/accept_redirects=0/#net\/ipv6\/conf\/all\/accept_redirects=0/’ /etc/ufw/sysctl.conf
sudo sed -i ‘s/^net\/ipv6\/conf\/default\/accept_redirects=0/#net\/ipv6\/conf\/default\/accept_redirects=0/’ /etc/ufw/sysctl.conf
sudo sed -i ‘s/^#net\/ipv6\/conf\/default\/autoconf=1/net\/ipv6\/conf\/default\/autoconf=1/’ /etc/ufw/sysctl.conf
sudo sed -i ‘s/^#net\/ipv6\/conf\/all\/autoconf=1/net\/ipv6\/conf\/all\/autoconf=1/’ /etc/ufw/sysctl.conf
echo “CHANGES TO /etc/ufw/sysctl.conf SAVED!”
sleep 1
echo “”
echo “CONFIGURATION COMPLETE!”
then hit Ctl+O and Enter to save, Ctl+X to exit
Make the file executable by running this command:
sudo chmod +x ipv6_disable.sh
Now run the script like this:
sudo bash ipv6_disable.sh