找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 6729|回复: 15

ap模式下为路由自动配置ipv6地址

[复制链接]
发表于 2020-2-4 23:19 | 显示全部楼层 |阅读模式
本帖最后由 xyx823 于 2020-2-24 13:27 编辑

尝试我的方法之前,请先看看论坛其他用户给出的解决方案能不能满足你的需求:
1.路由模式下配置成类ap模式,并配置ipv6地址:
https://www.right.com.cn/forum/thread-915587-1-1.html
2.ISP提供的光猫采用RA通告模式下发ipv6地址:
https://www.right.com.cn/forum/thread-876240-1-1.html
因为以上两个不满足我的需求,第一个路由模式又要重新设置一大堆,第二个试了没用。
翻查资料后,发现自动配置IPV6主要就两种方式:RA通告和DHCPV6。其中RA通告是IPV6协议的一部分,俗称原生支持ip地址动态分配。
那既然RA通告不行,只好尝试DHCPV6的途径。ssh登录路由后,发现有dhcp6c这个命令可用,但是要写一个配置文件/etc/dhcp6c.conf,而重启后/etc目录下新建文件又会消失。
这里给出我写的配置文件,详细的可参考https://manpages.ubuntu.com/manp ... /dhcp6c.conf.5.html
####/etc/dhcp6c.conf######
interface br0 {
        send ia-na 1,rapid-commit;
};
id-assoc na 1 {};

####/etc/dhcp6c.conf######
保存配置文件后,运行dhcpv6的客户端:
dhcp6c br0
还需要添加路由:
ip route add default via fe80::1 dev br0

运行以下测试是否配置成功:
ping6 ipv6.baidu.com
这样路由上的服务就能通过ipv6公网访问了!
以下为傻瓜式配置,解决重启后自动配置的问题。

1.进入padavan的管理页面-自定义设置-脚本-在路由器启动后执行,如图:

2.复制以下代码到### Custom user script
### Called after router started and network is ready的下面:
  1. #config ipv6 addr for lan
  2. cat <<'EOF' >/etc/dhcp6c.conf
  3. interface br0 {
  4.         send ia-na 1,rapid-commit;
  5. };
  6. id-assoc na 1 {};
  7. EOF
  8. dhcp6c br0
  9. ip -6 route add default via fe80::1 dev br0
复制代码
3.重启后,ssh到路由器上,使用ping6 ipv6.baidu.com验证是否成功。
================以下内容更新于2020年2月24日===========
上述配置试验一段时间后,发现ipv6地址在一天后大概率丢失。经核验,是ipv6防火墙阻挡了dhcpv6的接收端口,开放udp端口546即可。
  1. ip6tables -A INPUT -s fe80::/10 -d fe80::/10 -p udp -m udp --sport 547 --dport 546 -j ACCEPT
复制代码
但是不能启用自动配置(SLAAC Stateless Address Autoconfiguration),始终让我耿耿于怀。以下揭示为什么上面提到的RA通告试了没用以及开通RA通告后的效果。
使能accept_ra无效的主要原因,出自kernel.org
accept_ra - INTEGER
        Accept Router Advertisements; autoconfigure using them.

        It also determines whether or not to transmit Router
        Solicitations. If and only if the functional setting is to
        accept Router Advertisements, Router Solicitations will be
        transmitted.

        Possible values are:
                0 Do not accept Router Advertisements.
                1 Accept Router Advertisements if forwarding is disabled.
                2 Overrule forwarding behaviour. Accept Router Advertisements
                  even if forwarding is enabled.

        Functional default: enabled if local forwarding is disabled.
                            disabled if local forwarding is enabled.

因为路由器默认使能了转发功能(forwarding),所以仅把accept_ra设成1是无效的。两种解决办法,1.把br0上的转发关闭后再使能accept_ra(关闭了转发,短时间测试未发现其他功能受影响);2.或者直接设置accept_ra为2。
所以解决方法是SSH登录到路由器,写入以下内核参数:

  1. sysctl -w net.ipv6.conf.lo.disable_ipv6=0
  2. sysctl -w net.ipv6.conf.br0.disable_ipv6=0
  3. sysctl -w net.ipv6.conf.br0.use_tempaddr=0                #若要启用临时地址,将此值设置为2。
  4. sysctl -w net.ipv6.conf.br0.accept_ra=2
  5. sysctl -w net.ipv6.conf.br0.accept_ra_pinfo=1
  6. sysctl -w net.ipv6.conf.br0.accept_ra_defrtr=1
  7. sysctl -w net.ipv6.conf.br0.autoconf=1
复制代码

优势是接收到ra通告后,路由会自动配置自己的Ipv6地址和默认网关(不用再执行ip route add命令了),且ISP提供不同的前缀后,路由器为自动更新新IPV6地址。
劣势是ra通告是周期性发的,最快200秒,最慢600秒,不能立竿见影。按道理来说,支持ipv6的路由器上电后,会自动发送solicit报文,然后从上一级路由器获得立即的回复,并自动配置自己的ipv6地址。
这一点没搞出来。。。
如果要自启后,也能接受ra通告配置ipv6地址,按以下步骤添加脚本:
1.进入padavan的管理页面-自定义设置-脚本-在路由器启动后执行,如图:

