A summary of methods to disable IPV6 under Linux
--http://www.jb51.net/linuxjishu/335724.html
This article mainly introduces the method of disabling IPv6 in Linux, the operation of disabling IPV6 or considering the current and IPV4 compatibility issues, the need for friends can refer to the following
PV6 is considered an alternative to the traditional 32-bit address space on the Internet, which is used to address the impending exhaustion of existing IPv4 address spaces. However, since there are already a large number of hosts, devices with IPv4 connected to the Internet, it is almost impossible to switch them all overnight to IPv6. Many IPv4 to IPv6 conversion mechanisms (e.g., dual stack, network tunneling, proxies) have been proposed to facilitate IPV6 adoption, and many applications are being rewritten, as we have advocated, to increase support for IPv6. One thing to be sure is that IPv4 and IPv6 are bound to coexist in the foreseeable future.
Ideally, the process of transitioning to IPV6 should not be seen by the end user, but the Ipv4/ipv6 hybrid environment sometimes allows you to encounter a variety of problems that arise inadvertently between IPV4 and IPV6. For example, you might encounter problems with application timeouts, such as apt-get or SSH attempts to connect through IPV6, DNS servers accidentally emptied IPv6 AAAA records, or devices that you support IPV6 are not compatible with your Internet service provider's legacy IPV4 network, and so on.
Of course this does not mean that you should blindly disable IPV6 on your Linux machine. Given the benefits of IPV6 's promise, as a part of society we will eventually embrace it fully, but if IPV6 is really the culprit in the process of troubleshooting the end user, you can try to close it.
Here are some tips for you to disable IPV6 in Linux (for example, for a particular network interface) or all. These tips should apply to all major Linux distributions including Ubuntu, Debian, Linux Mint, CentOS, Fedora, Rhel, and Arch Linux.
See if IPV6 is enabled in Linux
all modern Linux distributions are automatically enabled by default IPv6。 In order to see if IPV6 is activated in your Linux,you can use Ifconfig or IP commands. If you see the output of the word "Inet6" after you enter these commands, it means that your Linux system has IPV6 enabled.
Copy the code code as follows:
$ ifconfig
Copy the code code as follows:
$ IP Addr
Temporarily disable IPV6
If you want to temporarily turn off IPV6 on your Linux system, you can use the/proc file system. "Temporary" means that the changes we have made to disable IPV6 will not be saved after the system restarts. The IPV6 will be enabled again after your Linux machine restarts.
To disable IPV6 for a specific network interface, use the following command:
Copy the code code as follows:
$ sudo sh-c ' echo 1 >/proc/sys/net/ipv6/conf/<interface-name>/disable_ipv6 '
For example, disable IPV6 for the Eth0 interface:
Copy the code code as follows:
$ sudo sh-c ' echo 1 >/proc/sys/net/ipv6/conf/eth0/disable_ipv6 '
201563173436921.jpg (773x330)
Re-enable the IPV6 for the Eth0 interface:
Copy the code code as follows:
$ sudo sh-c ' echo 0 >/proc/sys/net/ipv6/conf/eth0/disable_ipv6 '
If you want to disable IPV6 for all interfaces of the entire system including loopback interfaces, use the following command:
Copy the code code as follows:
$ sudo sh-c ' echo 1 >/proc/sys/net/ipv6/conf/all/disable_ipv6 '
Permanently disable IPV6
The above method is unable to permanently disable IPV6, you will be enabled if you restart the system IPv6. If you want to close it permanently, there are a few ways you can try it.
Method One
The first method is to permanently modify the/proc through the/etc/sysctl.conf file.
In other words, just open/etc/sysctl.conf with a text editor and add the following:
Copy the code code as follows:
# Disable IPV6 for all interfaces of the entire system
Net.ipv6.conf.all.disable_ipv6 = 1
# Disable the IPv6 of a specified interface (for example: Eth0, lo)
Net.ipv6.conf.lo.disable_ipv6 = 1
Net.ipv6.conf.eth0.disable_ipv6 = 1
In/etc/sysctl.conf make these changes effective, run the following command:
Copy the code code as follows:
$ sudo sysctl-p/etc/sysctl.conf
or reboot directly.
Method Two
Another way to permanently disable IPV6 is to pass a necessary kernel parameter at boot time.
Open/etc/default/grub with a text editor and add "ipv6.disable=1" to the Grubcmdlinelinux variable.
Copy the code code as follows:
$ sudo vi/etc/default/grub</p> <p> grub_cmdline_linux= "xxxxx ipv6.disable=1"
The above "xxxxx" stands for any existing kernel parameters and adds "ipv6.disable=1" after it.
Finally, don't forget to save the changes to GRUB/GRUB2 in the following ways:
Debian, Ubuntu, or Linux Mint systems:
Copy the code code as follows:
$ sudo update-grub
Fedora, Centos/rhel system:
Copy the code code as follows:
$ sudo grub2-mkconfig-o/boot/grub2/grub.cfg
Now as soon as you restart your Linux system, IPV6 will be completely disabled.
Additional optional steps after disabling IPV6
Here are some optional steps to consider when you disable IPV6, because when you disable IPV6 in the kernel, other programs may still try to use IPV6. In most cases, this behavior of the application is less likely to affect anything, but for efficiency or security reasons, you can disable IPv6 for them.
/etc/hosts
Depending on your settings,/etc/hosts will contain one or more IPV6 hosts and their addresses. Open/etc/hosts with a text editor and comment out the line of script that contains the IPV6 hosts.
Copy the code code as follows:
$ sudo vi/etc/hosts</p> <p> # comment These IPv6 hosts
#:: 1 ip6-localhost ip6-loopback
# fe00::0 Ip6-localnet
# ff00::0 Ip6-mcastprefix
# ff02::1 Ip6-allnodes
# Ff02::2 Ip6-allrouters
Network Manager
If you are using NetworkManager to manage your network settings, you can disable IPV6 in NetworkManager. In NetworkManager open wired connection, click the "IPv6 Settings" option and select "Ignore" in the "Method" column to save the exit.
201563173528661.png (473x489)
SSH Service
By default, the OpenSSH service (sshd) tries to bundle the addresses of IPV4 and IPV6.
To force sshd to bundle only IPV4 addresses, open/etc/ssh/sshd_config with a text editor and add the following lines. The inet applies only to IPv4, and Inet6 is for IPV6.
Copy the code code as follows:
$ sudo vi/etc/ssh/sshd_config</p> <p> addressfamily inet
Then restart the sshd service.
A summary of methods to disable IPV6 under Linux