Ubuntu Server 20.04 - Netplan configuration for dynamic IPv4 and static IPv6
Solution 1
I finally found my answer on the OVH Community post VPS en IPv6? Gateway?
The correct configuration (for this particular situation) is:
network:
version: 2
ethernets:
ens3:
dhcp4: true
dhcp6: false
match:
macaddress: fa:16:3e:33:8d:59
set-name: ens3
addresses:
- 2402:1f00:8100:400:0:0:0:c1/128
gateway6: 2402:1f00:8100:0400:0000:0000:0000:0001
routes:
- to: 2402:1f00:8100:0400:0000:0000:0000:0001
scope: link
I don't understand why, but the routes
section is needed for netplan to apply a new IPv6 route. gateway6
is not enough.
Solution 2
What did solve all my IPv6 problems with netplan was only have the address defined. Leave out gateway and routes.
Try out this config:
network:
version: 2
ethernets:
ens3:
dhcp4: true
dhcp6: false
match:
macaddress: fa:16:3e:33:8d:59
set-name: ens3
addresses:
- 2402:1f00:8100:400:0:0:0:c1/128
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.
Related videos on Youtube
yaap
Updated on September 18, 2022Comments
-
yaap over 1 year
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
andip route
but I want a permanent configuration using netplan.-
slangasek about 4 yearswhen you say you added it manually, what is the structure of /etc/netplan now? Have you added this under a second file, and with what name? How are you applying the configuration to your system?
-
slangasek about 4 yearsJust as a note, the 'match: name: ens3' should be completely unnecessary.
-
yaap about 4 yearsThanks, @slangasek. I directly replied in my question by adding the section "the try".
-
-
Axel Werner almost 4 yearsjust an untested guess: drop the /128 . try using /64 instead. i guess /128 is a host route. you should get away with just a gateway6 entry.
-
yaap almost 4 yearsHi Axel, thanks for the tip, I will try next time.
-
Nick over 3 yearsI needed the gateway and the route for it to work for me too! Thanks for this :)
-
gene_wood about 3 yearsThis worked for me on my OVH VPS host. I tested it before reboot with
netplan try
. For simplicity of reading I used the short IPv6 syntax which worked fine (2402:1f00:8100:400::c1/128
instead of2402:1f00:8100:400:0:0:0:c1/128
and2402:1f00:8100:0400::1
instead of2402:1f00:8100:0400:0000:0000:0000:0001
) -
Tom Nguyen almost 3 yearsFor OVH dedicated servers, read the Configuring IPv6 on dedicated servers article to find out the correct
gateway6
value.