Ubuntu 18.04 配置 Online IPv6

Ubuntu 的 netplan.io 实在是太烂了

Online 的 IPv6,之前写过一篇,是通过 /etc/network/interfaces 文件中的 pre-up 字段运行 dhclient 宣告 DUID,然而在 Ubuntu 18.04 中,ifupdown 换成了 netplan.io,原来的方法就不能用了。此外,dhclient 在每次运行的时候会清空当前 iface 上的 IPv6 地址,这个也给 netplan 造成了麻烦。在折腾之后有了一种解决办法:

  • 在 netplan 配置文件中写入静态 IPv6 地址(同 /etc/network/interfaces)
  • 使用 systemd 运行 dhclient
  • 在运行 dhclient 之后再次执行 netplan apply

需要写入如下文件:

/etc/dhcp/dhclient6.conf

interface "<iface>" {
  send dhcp6.client-id <DUID>;
  request;
}

/etc/systemd/system/dhclient.service

[Unit]
Description=dhclient for sending DUID IPv6
Wants=network.target
Before=network.target

[Service]
Type=forking
ExecStart=/sbin/dhclient -cf /etc/dhcp/dhclient6.conf -6 -P -v <iface>

[Install]
WantedBy=multi-user.target

/etc/systemd/system/dhclient-netplan.service

[Unit]
Description=redo netplan apply after dhclient
Wants=dhclient.service
After=dhclient.service
Before=network.target

[Service]
Type=oneshot
ExecStart=/usr/sbin/netplan apply

[Install]
WantedBy=dhclient.service

该文件在 dhclient.service 改变状态之后执行,注意该 oneshot 不能使用 RemainAfterExit=True,不然在 restart dhclient 以后,不能再次执行 netplan apply。

/etc/netplan/01-netcfg.yaml

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    <iface>:
      dhcp4: yes
      dhcp6: no
      accept-ra: yes
      addresses:
      - <IPv6>/56

即可。

参考资料:

https://documentation.online.net/en/dedicated-server/network/network-configuration-with-netplan
https://documentation.online.net/en/dedicated-server/network/ipv6/prefix
https://askubuntu.com/questions/1031853/how-to-set-up-ipv6-with-netplan-on-ubuntu-18-04?rq=1
https://lafibre.info/scaleway/configurer-une-ipv6-online-net-sur-ubuntu-18-04/
https://unix.stackexchange.com/questions/219940/getting-a-service-started-automatically-when-another-gets-started

Online Dedibox IPv6 配置

Ubuntu 18.04 配置 HE Tunnelbroker

Ubuntu 18.04 配置 Online IPv6》有3个想法

  1. Pingback引用通告: Online 独服 Ubuntu 18.04 关闭默认IPV6并额外配置静态IPV6 | Coldawn

  2. Pingback引用通告: Online.net Dedibox 透過Dibbler使用IPv6地址 | NPCHK Blog

  3. Pingback引用通告: PT实用工具&脚本分享 – 这是一个博客

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注