欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

关闭IPv6协议:Linux内核的操作指南

最编程 2024-08-14 19:29:13
...
第二种方式:
在/boot/grub/grub.conf文件中,在启动的Linux内核版本中传递下面的参数ipv6.disable=1,该效果和方式一基本类似,都需要重新启动,但是在启动完成后,使用lsmod还是可以参看到ipv6模块信息,但引用ipv6模块数为0. 在/proc/sys/net目录下也没有了ipv6的目录文件。
[root@root~]# lsmod | grep ipv6
ipv6331149  0
上面这种方式其实是根据IPv6模块的三个参数进行的,通过modinfo可以看到,IPv6模块支持三个参数,
modinfo ipv6
filename:       /lib/modules/2.6.32/kernel/net/ipv6/ipv6.ko
alias: net-pf-10
license:        GPL
description:    IPv6 protocol stack for Linux
author:Cast of dozens
srcversion:     AA5735202A5094F448BF9AE
depends:       
vermagic:       2.6.32 SMP mod_unload modversions
parm:  disable:Disable IPv6 module such that it is non-functional (int)
parm:  disable_ipv6:Disable IPv6 on all interfaces (int)
parm:  autoconf:Enable IPv6 address autoconfiguration on all interfaces (int)
在Linux内核的文档中我们可以看到对这个三个参数的解释:
disable
Specifies whether to load the IPv6 module, but disable all
its functionality.  This might be used when another module
has a dependency on the IPv6 module being loaded, but no
IPv6 addresses or operations are desired.
The possible values and their effects are:
0 IPv6 is enabled.
 This is the default value.
1 IPv6 is disabled.
 No IPv6 addresses will be added to interfaces, and
 it will not be possible to open an IPv6 socket.
 A reboot is required to enable IPv6.
autoconf
Specifies whether to enable IPv6 address autoconfiguration
on all interfaces.  This might be used when one does not wish
for addresses to be automatically generated from prefixes
received in Router Advertisements.
The possible values and their effects are:
0 IPv6 address autoconfiguration is disabled on all interfaces.
 Only the IPv6 loopback address (::1) and link-local addresses
 will be added to interfaces.
1 IPv6 address autoconfiguration is enabled on all interfaces.
 This is the default value.
disable_ipv6
Specifies whether to disable IPv6 on all interfaces.
This might be used when no IPv6 addresses are desired.
The possible values and their effects are:
0 IPv6 is enabled on all interfaces.
 This is the default value.
1 IPv6 is disabled on all interfaces.
 No IPv6 addresses will be added to interfaces.
在grub.conf中还可以使用ipv6.disable_ipv6=1禁止IPv6协议,和ipv6.disable不同的是对IPv6模块的引用不为零。
lsmod | grep ipv6
ipv6331934  30
使用echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6 命令可以把IPv6功能重新打开,
使用echo 0 > /sys/module/ipv6/parameters/disable_ipv6命令无法重新打开,这也是这两个控制IPv6协议开关的不同之处。即使在grub.conf文件中不添加ipv6的任何信息,向/sys/module/ipv6/parameters/disable_ipv6文件中写入也不能控制IPv6协议,建议使用proc目录下的变量控制。

推荐阅读