linux 禁用IPv 6

來源:互聯網
上載者:User

標籤:linux 禁用ipv 6

IPv6還沒有完全普及,但是安裝完系統之後IPv6是有效,在一定程度上影響網路效能,所以在我們在完全不使用IPv6的情況下,最好關閉IPv6。其實在上一篇網路設定的文章中,我們提到過是否啟用IPv6,但是只是那一點設定還是不能完全關閉IPv6,所以本文以完整的步驟敘述一下如何關閉它。


查看IP配置

#ifconfig 


eth0      Link encap:Ethernet  HWaddr 00:0C:29:CC:22:28  

          inet addr:192.168.2.253  Bcast:192.168.2.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fecc:2228/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:200403 errors:0 dropped:0 overruns:0 frame:0

          TX packets:5756 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:18713209 (17.8 MiB)  TX bytes:2042418 (1.9 MiB)


lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

如上出現inet6 則表示啟用了IPv6


方法一:

1.修改/etc/sysconfig/network,追加:

NETWORKING_IPV6=no

2.修改/etc/hosts,把ipv6的那句本地主機名稱解析的也注釋掉:

#::1   localhost localhost6 localhost6.localdomain6

3.讓系統不載入ipv6相關模組,這需要修改modprobe相關設定檔案,為了管理方便,我們建立設定檔案/etc/modprobe.d/ipv6off.conf,內容如下,三種方式,總有一款適合你:

alias net-pf-10 off

options ipv6 disable=1

或者

install ipv6 /bin/true

或者

install ipv6 /sbin/modprobe -n -i ipv6

注意,如果你使用了網卡綁定(bond)技術,而且不希望用ipv6,那麼你使用第一種,否則系統啟動時,bonding模組可能會載入失敗。

4.重啟系統,然後確認:

[[email protected] ~]# lsmod | grep -i ipv6

[[email protected] ~]# ifconfig | grep -i inet6

如果上述2個命令執行的結果沒有任何顯示,那麼說明ipv6已經被完全禁止了。

後記:

在第三步不載入ipv6模組的方法裡,可能有人會有類似這樣的設定方法:

alias net-pf-10 off

alias ipv6 off

options ipv6 disable=1

雖然這樣在系統重啟後,ipv6的確沒被載入,但是因為第二句,在有的版本的系統裡,當我們重啟網路的時候,會出現如下錯誤:

FATAL: Module off not found.


方法二:

(不需重啟系統)

編輯/etc/sysctl.conf 

#vim /etc/sysctl.conf 

添加

# IPv6 disabled

net.ipv6.conf.all.disable_ipv6 = 1

net.ipv6.conf.default.disable_ipv6 = 1

net.ipv6.conf.lo.disable_ipv6 = 1


使其生效

#sysctl -p


查看

#ifconfig 

eth0      Link encap:Ethernet  HWaddr 00:0C:29:CC:22:28  

          inet addr:192.168.2.253  Bcast:192.168.2.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:200717 errors:0 dropped:0 overruns:0 frame:0

          TX packets:5898 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:18742847 (17.8 MiB)  TX bytes:2064730 (1.9 MiB)


lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)


本文出自 “技術vs” 部落格,請務必保留此出處http://yuj0607.blog.51cto.com/2330331/1613563

linux 禁用IPv 6

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.