Community discussions

MikroTik App
 
ajgnet
newbie
Topic Author
Posts: 35
Joined: Wed Apr 27, 2022 1:57 am

How can I create a IPv6 /64 prefix from dhcpv6 client provided /56 prefix

Tue Oct 04, 2022 2:24 am

I'm trying to create a script in my dhcpv6 client that adds an nd prefix for my LAN (a ::/64) from my ISP provided /56. How can I do this? I was thinking of something like:
:if ($"pd-valid" = 1) do={ 
   :local lan_vz ([:pick $"pd-prefix" 0 19] . "::/64");
   /ipv6 nd prefix add interface=sfp-sfpplus1-LAN prefix=$"lan_vz" comment="VZLAN";
}
but this doesn't work, and it wouldn't work for ::/56 prefixes where there are abbreviated IPs. Any working examples would be extremely appreciated! Thank you
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: How can I create a IPv6 /64 prefix from dhcpv6 client provided /56 prefix

Tue Oct 04, 2022 5:07 am

You know that IPv6 address has from-pool parameter that can do it automatically, right?

If that's not good enough for some reason, you can get some ideas from this script (I don't exactly recommend it as whole):

viewtopic.php?p=911478#p911478
 
ajgnet
newbie
Topic Author
Posts: 35
Joined: Wed Apr 27, 2022 1:57 am

Re: How can I create a IPv6 /64 prefix from dhcpv6 client provided /56 prefix

Tue Oct 04, 2022 1:37 pm

I solved this by adding the below to my DHCPv6 Client Advanced Configuration:
:if ($"pd-valid" = 1) do={ 
  
   :local lanVZ ([:pick $"pd-prefix" 0 [:find $"pd-prefix" "/"]]."/64");
   :log info "VZ value is $lanVZ";
   /ipv6 nd prefix set interface=sfp-sfpplus1-LAN prefix=$"lanVZ" [find prefix~"2600:4041"]
   /ipv6 nd prefix add interface=sfp-sfpplus1-LAN prefix=$"lanVZ";
}
This way my LAN network is always provided a correct /64 prefix from my dynamic ISP assigned /56 via neighbor discovery. The IPv6 address from my ISP always begins with 2600:4041 so I use that to identify if the prefix needs to be added (removed for some reason) or updated (what usually happens). This is a bit of a hack but I can't figure out a better way to do this yet. Hope this helps someone.
 
ajgnet
newbie
Topic Author
Posts: 35
Joined: Wed Apr 27, 2022 1:57 am

Re: How can I create a IPv6 /64 prefix from dhcpv6 client provided /56 prefix

Tue Oct 04, 2022 1:38 pm

You know that IPv6 address has from-pool parameter that can do it automatically, right?
Not sure I know what that is. I saw a "from pool" option in the dhcpv6 server but I'm not using dhcpv6 on my LAN only neighbor discovery. Is there a better way to do this??
If that's not good enough for some reason, you can get some ideas from this script (I don't exactly recommend it as whole):

viewtopic.php?p=911478#p911478
Thanks! This was super helpful
 
biomesh
Long time Member
Long time Member
Posts: 561
Joined: Fri Feb 10, 2012 8:25 pm

Re: How can I create a IPv6 /64 prefix from dhcpv6 client provided /56 prefix

Tue Oct 04, 2022 1:50 pm

Basic config

dhcp client on the wan interface saving pd to a pool
/ipv6 dhcp-client
add add-default-route=yes interface=wan pool-name=comcast_ipv6 \
    prefix-hint=::/60 request=address,prefix use-peer-dns=no
ip address/prefix (::/64) assigned from the pd pool
/ipv6 address
add from-pool=comcast_ipv6 interface=vlan10
add from-pool=comcast_ipv6 interface=vlan500
 
ajgnet
newbie
Topic Author
Posts: 35
Joined: Wed Apr 27, 2022 1:57 am

Re: How can I create a IPv6 /64 prefix from dhcpv6 client provided /56 prefix

Tue Oct 04, 2022 2:17 pm

hah, oh wow that saves me a lot of time. thanks so much. but stupid question - it looks like when I do it this way the valid lifetime is 30 days and there isn't a way to change that. My ISP changes my prefix regularly and if there's a reboot or refresh/renew of the IPv6 address on my router the prefix changes and clients will still use the old prefix. Is there a way to fix that?

with my method I was able to specify the valid lifetime to 5 minutes so clients would refresh their ipv6 address more quickly (invalidate the old address)

edit: solved this with
[adm@gw01] /ipv6/nd/prefix/default> print
autonomous: yes
valid-lifetime: 5m
preferred-lifetime: 2m30s
mikrotik is so good - thanks guys

Who is online

Users browsing this forum: wirelesslywired and 9 guests