How to set a static IPv6 default route with dhcpcd

dhcpcdnetworkingroute

I am going to set a static IPv6 address and a corresponding IPv6 default route with dhcpcd. I have looked through man dhcpcd.conf, but to find nowhere mentioning how to set an IPv6 default route.

My current dhcpcd.conf:

hostname
duid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option interface_mtu
require dhcp_server_identifier

interface eth0
noipv6rs
static ip6_address=2001:xxx::xxx/128

What I want dhcpcd to do is:

ip addr add 2001:xxx::xxx/112 dev eth0
ip -6 route add 2001:xxx::xxxx dev eth0
ip -6 route add default via 2001:xxx::xxxx

However, with my current configuration, dhcpcd does only the first two lines for me but not the third line.

man dhcpcd.conf only tells that an IPv4 default router can be set via something like static routers=192.168.0.1.

I know it can be done by ip -6 route add manually, using hooks of dhcpcd, or simply put aside dhcpcd. But I rely on dhcpcd to handle DHCPv4. And I think it would less messy if dhcpcd can handle both IPv4 and IPv6 configurations.

My question:

Is there a more direct way where dhcpcd sets the IPv6 default route automatically by specifying some options / commands in dhcpcd.conf?

Best Answer

You cannot use DHCPv4 to give out default IPv6 routes. You cannot even use DHCPv6 to give out default IPv6 routes.

The reason is that IPv6 is different from IPv4 in many respects, and one of them is how routers behave: Every IPv6 router announces itself as gateway to the segment which can use it as gateway. And you can have multiple routers for segment, it's not restricted to a single gateway as in IPv4.

Therefore, this doesn't happen by exchanging DHCP broadcasts and replies, but instead it happens by exchanging router solicitation (RS) and router advertisement (RA) messages between hosts and routers, as defined in the IPv6 Neighbour Discovery Protocol.

So the only way to make your IPv6 hosts configure themselves with the right route is to run radvp (properly configured) in addition to dhcpd on your router/gateway. While you are at it, you can enable RS messages again (delete noipv6rs), because if Linux considers itself a router (forwarding is enabled) it won't (or at least shouldn't) send out RS messages.

And using radvp is actually the "less messy" way - it allows you to add routers to or remove routers from your segment without having to update a central configuration file.

In addition, stateless autoconfiguration (SLAAC) will allow your hosts to generate IPv6 addresses from the routeable prefixes themselves.

Related Question