Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望ipv6地址获取可以根据valid_lft或preferred_lft排序选择 #872

Closed
2 tasks done
ryjer opened this issue Oct 1, 2023 · 5 comments
Closed
2 tasks done
Labels
enhancement New feature or request Stale

Comments

@ryjer
Copy link

ryjer commented Oct 1, 2023

功能描述

根据ip命令中的ipv6相关信息

$ ip -6 addr show ens192
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    altname enp11s0
    inet6 fd00:8214:d450::1234/128 scope global dynamic noprefixroute 
       valid_lft 36214sec preferred_lft 36214sec
    inet6 2408:9e22:6618:8c80::cd9/128 scope global dynamic noprefixroute 
       valid_lft 36214sec preferred_lft 36214sec
    inet6 2408:9e22:6618:8c80:20c:29ff:febb:ca5b/64 scope global dynamic noprefixroute 
       valid_lft 247516sec preferred_lft 161116sec
    inet6 fd00:8214:d450:0:20c:29ff:febb:ca5b/64 scope global noprefixroute 
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:febb:ca5b/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

根据valid_lft (有效使用期限) 和 preferred_lft (首选生存期)信息。可以找出最新分配的ipv6地址,这个最新的ip地址就是最近一次拨号后生成的最新ipv6地址

我希望IPv6功能中通过网卡获取后可以添加根据 valid_lftpreferred_lft剩余时间排序选择的功能,这样可以通过选择剩余时间最长的ipv6进行准确的ddns

解决的问题

家用宽带虽然提供了ipv6公网地址,但是家用宽带会定期进行pppoe重播。
重播会分配不同的ipv6前缀,但局域网内的设备在路由重播后并不会将之前的ipv6前缀删除,而是继续根据新的ipv6前缀生成新的ip。
这样经过几次重播后,局域网设备就会累积大量的ipv6地址,但其中只有1个是可用的。而且这些ipv6地址在ddns-go中的顺序有相当的随意性,无法使用@数字的方式准确选择正确地址

附加信息

No response

检查清单

  • 我已搜索同类问题,并确保没有我要提交的功能
  • 我已使用最新版本,并确保该功能仍未在最新版本中实现
@ryjer ryjer added the enhancement New feature or request label Oct 1, 2023
@jeessy2
Copy link
Owner

jeessy2 commented Oct 1, 2023

感觉可以通过命令获取,脚本自行研究

@yin1999
Copy link
Contributor

yin1999 commented Oct 6, 2023

其实可以考虑使用脚本把旧的IPv6地址删掉(如果路由器支持的话,也可以用路由器主动发送弃用报文),如果不去清除或弃用旧IPv6地址,主机也没法使用默认路由访问外网IPv6服务器。我之前写了一个自动删除旧IPv6地址的脚本:https://gist.github.com/yin1999/cfa50d5b9342380f003631a2ac683ea3

@bingood
Copy link

bingood commented Oct 12, 2023

我是通过命令获取实现如上功能的,你可以试试
ip addr show|grep -v deprecated|grep -A1 'inet6 [^f:]'|grep -v ^--|sed -nr ':a;N;s#^ +inet6 ([a-f0-9:]+)/.+? scope global .*? valid_lft ([0-9]+sec) .*#\2 \1#p;Ta'|sort -nr|head -n1|cut -d' ' -f2

Copy link

This issue is stale because it has been open 30 days with no activity. Remove Stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Nov 12, 2023
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Stale
Projects
None yet
Development

No branches or pull requests

4 participants