Ubuntu 禁用IPv6的方法

IPv6 是为了解决 IPv4 地址耗尽的问题,但我们的服务器一般用不到它,反而禁用 IPv6 不仅仅会加快网络,还会有助于减少管理开销和提高安全级别。
以下几步在 Ubuntu 禁用 IPv6 (需要 root 权限)

Ubuntu 禁止加载 IPv6 模块

检查是否启用了 IPv6

如果启用了 IPv6,会看到 inet6 xxx 内容,如下所示:

[root@Ubuntu:~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 56:00:02:8f:cf:64 brd ff:ff:ff:ff:ff:ff
    inet 45.63.11.216/23 brd 45.63.11.255 scope global dynamic ens3
       valid_lft 86270sec preferred_lft 86270sec
    inet6 fe80::5400:2ff:fe8f:cf64/64 scope link 
       valid_lft forever preferred_lft forever

修改 /etc/sysctl.conf 文件

添加以下内容

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

执行 sysctl -p 使设置生效

[root@Ubuntu:modprobe.d]# sysctl -p
net.ipv6.conf.all.accept_ra = 2
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

创建 /etc/rc.local 文件

上一步已经禁用了 IPv6,但是重启后会复原。要想重启后也禁用,则必须做这一步。

[root@Ubuntu:~]# vim /etc/rc.local

填入内容

#!/bin/bash

# /etc/rc.local

/etc/sysctl.d

/etc/init.d/procps restart

exit 0

授权文件可执行

[root@Ubuntu:~]# chmod 755 /etc/rc.local 

验证是否生效

重启后执行 ip a 验证

[root@Ubuntu:~]# reboot
...
[root@Ubuntu:~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 56:00:02:8f:cf:64 brd ff:ff:ff:ff:ff:ff
    inet 45.63.11.216/23 brd 45.63.11.255 scope global dynamic ens3
       valid_lft 86332sec preferred_lft 86332sec
Responses
  1. Outliff

    It's true, a issue can be used by you. However, you must look after a couple matters just prior to producing the name of a composition:... Short -- once you are able to, create a composition name quick. http://www.vsbarbarians.com.au/index.php/2021/05/19/3-short-stories-you-didnt-know-about-professional-research-paper-writing-service/ http://198.49.162.244/the-ultimate-deal-on-professional-paper-writing-service/ http://familee5.com/do-you-have-to-report-your-sat-essay-score/

    Reply
  2. Ali

    Very good information. Lucky me I came across your site by accident (stumbleupon). I've book-marked it for later!

    Reply
  3. Outliff

    Create a summary of the composition. Your composition needs to stick to the typical 5 paragraph structure (Introduction, system Paragraphs, summary ) except if instructed by your own teacher. http://ineuropaonline.com/why-paper-writing-service-succeeds.html https://www.vortexbd.com/uncategorized/cheap-custom-writing-service-keep-it-simple-and-stupid/ https://houseofjobss.com/how-did-we-get-there-the-history-of-help-with-thesis-writing-told-through-tweets/

    Reply
  4. I know this if off topic but I'm looking into starting my own weblog and was curious what all is required to get set up? I'm assuming having a blog like yours would cost a pretty penny? I'm not very internet savvy so I'm not 100% sure. Any recommendations or advice would be greatly appreciated. Thanks

    Reply
  5. Hi to all, the contents present at this site are truly awesome for people knowledge, well, keep up the nice work fellows.

    Reply
  6. Howdy! This is my first visit to your blog! We are a collection of volunteers and starting a new initiative in a community in the same niche. Your blog provided us valuable information to work on. You have done a wonderful job!

    Reply