2.复制以下代码到### Custom user script
### Called after router started and network is ready的下面:
  1. #config ipv6 addr for lan
  2. sysctl -w net.ipv6.conf.lo.disable_ipv6=0
  3. sysctl -w net.ipv6.conf.br0.disable_ipv6=0
  4. sysctl -w net.ipv6.conf.br0.use_tempaddr=0
  5. sysctl -w net.ipv6.conf.br0.accept_ra=2
  6. sysctl -w net.ipv6.conf.br0.accept_ra_pinfo=1
  7. sysctl -w net.ipv6.conf.br0.accept_ra_defrtr=1
  8. sysctl -w net.ipv6.conf.br0.autoconf=1
复制代码

3.拉到页面下面,点击应用页面设置,等待10秒以便写入到flash中。
4.重启路由器,最慢600秒后,ssh到路由器上,使用ping6 ipv6.baidu.com验证是否成功。
如果有大神有更好的方法,希望大神不吝赐教。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
我的恩山、我的无线 The best wifi forum is right here.
发表于 2020-2-5 07:51 | 显示全部楼层
谢谢分享了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-2-5 13:04 | 显示全部楼层
谢谢分享试试看
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-2-5 15:25 | 显示全部楼层
非常感谢楼主的分享!谢谢
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-2-5 15:35 | 显示全部楼层
5 15:31:49 dhcp6c[487]: sendto: Cannot assign requested address 这是日志文件
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-2-6 00:27 | 显示全部楼层
感谢楼主分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-2-7 14:45 | 显示全部楼层
C:\Windows\system32>ping -6 ipv6.baidu.com

正在 Ping ipv6.baidu.com [2400:da00:2::29] 具有 32 字节的数据:
来自 2400:da00:2::29 的回复: 时间=60ms
来自 2400:da00:2::29 的回复: 时间=59ms
来自 2400:da00:2::29 的回复: 时间=60ms
来自 2400:da00:2::29 的回复: 时间=60ms

2400:da00:2::29 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 59ms,最长 = 60ms,平均 = 59ms
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2020-2-17 13:25 | 显示全部楼层
发现一个问题,大概一天后已分配的ipv6地址会被dhcpv6移除,也不增加新的。重开dhcpv6也获取不到ipv6地址,但是重启路由器后就能。在此记录一下。

点评

发现问题出在防火墙上,ip6tables里开放udp546端口即可。至少重开dhcpv6也可以再次获取到ipv6地址了。 ip6tables -A INPUT -s fe80::/10 -d fe80::/10 -p udp -m udp --sport 547 --dport 546 -j ACCEPT  详情 回复 发表于 2020-2-22 22:12
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2020-2-22 22:12 | 显示全部楼层
xyx823 发表于 2020-2-17 13:25
发现一个问题,大概一天后已分配的ipv6地址会被dhcpv6移除,也不增加新的。重开dhcpv6也获取不到ipv6地址, ...

发现问题出在防火墙上,ip6tables里开放udp546端口即可。至少重开dhcpv6也可以再次获取到ipv6地址了。
ip6tables -A INPUT -s fe80::/10 -d fe80::/10 -p udp -m udp --sport 547 --dport 546 -j ACCEPT
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2020-2-24 20:34 | 显示全部楼层
如果ra和dhcp6c一起用的话,前缀变了后会频繁出现以下报错:
Feb 24 20:29:09 dhcp6c[515]: status code for identity association-1: no binding
Feb 24 20:29:09 dhcp6c[515]: receive NoBinding against renew/rebind for identity association-1
Feb 24 20:29:09 dhcp6c[515]: status code for identity association-1: not on-link
Feb 24 20:29:09 dhcp6c[515]: T1(0) and/or T2(0) is locally determined
Feb 24 20:29:09 dhcp6c[515]: T1 (0) or T2 (0) is too small
Feb 24 20:29:09 dhcp6c[515]:  adjusted to 18 and 30
意思是,前缀已改变,原地址不准续约,但dhcp6c又不知道新地址是什么。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-2-24 22:41 | 显示全部楼层
本帖最后由 yecao 于 2020-3-8 19:10 编辑

谢谢分享! 不过不能通过此IP地址进入路由器管理页面。

点评

你后来弄好了吗  详情 回复 发表于 2023-7-14 17:25
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-3-1 06:44 来自手机 | 显示全部楼层
不错的,谢谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2021-3-20 23:14 | 显示全部楼层
非常感谢,试一下
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2023-1-24 20:25 | 显示全部楼层
非常感谢,用ra方案可以得到ipv6了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2023-1-24 20:25 | 显示全部楼层
非常感谢,用ra方案可以得到ipv6了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-25 18:45

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表