ipv6

  • 新版本的 debian/ubuntu 系统倾向于使用ipv6
  • 只要探测到物理网络环境支持ipv6,那么系统就会生成私有的ipv6地址池,并且尝试向路由器注册

    即使路由器拒绝为ipv6服务,但是系统仍然会生成并且使用自己的ipv6
  • 高版本的系统上ipv6的优先级比ipv4高

    以apt为例

    在执行apt时,操作系统发现ipv6被标记为可用

    那么操作系统就会支持尝试使用ipv6来完成apt的网络操作

    这直接会导致apt失败或者永久等待

早期系统

编辑配置文件/etc/sysctl.conf

# 禁用整个系统所有接口的IPv6
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

# 禁用某一个指定接口的IPv6(例如:eth0, lo)
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.eth0.disable_ipv6 = 1

应用新的策略

sysctl -p 
  • 上面的代码可以做到永久禁用 ipv6

ubuntu18+

  • 较新版本的 debian/ubuntu使用上面的方案并不能自动禁用ipv6

    但是手动运行 sysctl -p 仍然可以强制生效
  • 这里采用grub直接在内核启动时禁用

编辑配置文件/etc/default/grub

在属性GRUB_CMDLINE_LINUX_DEFAULT中增加值ipv6.disable=1,修改完成后如下

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"

修改完后使用如下命令刷新配置

update-grub

降低ipv6优先级

  • 无论是直接禁用 ipv6还是内核禁用,都可能会造成一些问题
  • 比较文艺的方案时降低ipv6的优先级
  • 这里要注意的是具体使用ipv6还是ipv4仍然是在目标程序决定

编辑配置文件/etc/gai.conf,增加如下配置在文件末尾

precedence ::ffff:0:0/96  100

ipv6

  • Newer versions of debian/ubuntu systems tend to use ipv6
  • whenever the physical network environment is detected to support ipv6, the system generates a private ipv6 address pool and tries to register it with the router

    Even if the router refuses to serve ipv6, the system will still generate and use its own ipv6
  • IPv6 has a higher priority than ipv4 on higher versions of systems

    Using apt as an example
    For example
    When apt is executed, the OS finds that ipv6 is marked as available

    then the OS will support trying to use ipv6 for apt's network operations

    This can directly cause apt to fail or wait permanently

Early systems

Edit the configuration file /etc/sysctl.conf

# Disable IPv6 for all interfaces across the system
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

# Disable IPv6 for a specific interface (e.g. eth0, lo)
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.eth0.disable_ipv6 = 1

Apply the new policy

sysctl -p 
  • The above code can be used to permanently disable ipv6

ubuntu18+

  • newer versions of debian/ubuntu do not automatically disable ipv6 using the above scheme

    but running sysctl -p manually will still force it to take effect
  • here grub is used to disable it directly at kernel boot time

Edit the configuration file /etc/default/grub

Add the value ipv6.disable=1 to the attribute GRUB_CMDLINE_LINUX_DEFAULT, and the change will look like this

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"

then use the cmd to flush grub

update-grub

lower ipv6 priority

  • Either disabling ipv6 directly or in the kernel may cause some problems
  • The more elegant solution is to lower the priority of ipv6
  • Note here that the decision to use ipv6 or ipv4 is still up to the target application

Edit the configuration file /etc/gai.conf and add the following configuration at the end of the file

precedence ::fff:0:0/96 100
Last modification:February 23, 2021
如果觉得我的文章对你有用,请随意赞赏