路由联盟

3-Openwrt ipv6之-odhcpd服务器

2020-07-07  本文已影响0人  Creator_Ly

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'

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


这时候,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

上一篇下一篇

猜你喜欢

热点阅读