Linux核心關閉IPv6協議的方式

來源:互聯網
上載者:User

Linux核心關閉IPv6協議的方式

在Linux禁用IPv6可以使用下面的幾種方式:

第一種方式:

在/etc/modprobe.d/dist.conf檔案中添加install ipv6 /bin/true,在reboot後使用使用lsmod | grep ipv6查看,IPv6模組沒有被載入,在/proc/sys/net目錄下也已經沒有了ipv6的目錄檔案。[root@root net]# ls

core  ipv4  netfilter  unix

第二種方式:

        在/boot/grub/grub.conf檔案中,在啟動的Linux核心版本中傳遞下面的參數ipv6.disable=1,該效果和方式一基本類似,都需要重新啟動,但是在啟動完成後,使用lsmod還是可以參看到ipv6模組資訊,但引用ipv6模組數為0. 在/proc/sys/net目錄下也沒有了ipv6的目錄檔案。

[root@root~]# lsmod | grep ipv6

ipv6                  331149  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

ipv6                  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]# ls

all  default  eth0  gre0  lo

        可以針對不同的介面禁止,如果是針對所有的介面,可以使用下面的命令,該命令會直接把介面上的IPv6地址給刪掉,包括本地鏈路地址fe80::,

IPv6, net.ipv6.conf.all.disable_ipv6 = 1

net.ipv6.conf.default.disable_ipv6 = 1

        下面是Linux核心對該參數的解釋:

disable_ipv6 - BOOLEAN Disable IPv6 operation.  If accept_dad is set to 2, this value

        will be dynamically set to TRUE if DAD fails for the link-local

        address.

        Default: FALSE (enable IPv6 operation)

        When this value is changed from 1 to 0 (IPv6 is being enabled),

        it will dynamically create a link-local address on the given

        interface and start Duplicate Address Detection, if necessary.

        When this value is changed from 0 to 1 (IPv6 is being disabled),

        it will 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)

{

        int err;

        struct ipv6_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)

                            goto err_alloc_all;

 

                  dflt = kmemdup(dflt, sizeof(ipv6_devconf_dflt), GFP_KERNEL);

                  if (dflt == NULL)

                            goto err_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 < 0)

                  goto err_reg_all;

 

        err = __addrconf_sysctl_register(net, "default", NET_PROTO_CONF_DEFAULT,

                            NULL, dflt);

        if (err < 0)

                  goto err_reg_dflt;

#endif

        return 0;

 

#ifdef CONFIG_SYSCTL

err_reg_dflt:

        __addrconf_sysctl_unregister(all);

err_reg_all:

        kfree(dflt);

#endif

err_alloc_dflt:

        kfree(all);

err_alloc_all:

        return err;

}

Ubuntu開啟IPV6

思科CCIE認證知識點之IPV6地址

WireShark下抓取IPV6資料包使用教程

Ubuntu 12.04 校園網下使用IPV6源 免流量更新

Linux搭建IPV6 ftp伺服器

CentOS IPV6設定

CentOS純IPV6環境下設定更新源

CentOS 6 IPV6 關閉方法

如何在Ubuntu,Linux Mint,Debian上禁用IPv6 

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.