3-Openwrt ipv6之-odhcpd服务器

16 篇文章 8 订阅

openwrt上面的dhcpv6服务器package一般使用odhcpd,里面即包含了有状态的dhcpv6服务器,也包含了无状态的ra服务器。

1.odhcpd服务器启动过程

开启config配置

CONFIG_PACKAGE_odhcpd=y
CONFIG_PACKAGE_odhcpd_ext_prefix_class=0
CONFIG_PACKAGE_odhcpd_ext_cer_id=0

etc/init.d/odhcpd会启动服务器进程

#!/bin/sh /etc/rc.common

START=35
STOP=85
USE_PROCD=1

start_service() {
    procd_open_instance
    procd_set_param command /usr/sbin/odhcpd
    procd_set_param respawn
    procd_close_instance
}

service_triggers()
{
    procd_add_reload_trigger "dhcp"
}

odhcpd进程里面回去读/etc/config/dhcp uci的值

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option force '1'
        option dhcpv6 'server'
        option ra 'server'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
  • option dhcpv6 'server’表示启动dhcpv6 server
  • option ra 'server’表示启动ra/SLACC server

uci的全部设置值在网址:https://openwrt.org/docs/techref/odhcpd
下可以看到全部的,这边介绍一部分用到的。

odhcpd的参数基本不会变,如下:

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'  # DHCP/v6 lease/hostfile
        option leasetrigger '/usr/sbin/odhcpd-update'  # Lease trigger script

dhcp的参数如下:

Sections of type dhcp (configure DHCP / DHCPv6 / RA / NDP service)

Option		Type	Default			Description
interface	string	<name of UCI section>	logical OpenWrt interface
ifname		string	<resolved from logical>	physical network interface
ignore		bool	0			do not serve this interface
						unless overridden by ra, ndp,
						dhcpv4 or dhcpv6 options
master		bool	0			is a master interface
						for relaying

ra		string	disabled		Router Advert service
		[disabled|server|relay|hybrid]
dhcpv6		string	disabled		DHCPv6 service
		[disabled|server|relay|hybrid]
dhcpv4		string	disabled		DHCPv4 service
		[disabled|server]
ndp		string	disabled		Neighbor Discovery Proxy
		[disabled|relay|hybrid]

dynamicdhcp	bool	1			dynamically create leases
						for DHCPv4 and DHCPv6
dns		list	<local address>		DNS servers to announce
						accepts IPv4 and IPv6
domain		list	<local search domain>	Search domains to announce

ra_default	integer	0			Override default route
		                                0: default 
                                                1: ignore no public address 
                                                2: ignore all
ra_management	integer	1			RA management mode
		                                0: no M-Flag but A-Flag
                                                1: both M and A 
                                                2: M but not A
ra_offlink	bool	0			Announce prefixes off-link
ra_preference	string	medium			Route(r) preference
		[medium|high|low]

ra_maxinterval   integer 600	                Maximum time allowed between
				                sending unsolicited RA
ra_mininterval   integer 200	                Minimum time allowed between
				                sending unsolicited RA
ra_lifetime 	 integer 1800	                Value to be placed in Router
				                Lifetime field of RA
ra_useleasetime  bool	 0  	                Use configured leasetime as
				                limit for the preferred and
				                valid lifetime of a prefix
ra_reachabletime integer 0  	                Reachable Time in milliseconds to be
				                advertised in RA messages
ra_retranstime   integer 0  	                Retransmit Time in milliseconds to be
				                advertised in RA messages
ra_hoplimit 	 integer 0  	                Current hoplimit to be advertised
				                in RA messages
ra_mtu           integer 0  	                MTU to be advertised in
                                                RA messages

ndproxy_routing	bool	1			Learn routes from NDP
ndproxy_slave	bool	0			NDProxy external slave
ndproxy_static	list				Static NDProxy prefixes

host的参数如下:

Sections of type host (static leases)
Option		Type	Default			Description
ip		string				IP-Address to lease
mac		string				MAC-address
duid		string				DUID in base16
hostid		string				IPv6 host identifier
name		string				Hostname
2. dhcpv6=server,ra=disabled

dhcpv6在server模式支持全部的模式:stateless, stateful and PD-server mode

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option force '1'
        option dhcpv6 'server'
        option ra 'disabled'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

win电脑连接路由器后,电脑会向路由器的odhcpd服务器申请地址,路由器的地址为2001:db8:0:1::254/128,分配给win的地址为2001:db8:0:f00::3c3/128

root@zihome:/# cat /tmp/hosts/odhcpd 
2001:db8:0:f00::3c3     DESKTOP-761V91F
# br-lan 000100012426e0d18cec4bcb4202 98cec4b DESKTOP-761V91F 1589774825 3c3 128 2001:db8:0:f00::3c3/128

在win上面可以通过ipconfig/all查看

C:\Users\SZTEST_>ipconfig/all

