mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
Merge pull request #2664 from ZTinoZ/master
Finish the translation by ZTinoZ
This commit is contained in:
commit
04ef86c7a3
@ -1,149 +0,0 @@
|
||||
Translating by ZTinoZ
|
||||
Linux FAQs with Answers--How to disable IPv6 on Linux
|
||||
================================================================================
|
||||
> **Question**: I notice that one of my applications is trying to establish a connection over IPv6. But since our local network is not able to route IPv6 traffic, the IPv6 connection times out, and the application falls back to IPv4, which causes unnecessary delay. As I don't have any need for IPv6 at the moment, I would like to disable IPv6 on my Linux box. What is a proper way to turn off IPv6 on Linux?
|
||||
|
||||
IPv6 has been introduced as a replacement of IPv4, the traditional 32-bit address space used in the Internet, to solve the imminent exhaustion of available IPv4 address space. However, since IPv4 has been used by every host or device connected to the Internet, it is practically impossible to switch every one of them to IPv6 overnight. Numerous IPv4 to IPv6 transition mechanisms (e.g., dual IP stack, tunneling, proxying) have been proposed to facilitate the adoption of IPv6, and many applications are being rewritten, as we speak, to add support for IPv6. One thing for sure is that IPv4 and IPv6 will inevitably coexist for the forseeable future.
|
||||
|
||||
Ideally the [ongoing IPv6 transition process][1] should not be visible to end users, but the mixed IPv4/IPv6 environment might sometimes cause you to encounter various hiccups originating from unintended interaction between IPv4 and IPv6. For example, you may experience timeouts from applications such as apt-get or ssh trying to unsuccessfully connecting via IPv6, DNS server accidentally dropping AAAA DNS records for IPv6, or your IPv6-capable device not compatible with your ISP's legacy IPv4 network, etc.
|
||||
|
||||
Of course this doesn't mean that you should blindly disable IPv6 on you Linux box. With all the benefits promised by IPv6, we as a society want to fully embrace it eventually, but as part of troubleshooting process for end-user experienced hiccups, you may try turning off IPv6 to see if indeed IPv6 is a culprit.
|
||||
|
||||
Here are a few techniques allowing you to disable IPv6 partially (e.g., for a certain network interface) or completely on Linux. These tips should be applicable to all major Linux distributions including Ubuntu, Debian, Linux Mint, CentOS, Fedora, RHEL, and Arch Linux.
|
||||
|
||||
### Check if IPv6 is Enabled on Linux ###
|
||||
|
||||
All modern Linux distributions have IPv6 automatically enabled by default. To see IPv6 is activated on your Linux, use ifconfig or ip commands. If you see "inet6" in the output of these commands, this means your Linux has IPv6 enabled.
|
||||
|
||||
$ ifconfig
|
||||
|
||||
![](https://farm8.staticflickr.com/7282/16415082398_5fb0920506_b.jpg)
|
||||
|
||||
$ ip addr
|
||||
|
||||
![](https://farm8.staticflickr.com/7290/16415082248_c4e075548b_c.jpg)
|
||||
|
||||
### Disable IPv6 Temporarily ###
|
||||
|
||||
If you want to turn off IPv6 temporarily on your Linux system, you can use /proc file system. By "temporarily", we mean that the change we make to disable IPv6 will not be preserved across reboots. IPv6 will be enabled back again after you reboot your Linux box.
|
||||
|
||||
To disable IPv6 for a particular network interface, use the following command.
|
||||
|
||||
$ sudo sh -c 'echo 1 > /proc/sys/net/ipv6/conf/<interface-name>/disable_ipv6'
|
||||
|
||||
For example, to disable IPv6 for eth0 interface:
|
||||
|
||||
$ sudo sh -c 'echo 1 > /proc/sys/net/ipv6/conf/eth0/disable_ipv6'
|
||||
|
||||
![](https://farm8.staticflickr.com/7288/15982511863_0c1feafe7f_b.jpg)
|
||||
|
||||
To enable IPv6 back on eth0 interface:
|
||||
|
||||
$ sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/eth0/disable_ipv6'
|
||||
|
||||
If you want to disable IPv6 system-wide for all interfaces including loopback interface, use this command:
|
||||
|
||||
$ sudo sh -c 'echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
|
||||
|
||||
### Disable IPv6 Permanently across Reboots ###
|
||||
|
||||
The above method does not permanently disable IPv6 across reboots. IPv6 will be activated again once you reboot your system. If you want to turn off IPv6 for good, there are several ways you can do it.
|
||||
|
||||
#### Method One ####
|
||||
|
||||
The first method is to apply the above /proc changes persistently in /etc/sysctl.conf file.
|
||||
|
||||
That is, open /etc/sysctl.conf with a text editor, and add the following lines.
|
||||
|
||||
# to disable IPv6 on all interfaces system wide
|
||||
net.ipv6.conf.all.disable_ipv6 = 1
|
||||
|
||||
# to disable IPv6 on a specific interface (e.g., eth0, lo)
|
||||
net.ipv6.conf.lo.disable_ipv6 = 1
|
||||
net.ipv6.conf.eth0.disable_ipv6 = 1
|
||||
|
||||
To activate these changes in /etc/sysctl.conf, run:
|
||||
|
||||
$ sudo sysctl -p /etc/sysctl.conf
|
||||
|
||||
or simply reboot.
|
||||
|
||||
#### Method Two ####
|
||||
|
||||
An alternative way to disable IPv6 permanently is to pass a necessary kernel parameter via GRUB/GRUB2 during boot time.
|
||||
|
||||
Open /etc/default/grub with a text editor, and add "ipv6.disable=1" to GRUB_CMDLINE_LINUX variable.
|
||||
|
||||
$ sudo vi /etc/default/grub
|
||||
|
||||
----------
|
||||
|
||||
GRUB_CMDLINE_LINUX="xxxxx ipv6.disable=1"
|
||||
|
||||
In the above, "xxxxx" denotes any existing kernel parameter(s). Add "ipv6.disable=1" after them.
|
||||
|
||||
![](https://farm8.staticflickr.com/7286/15982512103_ec5d940e58_b.jpg)
|
||||
|
||||
Finally, don't forget to apply the modified GRUB/GRUB2 settings by running:
|
||||
|
||||
On Debian, Ubuntu or Linux Mint:
|
||||
|
||||
$ sudo update-grub
|
||||
|
||||
On Fedora, CentOS/RHEL:
|
||||
|
||||
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||
|
||||
Now IPv6 will be completely disabled once you reboot your Linux system.
|
||||
|
||||
### Other Optional Steps after Disabling IPv6 ###
|
||||
|
||||
Here are a few optional steps you can consider after disabling IPv6. This is because while you disable IPv6 in the kernel, other programs may still try to use IPv6. In most cases, such application behaviors will not break things, but you want to disable IPv6 for them for efficiency or safety reason.
|
||||
|
||||
#### /etc/hosts ####
|
||||
|
||||
Depending on your setup, /etc/hosts may contain one or more IPv6 hosts and their addresses. Open /etc/hosts with a text editor, and comment out all lines which contain IPv6 hosts.
|
||||
|
||||
$ 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 on NetworkManager as follows. Open the wired connection on NetworkManager, click on "IPv6 Settings" tab, and choose "Ignore" in "Method" field. Save the change and exit.
|
||||
|
||||
![](https://farm8.staticflickr.com/7293/16394993017_21917f027b_o.png)
|
||||
|
||||
#### SSH server ####
|
||||
|
||||
By default, OpenSSH server (sshd) tries to bind on both IPv4 and IPv6 addresses.
|
||||
|
||||
To force sshd to bind only on IPv4 address, open /etc/ssh/sshd_config with a text editor, and add the following line. inet is for IPv4 only, and inet6 is for IPv6 only.
|
||||
|
||||
$ sudo vi /etc/ssh/sshd_config
|
||||
|
||||
----------
|
||||
|
||||
AddressFamily inet
|
||||
|
||||
and restart sshd server.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/disable-ipv6-linux.html
|
||||
|
||||
作者:[Dan Nanni][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://ask.xmodulo.com/author/nanni
|
||||
[1]:http://www.google.com/intl/en/ipv6/statistics.html
|
@ -0,0 +1,148 @@
|
||||
Linux有问必答时间--如何在Linux下禁用IPv6
|
||||
================================================================================
|
||||
> **问题**:我发现我的一个应用程序在尝试通过IPv6建立连接,但是由于我们本地网络不允许分配IPv6的流量,IPv6连接会超时,应用程序的连接会退回到IPv4,这样就会造成不必要的延迟。由于我目前对IPv6没有任何需求,所以我想在我的Linux主机上禁用IPv6。有什么比较合适的方法呢?
|
||||
|
||||
IPv6被认为是IPv4——互联网上的传统32位地址空间的替代产品,它为了解决现有IPv4地址空间即将耗尽的问题。然而,由于IPv4已经被每台主机或设备连接到了互联网上,所以想在一夜之间将它们全部切换到IPv6几乎是不可能的。许多IPv4到IPv6的转换机制(例如:双协议栈、网络隧道、代理) 已经被提出来用来促进IPv6能被采用,并且很多应用也正在进行重写,就像我们所说的,来增加对IPv6的支持。有一件事情能确定,就是在可预见的未来里IPv4和IPv6势必将共存。
|
||||
|
||||
理想情况下,[向IPv6过渡的进程][1]不应该被最终的用户所看见,但是IPv4/IPv6混合环境有时会让你碰到各种源于IPv4和IPv6之间不经意间的相互作用的问题。举个例子,你会碰到应用程序超时的问题比如apt-get或ssh尝试通过IPv6连接失败、DNS服务器意外清空了IPv6的AAAA记录、或者你支持IPv6的设备不兼容你的互联网服务提供商遗留下的IPv4网络等等等等。
|
||||
|
||||
当然这不意味着你应该盲目地在你的Linux机器上禁用IPv6。鉴于IPv6许诺的种种好处,作为社会的一份子我们最终还是要充分拥抱它的,但是作为给最终用户进行故障排除过程的一部分,如果IPv6确实是罪魁祸首那你可以尝试去关闭它。
|
||||
|
||||
这里有一些让你在Linux中部分或全部禁用IPv6的小技巧(例如:为一个已经确定的网络接口)。这些小贴士应该适用于所有主流的Linux发行版包括Ubuntu、Debian、Linux Mint、CentOS、Fedora、RHEL以及Arch Linux。
|
||||
|
||||
### 查看IPv6在Linux中是否被启用 ###
|
||||
|
||||
所有现代Linux发行版默认都自动启用IPv6。为了能看到IPv6在你的Linux中是否被激活,可以使用ifconfig或ip命令。如果你在输入这些命令之后看到"inet6"字样的输出,那就意味着你的Linux系统启用了IPv6。
|
||||
|
||||
$ ifconfig
|
||||
|
||||
![](https://farm8.staticflickr.com/7282/16415082398_5fb0920506_b.jpg)
|
||||
|
||||
$ ip addr
|
||||
|
||||
![](https://farm8.staticflickr.com/7290/16415082248_c4e075548b_c.jpg)
|
||||
|
||||
### 临时禁用IPv6 ###
|
||||
|
||||
如果你想要在你的Linux系统上临时关闭IPv6,你可以用 /proc 文件系统。"临时",意思是我们所做的禁用IPv6的更改在系统重启后将不被保存。IPv6会在你的Linux机器重启后再次被启用。
|
||||
|
||||
要将一个特定的网络接口禁用IPv6,使用以下命令:
|
||||
|
||||
$ sudo sh -c 'echo 1 > /proc/sys/net/ipv6/conf/<interface-name>/disable_ipv6'
|
||||
|
||||
举个例子,将eth0接口禁用IPv6:
|
||||
|
||||
$ sudo sh -c 'echo 1 > /proc/sys/net/ipv6/conf/eth0/disable_ipv6'
|
||||
|
||||
![](https://farm8.staticflickr.com/7288/15982511863_0c1feafe7f_b.jpg)
|
||||
|
||||
重新启用eth0接口的IPv6:
|
||||
|
||||
$ sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/eth0/disable_ipv6'
|
||||
|
||||
如果你想要将整个系统所有接口包括回环接口禁用IPv6,使用以下命令:
|
||||
|
||||
$ sudo sh -c 'echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
|
||||
|
||||
### 永久禁用IPv6 ###
|
||||
|
||||
以上方法是不能永久禁用IPv6的,你一旦重启系统IPv6还是会被启用。如果你想要永久关闭它,有几个方法你可以试试。
|
||||
|
||||
#### 方法一 ####
|
||||
|
||||
第一种方法是请求以上提到的 /proc 对 /etc/sysctl.conf 文件进行修改。
|
||||
|
||||
换句话说,就是用文本编辑器打开 /etc/sysctl.conf 然后添加以下内容:
|
||||
|
||||
# 禁用整个系统所有接口的IPv6
|
||||
net.ipv6.conf.all.disable_ipv6 = 1
|
||||
|
||||
# 禁用某一个指定接口的IPv6(例如:eth0, lo)
|
||||
net.ipv6.conf.lo.disable_ipv6 = 1
|
||||
net.ipv6.conf.eth0.disable_ipv6 = 1
|
||||
|
||||
在 /etc/sysctl.conf 使这些更改生效,运行以下命令:
|
||||
|
||||
$ sudo sysctl -p /etc/sysctl.conf
|
||||
|
||||
或者直接重启。
|
||||
|
||||
#### 方法二 ####
|
||||
|
||||
另一个永久禁用IPv6的方法是在开机的时候执行一个必要的内核参数。
|
||||
|
||||
用文本编辑器打开 /etc/default/grub 并给GRUB_CMDLINE_LINUX变量添加"ipv6.disable=1"。
|
||||
|
||||
$ sudo vi /etc/default/grub
|
||||
|
||||
----------
|
||||
|
||||
GRUB_CMDLINE_LINUX="xxxxx ipv6.disable=1"
|
||||
|
||||
上面的"xxxxx"代表任意存在着的内核参数,在它后面添加"ipv6.disable=1"。
|
||||
|
||||
![](https://farm8.staticflickr.com/7286/15982512103_ec5d940e58_b.jpg)
|
||||
|
||||
最后,不要忘记用以下方法保存对GRUB/GRUB2的修改:
|
||||
|
||||
Debian、Ubuntu或Linux Mint系统:
|
||||
|
||||
$ sudo update-grub
|
||||
|
||||
Fedora、CentOS/RHEL系统:
|
||||
|
||||
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||
|
||||
现在只要你重启你的Linux系统,IPv6就会完全被禁用。
|
||||
|
||||
### 禁用IPv6之后的其它可选步骤 ###
|
||||
|
||||
这里有一些可选步骤在你禁用IPv6后需要考虑,这是因为当你在内核里禁用IPv6后,其它程序仍然会尝试使用IPv6。在大多数情况下,例如应用程序的运转状态不太会遭到破坏,但是出于效率或安全方面的原因,你要为他们禁用IPv6。
|
||||
|
||||
#### /etc/hosts ####
|
||||
|
||||
根据你的设置, /etc/hosts 会包含一条或多条IPv6的hosts和它们的地址。用文本编辑器打开 /etc/hosts 并注释掉包含IPv6 hosts的脚本行。
|
||||
|
||||
$ 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 ####
|
||||
|
||||
如果你在用NetworkManager来管理你的网络设置,你可以在NetworkManager里禁用IPv6。在NetworkManager打开wired connection,点击"IPv6 Settings"选项并在"Method"一栏选择"Ignore",保存退出。
|
||||
|
||||
![](https://farm8.staticflickr.com/7293/16394993017_21917f027b_o.png)
|
||||
|
||||
#### SSH服务 ####
|
||||
|
||||
默认情况下,OpenSSH服务(sshd)会去尝试捆绑IPv4和IPv6的地址。
|
||||
|
||||
要强制sshd只捆绑IPv4地址,用文本编辑器打开 /etc/ssh/sshd_config 并添加以下脚本行。inet只适用于IPv4,而inet6是适用于IPv6的。
|
||||
|
||||
$ sudo vi /etc/ssh/sshd_config
|
||||
|
||||
----------
|
||||
|
||||
AddressFamily inet
|
||||
|
||||
然后重启sshd服务。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/disable-ipv6-linux.html
|
||||
|
||||
作者:[Dan Nanni][a]
|
||||
译者:[ZTinoZ](https://github.com/ZTinoZ)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://ask.xmodulo.com/author/nanni
|
||||
[1]:http://www.google.com/intl/en/ipv6/statistics.html
|
Loading…
Reference in New Issue
Block a user