Get only one IPv6 address on clients question

I dont know for sure if this is openwrt related question,

My openwrt details,

root@OpenWrt:~# ubus call system board
{
        "kernel": "6.6.67",
        "hostname": "OpenWrt",
        "system": "ARMv8 Processor rev 3",
        "model": "Raspberry Pi 4 Model B Rev 1.1",
        "board_name": "raspberrypi,4-model-b",
        "rootfs_type": "ext4",
        "release": {
                "distribution": "OpenWrt",
                "version": "24.10.0-rc4",
                "revision": "r28211-d55754ce0d",
                "target": "bcm27xx/bcm2711",
                "description": "OpenWrt 24.10.0-rc4 r28211-d55754ce0d",
                "builddate": "1734915335"
        }
}

I have below dhcp reservation done in /etc/config/dhcp,

config host
        option dns '1'
        option name 'pinas'
        option mac 'xxxx'
        option ip '192.168.0.195'
        option leasetime '6h'
        option duid 'xxxx'
        option hostid '95'

config host
        option dns '1'
        option name 'raspberrypi'
        option mac 'xxxx'
        option ip '192.168.0.6'
        option leasetime '6h'
        option duid 'xxxxxx'
        option hostid '06'

And everything works (both pinas and raspberrypi computers got IPv6 address ending ::95 and ::6 respectively)

I have a ddns script running on both computers to grab the latest IPv6 address and update against DNS.
The command I used to grab the IPv6 address is,
ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1

Issue is, some times it grab correct IPv6 address I wanted (ending with ending ::95 and ::6) But some times it grab the longer IPv6 address.

ipconfig from both computers,

pi@pinas:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.195  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fd96:870e:ded0:0:c2ed:de96:5e98:4586  prefixlen 64  scopeid 0x0<global>
        inet6 xxxx:xxx:xx:7673:b9c6:ed2b:d8bd:f619  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::8715:e707:9184:e674  prefixlen 64  scopeid 0x20<link>
        inet6 xxxx:xxx:xx:7673::95  prefixlen 128  scopeid 0x0<global>
        inet6 fd96:870e:ded0:0:a84a:a0bb:ba70:b814  prefixlen 64  scopeid 0x0<global>
        inet6 fd96:870e:ded0::95  prefixlen 128  scopeid 0x0<global>
        inet6 xxxx:xxx:xx:7673:fbdf:b2cf:30ae:12e0  prefixlen 64  scopeid 0x0<global>

pi@raspberrypi:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.6  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 xxxx:xxx:xx:7673::6  prefixlen 128  scopeid 0x0<global>
        inet6 fd96:870e:ded0::6  prefixlen 128  scopeid 0x0<global>
        inet6 fd96:870e:ded0:0:215:c936:c3be:6d26  prefixlen 64  scopeid 0x0<global>
        inet6 xxxx:xxx:xx:7673:f6b8:127c:68b9:334  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::dc04:fdf9:d894:680f  prefixlen 64  scopeid 0x20<link>

Is there a way we can make openwrt put only one IPv6 address (the shorter one)?

Please post the full config.

  1. ifconfig is deprecated since 14 years. To get a minmal output with ip use ip -br (brief) like ip -br addr or ip -br link (A full ip even has an flag to output json (-j).

Buuuuuut, on a default setup with openwrt, each client who issues a dhcp-request and gets an answer, will also get an A and/or AAAA record. So why is thisn't working in your setup?


root@OpenWrt:~# cat /etc/config/dhcp

config dnsmasq
        option domainneeded '1'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option cachesize '1000'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
        option localservice '1'
        option ednspacket_max '1232'
        option confdir '/tmp/dnsmasq.d'
        list server '8.8.8.8'
        list server '1.1.1.1'

config dhcp 'lan'
        option interface 'lan'
        option start '200'
        option limit '250'
        option leasetime '12h'
        option dhcpv4 'server'
        option dhcpv6 'server'
        option ra 'server'
        list ra_flags 'managed-config'
        list ra_flags 'other-config'
        option leastime '12h'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'
        option start '100'
        option limit '150'
        option leasetime '12h'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
        option loglevel '4'

config host
        option dns '1'
        option name 'pinas'
        option mac 'xxxxx'
        option ip '192.168.0.195'
        option leasetime '6h'
        option duid 'xxxxx'
        option hostid '95'

config host
        option dns '1'
        option name 'raspberrypi'
        option mac 'xxxx'
        option ip '192.168.0.6'
        option leasetime '6h'
        option duid 'xxxxx'
        option hostid '06'

config host
        option dns '1'
        option name 'mypc'
        option mac 'xxxxxxx'
        option ip '192.168.0.7'
        option leasetime '6h'
        option duid 'xxxxxxxx'
        option hostid '07'
root@OpenWrt:~#

I am not using ifconfig. Using ip command only (as I posted in original post)

For now, I changed my command as below,

ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | sort -Vr | head -n 1

added sort -Vr to get around the issue

Not related but assuming you have a /24 LAN network the total clients cannot exceed 254, you start at 200 and with 250 added you will have 450 which is higher than the max total of 254.
So either start at 100 and limit to 150 or start at 200 and limit to 50

Did you mean start at 100 and limit at 150
or
start at 200 and limit at 250 (that's what I currently have?)

the max total is 254
200 + 250 is 450 and is > 254

Ah I see what you say.
I thought start 200 and limit 250 means, ip address would be between 192.168.0.200 - 192.168.0.250

I will change limit to 50. Which means ip address would be between 192.168.0.200 - 192.168.0.250 correct?
I only have less than 50 clients.

1 Like

Correct indeed :slight_smile:

1 Like

This isn't really an OpenWrt issue. It's normal for IPv6 clients to have multiple addresses. You need to check the relevant IPv6 address options for whatever is running on the clients and make the changes there.

4 Likes

You could disable RA and have the clients only able to take a DHCPv6 address, however that would break clients that do not implement DHCPv6.

What is RA and how to do that?
Does this mean, clients wont get IPv4 address at all? and clients cannot talk to internet websites that run only IPv4?

RA is Router Advertisment. It's an IPv6 mechanism where the router advertises details to allow IPv6 clients to self configure addresses. I wouldn't recommend disabling it. It's better to disable the process on individual clients.

For my understanding (still learning IPv6) if you do not send the A-bit , I assume that that is what is applicable in this situation so that the client does not use SLAAC, how about Android clients which can only use SLAAC, do they still setup a SLAAC IPv6 address?

Uff. Thanks @krazeh, I didn't realized that @simtcrom just wanted to get just one address.

If you disable RA, you can also not use DHPCv6 as far as I'm aware. So only static configured IPv6 at best.

The only real solution here is parsing the output of ip properly and choosing the address you want. Because there are always going to be situations where the network interface has multiple global IPv6 addresses. For example, when the assigned prefix from the ISP changes, there are going to be addresses from both the old and new prefix. Sorting the addresses by lifetime and then picking the shortest one might work.

Devices with a somewhat recent Android version try to obtain a prefix using DHCPv6-PD if SLAAC is not available.

2 Likes

This might be the case but right now, afaik, a IPv6 network needs RA.

2 Likes

Yes, but as mentioned by @egc, it is possible to disable SLAAC by not setting the A flag the RA prefix information (option ra_slaac in OpenWrt).

I wouldn't recommend it, but it still is an option. Personally, I would rather disable DHCPv6 (or just the RA managed flag), and configure static interface identifiers on end devices instead.

1 Like

Are you suggesting setup IPv6 address at client side?
How can I do that, when I don't know what IPv6 address ISP provides?