以太网适配器 以太网:

   连接特定的 DNS 后缀 . . . . . . . : lan
   描述. . . . . . . . . . . . . . . : Realtek PCIe GBE Family Controller
   物理地址. . . . . . . . . . . . . : 8C-EC-4B-CB-42-02
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是
   IPv6 地址 . . . . . . . . . . . . : 2001:db8:0:f00::3c3(首选)
   获得租约的时间  . . . . . . . . . : 2020年5月18日 11:42:46
   租约过期的时间  . . . . . . . . . : 2020年5月18日 11:54:39
   本地链接 IPv6 地址. . . . . . . . : fe80::a9f1:2e40:14e2:6a01%22(首选)
   IPv4 地址 . . . . . . . . . . . . : 192.168.18.172(首选)
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   获得租约的时间  . . . . . . . . . : 2020年5月18日 11:22:05
   租约过期的时间  . . . . . . . . . : 2020年5月18日 23:42:31
   默认网关. . . . . . . . . . . . . : 192.168.18.1
   DHCP 服务器 . . . . . . . . . . . : 192.168.18.1
   DHCPv6 IAID . . . . . . . . . . . : 160230475
   DHCPv6 客户端 DUID  . . . . . . . : 00-01-00-01-24-26-E0-D1-8C-EC-4B-CB-42-02
   DNS 服务器  . . . . . . . . . . . : 2001:db8:0:f00::1
                                       192.168.18.1
   TCPIP 上的 NetBIOS  . . . . . . . : 已启用
   连接特定的 DNS 后缀搜索列表:
                                       lan

win电脑后面就会定期的发送Renew,服务器返回Relay

3. dhcpv6=server,ra=server

  • ubuntu把isc-dhcp和radvd服务器都开起来
  • 路由器也把dhcpv6和ra两个服务器都开起来

这时候,odhcp6c可以获取到两个地址,一个dhcpv6分配的地址,一个通过RA协议自己算出的地址。

root@zihome:/# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 08:10:7B:A7:26:3C  
          inet6 addr: 2016:ac11:5cad:0:a10:7bff:fea7:263c/64 Scope:Global
          inet6 addr: fe80::a10:7bff:fea7:263c/64 Scope:Link
          inet6 addr: 2001:db8:0:1::254/128 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2288 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5709 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:387179 (378.1 KiB)  TX bytes:830273 (810.8 KiB)
3. dhcpv6=disabled,ra=server

路由器上面ra为server,dhcpv6为disabled

ubuntu上面只开启isc-dhcp服务器,关闭radvd服务器

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option force '1'
        option ra 'server'
        option dhcpv6 'disabled'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'
4. dhcpv6=realy,ra=realy

对于路由器的中继模式,按照教程的设置一直没有成功,不知道是不是理解有问题。

# cat /etc/config/dhcp
config dhcp wan
    option dhcpv6 relay
    option ra relay
    option ndp relay
    option master 1
 
config dhcp lan
    option dhcpv6 relay
    option ra relay
    option ndp relay

https://www.v2ex.com/t/176040
https://dev.archive.openwrt.org/ticket/16923

5.设备管理查看

也可以用ubus命令获取

ubus call dhcp ipv6leases

https://openwrt.org/zh/docs/guide-user/base-system/dhcp_configuration

http://www.test-ipv6.com/

https://github.com/openwrt/odhcpd

https://openwrt.org/docs/guide-user/network/ipv6/start

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenWRT中获取IPv6地址的步骤如下: 1. 首先,确保你的光猫已经设置为桥接模式,并且路由器已经成功进行了PPPoE拨号。 2. 登录到OpenWRT的管理界面。 3. 在管理界面中,找到网络设置或网络接口的选项。 4. 找到WAN口的设置选项,并点击进入。 5. 在WAN口设置中,你应该能够找到IPv6相关的设置选项。 6. 确保IPv6设置中的RA服务和DHCPv6服务都被设置为服务器模式,并且NDP代理已经被禁用。 7. 在IPv6设置中,你可以设置LAN口的IPv6分配长度。一般来说,你可以选择大于60小于等于64的数字,但建议直接使用64。 8. 如果你需要自定义IPv6 DNS服务器,你可以在相应的设置选项中添加你的DNS服务器。 9. 保存并应用你的设置。 通过以上步骤,你应该能够成功获取到OpenWRT路由器的IPv6地址。请注意,具体的界面和选项可能会因为不同的OpenWRT版本而有所不同,所以请根据你的实际情况进行相应的设置。 #### 引用[.reference_title] - *1* [OpenWrt 软路由 IPV6设置](https://blog.csdn.net/mshxuyi/article/details/129340914)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [OpenWRT开启IPv6教程](https://blog.csdn.net/axxxwo/article/details/128759475)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [OpenWrtIPv6设置详解](https://blog.csdn.net/a924282761/article/details/129067001)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值