TL;DR
Does anyone have a working netplan configuration that sets a dynamic IPv4 and a static IPv6 under Ubuntu Server 20.04?
What works
My provider (OVH) gave me a server with this configuration in /etc/netplan/50-cloud-init.yaml
out of the box:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
ens3:
dhcp4: true
match:
macaddress: xx:yy:zz:aa:bb:cc
mtu: 1500
set-name: ens3
So the server is obtaining an IPv4 address through DHCP. Everything works here.
The issue
But, they also gave a static IPv6 (found from the web console management for this server) which is not present in the netplan configuration.
I tried to add it manually, using snippet like:
network:
version: 2
ethernets:
ens3:
dhcp6: false
match:
name: ens3
addresses:
- "dead:beef:404:200::cafe/128"
gateway6: "dead:beef:404:200::1"
But nothing works: if the IPv4 works I have no IPv6, and if I get an IPv6 it revokes my IPv4 and I lose access to the server.
The try
I just tried this exact configuration in /etc/netplan/60-test-askubuntu.yaml
after renamed all other files with .yaml.bak
:
network:
version: 2
ethernets:
ens3:
dhcp6: false
addresses:
- "2001:41d0:206:cd1d::6153/128"
gateway6: "2001:41d0:206:cd1d::1"
dhcp4: true
mtu: 1500
Result: the IPv4 is still working but I guess it will fail when the DHCP bail will be expired. The IPv6 address is set, but the gateway is not set so I cannot ping6 an IPv6 address:
user@server:/etc/netplan$ 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether fa:16:3e:23:28:1f brd ff:ff:ff:ff:ff:ff
inet 51.210.xx.yy/32 scope global dynamic ens3
valid_lft 86396sec preferred_lft 86396sec
inet6 2001:41d0:206:cd1d::6153/128 scope global
valid_lft forever preferred_lft forever
inet6 fe80::f816:3eff:fe23:281f/64 scope link
valid_lft forever preferred_lft forever
user@server:/etc/netplan$ ip route
default via 51.210.8.1 dev ens3 proto dhcp src 51.210.xx.yy metric 100
51.210.8.1 dev ens3 proto dhcp scope link src 51.210.xx.yy metric 100
user@server:/etc/netplan$ ping google.com
PING google.com (172.217.22.142) 56(84) bytes of data.
64 bytes from par21s12-in-f14.1e100.net (172.217.22.142): icmp_seq=1 ttl=51 time=6.16 ms
64 bytes from par21s12-in-f14.1e100.net (172.217.22.142): icmp_seq=2 ttl=51 time=6.19 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 6.161/6.177/6.194/0.016 ms
user@server:/etc/netplan$ ping6 google.com
ping6: connect: Network is unreachable
user@server:/etc/netplan$ ip route
default via 51.210.8.1 dev ens3 proto dhcp src 51.210.xx.yy metric 100
51.210.8.1 dev ens3 proto dhcp scope link src 51.210.xx.yy metric 100
user@server:/etc/netplan$ ip -6 route
::1 dev lo proto kernel metric 256 pref medium
2001:41d0:206:cd1d::6153 dev ens3 proto kernel metric 256 pref medium
fe80::/64 dev ens3 proto kernel metric 256 pref medium
Question
Does anyone have a working netplan configuration for a dynamic IPv4 and a static IPv6?
It works when I set it manually using ip addr
and ip route
but I want a permanent configuration using netplan.
I finally found my answer on the OVH Community post VPS en IPv6? Gateway?
The correct configuration (for this particular situation) is:
I don't understand why, but the
routes
section is needed for netplan to apply a new IPv6 route.gateway6
is not enough.What did solve all my IPv6 problems with netplan was only have the address defined. Leave out gateway and routes.
Try out this config:
Having defined address + gateway breaked up after reboot.
netplan apply
was required after every reboot. And it only worked if I changed the ip6 to another value and back. So it was a completely strange behaviour.Having defined address + gateway + routes did work, but added unnecessary routes.
Having defined address only did the trick. There I played around with the prefix length:
/128
,/64
and/56
. All worked for me on an OVH dedicated server.