在Linux禁用IPv6可以使用下面的几种方式:第一种方式:在/etc/modprobe.d/dist.conf文件中添加installipv6 /bin/true,在reboot后使用使用lsmod | grep ipv6查看,IPv6模块没有被加载,在/proc/sys/net目录下也已经没有了ipv6的目录文件。[root@root net]# lscore ipv4 netfilter unix第二种方式: 在/boot/grub/grub.conf文件中,在启动的Linux内核版本中传递下面的参数ipv6.disable=1,该效果和方式一基本类似,都需要重新启动,但是在启动完成后,使用lsmod还是可以参看到ipv6模块信息,但引用ipv6模块数为0. 在/proc/sys/net目录下也没有了ipv6的目录文件。[root@root~]# lsmod | grep ipv6ipv6 331149 0 上面这种方式其实是根据IPv6模块的三个参数进行的,通过modinfo可以看到,IPv6模块支持三个参数,modinfo ipv6filename: /lib/modules/2.6.32/kernel/net/ipv6/ipv6.koalias: net-pf-10license: GPLdescription: IPv6 protocol stack for Linuxauthor: Cast of dozenssrcversion: AA5735202A5094F448BF9AEdepends: vermagic: 2.6.32 SMP mod_unload modversionsparm: disable:Disable IPv6 module suchthat it is non-functional (int)parm: disable_ipv6:Disable IPv6 on allinterfaces (int)parm: autoconf:Enable IPv6 addressautoconfiguration on all interfaces (int) 在Linux内核的文档中我们可以看到对这个三个参数的解释:disable Specifieswhether to load the IPv6 module, but disable all itsfunctionality. This might be used whenanother module hasa dependency on the IPv6 module being loaded, but no IPv6addresses or operations are desired. Thepossible values and their effects are: 0IPv6 is enabled. Thisis the default value. 1IPv6 is disabled. NoIPv6 addresses will be added to interfaces, and itwill not be possible to open an IPv6 socket. Areboot is required to enable IPv6.autoconf Specifieswhether to enable IPv6 address autoconfiguration onall interfaces. This might be used whenone does not wish foraddresses to be automatically generated from prefixes receivedin Router Advertisements. Thepossible values and their effects are: 0IPv6 address autoconfiguration is disabled on all interfaces. Onlythe IPv6 loopback address (::1) and link-local addresses willbe added to interfaces. 1IPv6 address autoconfiguration is enabled on all interfaces. Thisis the default value.disable_ipv6 Specifieswhether to disable IPv6 on all interfaces. Thismight be used when no IPv6 addresses are desired. Thepossible values and their effects are: 0IPv6 is enabled on all interfaces. Thisis the default value. 1IPv6 is disabled on all interfaces. NoIPv6 addresses will be added to interfaces. 在grub.conf中还可以使用ipv6.disable_ipv6=1禁止IPv6协议,和ipv6.disable不同的是对IPv6模块的引用不为零。lsmod | grep ipv6ipv6 331934 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目录下的变量控制。第三种方式: 在/proc/sys/net/ipv6/conf/目录下有下面的目录:[root@root conf]# lsall default eth0 gre0 lo 可以针对不同的接口禁止,如果是针对所有的接口,可以使用下面的命令,该命令会直接把接口上的IPv6地址给删掉,包括本地链路地址fe80::,IPv6, net.ipv6.conf.all.disable_ipv6 = 1net.ipv6.conf.default.disable_ipv6 = 1 下面是Linux内核对该参数的解释:disable_ipv6 - BOOLEAN Disable IPv6operation. If accept_dad is set to 2,this value willbe dynamically set to TRUE if DAD fails for the link-local address. Default:FALSE (enable IPv6 operation) Whenthis value is changed from 1 to 0 (IPv6 is being enabled), itwill dynamically create a link-local address on the given interfaceand start Duplicate Address Detection, if necessary. Whenthis value is changed from 0 to 1 (IPv6 is being disabled), itwill dynamically delete all address on the given interface附录:模块参数的定义module_param_named(disable_ipv6,ipv6_defaults.disable_ipv6, int, 0444);MODULE_PARM_DESC(disable_ipv6,"Disable IPv6 on all interfaces")只在addrconf_init_net函数中使用了IPv6模块参数,所以IPv6模块的disable_ipv6参数只有在初始化时进行了赋值,系统启动后的修改无法改变原先的配置。static int addrconf_init_net(struct net*net){ interr; structipv6_devconf *all, *dflt; err= -ENOMEM; all= &ipv6_devconf; dflt= &ipv6_devconf_dflt; if(net != &init_net) { all= kmemdup(all, sizeof(ipv6_devconf), GFP_KERNEL); if(all == NULL) gotoerr_alloc_all; dflt= kmemdup(dflt, sizeof(ipv6_devconf_dflt), GFP_KERNEL); if(dflt == NULL) gotoerr_alloc_dflt; }else { /*these will be inherited by all namespaces */ dflt->autoconf= ipv6_defaults.autoconf; dflt->disable_ipv6 =ipv6_defaults.disable_ipv6; } net->ipv6.devconf_all= all; net->ipv6.devconf_dflt= dflt; #ifdef CONFIG_SYSCTL err= __addrconf_sysctl_register(net, "all", NET_PROTO_CONF_ALL, NULL,all); if(err gotoerr_reg_all; err= __addrconf_sysctl_register(net, "default", NET_PROTO_CONF_DEFAULT, NULL,dflt); if(err gotoerr_reg_dflt;#endif return0; #ifdef CONFIG_SYSCTLerr_reg_dflt: __addrconf_sysctl_unregister(all);err_reg_all: kfree(dflt);#endiferr_alloc_dflt: kfree(all);err_alloc_all: returnerr;}