A summary of how to disable IPV6 under Linux

Source: Internet
Author: User
Tags file system ssh centos arch linux

PV6 is considered an alternative to the traditional 32-bit address space on the ipv4--Internet, which is used to solve the problem of the impending exhaustion of the existing IPV4 address space. However, since a large number of hosts and devices are connected to the Internet with IPV4, it is almost impossible to switch them all overnight to IPv6. Many IPv4 to IPv6 conversion mechanisms (e.g., dual protocol stacks, network tunnels, proxies) have been proposed to facilitate IPV6 adoption, and many applications are being rewritten, as we advocate, to increase support for IPv6. One thing is certain 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 Ipv4/ipv6 mixed environments can sometimes cause you to encounter a variety of inadvertently colliding problems that arise between IPV4 and IPV6. For example, you may encounter application timeouts, such as apt-get or SSH attempts to fail the connection via IPV6, the DNS server accidentally clears the IPv6 aaaa record, or the device you support IPV6 is incompatible with your Internet service provider's legacy IPV4 network, and so on.

This does not mean, of course, that you should blindly disable IPV6 on your Linux machine. Given all the benefits IPv6 promised, as a part of society we end up embracing it, but as part of the troubleshooting process for end users, if IPV6 is really the culprit, you can try to shut it down.

Here are some tips for disabling IPv6 in parts of Linux (for example, for a particular network interface) or all of them. 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 IPV6 by default. 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.

The code is as follows:

$ ifconfig


The code is 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. IPV6 will be enabled again after your Linux machine restarts.

To disable IPV6 for a specific network interface, use the following command:

The code is as follows:

$ sudo sh-c ' echo 1 >/proc/sys/net/ipv6/conf/ /disable_ipv6 '

For example, disable the Eth0 interface IPv6:

The code is as follows:

$ sudo sh-c ' echo 1 >/proc/sys/net/ipv6/conf/eth0/disable_ipv6 '

Re-enable the IPv6 of the Eth0 interface:

The code is as follows:

$ sudo sh-c ' echo 0 >/proc/sys/net/ipv6/conf/eth0/disable_ipv6 '

If you want to disable IPV6 for all of the system's interfaces including the loopback interface, use the following command:

The code is as follows:

$ sudo sh-c ' echo 1 >/proc/sys/net/ipv6/conf/all/disable_ipv6 '

Permanently disable IPV6

The above method is not permanently disabled IPv6, once you restart the system IPv6 will still be enabled. If you want to permanently close it, there are several ways you can try.

Method One

The first method is to make permanent changes to/proc through the/etc/sysctl.conf file.

In other words, open/etc/sysctl.conf with a text editor and add the following:

The code is as follows:

# Disable IPV6 for all interfaces of the entire system

Net.ipv6.conf.all.disable_ipv6 = 1

# Disables 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 take effect, run the following command:

The code is 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.

The code is as follows:

$ sudo vi/etc/default/grub

grub_cmdline_linux= "xxxxx ipv6.disable=1"

"XXXXX" above represents any existing kernel parameter and adds "Ipv6.disable=1" after it.

Finally, don't forget to save changes to GRUB/GRUB2 in the following ways:

Debian, Ubuntu, or Linux Mint systems:

The code is as follows:

$ sudo update-grub

Fedora, Centos/rhel system:

The code is as follows:

$ sudo grub2-mkconfig-o/boot/grub2/grub.cfg

Now as soon as you reboot your Linux system, the IPV6 will be completely disabled.

Other optional steps after disabling IPV6

Here are some optional steps to consider after 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 not likely to affect anything, but for efficiency or security reasons, you can disable IPv6 for them.

/etc/hosts

Depending on your setup,/etc/hosts will contain one or more IPV6 hosts and their addresses. Open/etc/hosts with a text editor and comment out the script line containing IPV6 hosts.

The code is as follows:

$ sudo vi/etc/hosts

# 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 the wired connection, click the "IPv6 Settings" option and select "Ignore" in the "Method" column to save the exit.

SSH Service

By default, the OpenSSH service (SSHD) attempts to bundle IPV4 and IPV6 addresses.

To force sshd to bundle only IPV4 addresses, open/etc/ssh/sshd_config with a text editor and add the following line. Inet is only applicable to IPv4, and Inet6 is suitable for IPv6.

The code is as follows:

$ sudo vi/etc/ssh/sshd_config

AddressFamily inet

Then restart the sshd service.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.