RouterOS DHCP-Server配置Vendor Classes
从v6.45beta6开始,RouterOS的DHCP Server支持对vendor class id进行配匹,可通过DHCP客户端的厂商ID选择指定的地址池。下面的实例,基于三星Android手机提供一个指定IP地址池。
首先,路由器已经有192.168.88.1/24的IP配置到bridge接口,需区分不同厂商设备class id,创建一个新的IP地址段,在/ip addres下为bridge接口添加一个IP地址172.16.16.1/24
/ip address add address=172.16.16.1/24 interface=bridge
创建普通客户端pool的地址池
/ip pool add name=default-dhcp ranges=192.168.88.10-192.168.88.254
新建一个pool-for-VID地址池,分配IP地址172.16.16.10-172.16.16.120
/ip pool
add name=pool-for-VID ranges=172.16.16.10-172.16.16.120
配置普通客户端的DHCP规则
/ip dhcp-server add address-pool=default-dhcp disabled=no interface=bridge name=defconf /ip dhcp-server network add address=192.168.88.0/24 comment=defconf gateway=192.168.88.1 dns-server=192.168.88.1
根据三星手机vendor-class-id ,创建一个新的规则配匹vid=android-dhcp-9,并调用pool-for-VID地址池
/ip dhcp-server vendor-class-id add address-pool=pool-for-VID name=samsung server=defconf vid=android-dhcp-9
为三星手机创建新的network策略
/ip dhcp-server network add address=172.16.16.0/24 comment=defconf gateway=172.16.16.1 dns-server=172.16.16.1
当三星手机连接到DHCP后,会从172.16.16.0网段中分配IP
[admin@mikrotik] > /ip dhcp-server lease print detail Flags: X - disabled, R - radius, D - dynamic, B - blocked 0 D address=172.16.16.120 mac-address=30:07:4D:F5:07:49 client-id="1:30:7:4d:f5:7:49" address-lists="" server=defconf dhcp-option="" status=bound expires-after=8m55s last-seen=1m5s active-address=172.16.16.120 active-mac-address=30:07:4D:F5:07:49 active-client-id="1:30:7:4d:f5:7:49" active-server=defconf host-name="Galaxy-S8"
如果你不知道各个厂商设备的Vendor Class ID,可以开启DHCP debug,在日志中查看,创建DHCP debug日志配置如下命令:
[admin@mikrotik]/system logging add topics=dhcp
这是当客户端获取DHCP服务器IP地址时,会在/logs显示信息,通过查看 Class-ID 得到Vendor Class ID
10:30:31 dhcp,debug,packet defconf received request with id 4238230732 from 0.0.0.0
10:30:31 dhcp,debug,packet secs = 3
10:30:31 dhcp,debug,packet ciaddr = 0.0.0.0
10:30:31 dhcp,debug,packet chaddr = 30:07:4D:F5:07:49
10:30:31 dhcp,debug,packet Msg-Type = request
10:30:31 dhcp,debug,packet Client-Id = 01-30-07-4D-F5-07-49
10:30:31 dhcp,debug,packet Address-Request = 172.16.16.120
10:30:31 dhcp,debug,packet Server-Id = 192.168.88.1
10:30:31 dhcp,debug,packet Max-DHCP-Message-Size = 1500
10:30:31 dhcp,debug,packet Class-Id = "android-dhcp-9"
10:30:31 dhcp,debug,packet Host-Name = "Galaxy-S8"
以上是官方三星Galaxy-S8手机的class-Id为android-dhcp-9
下面是我从log中获取华为mate30的class-id
10:43:14 dhcp,debug,packet tsecs = 4
10:43:14 dhcp,debug,packet tciaddr = 0.0.0.0
10:43:14 dhcp,debug,packet tMsg-Type = request
10:43:14 dhcp,debug,packet tAddress-Request = 192.168.80.19
10:43:14 dhcp,debug,packet tServer-Id = 192.168.80.1
10:43:14 dhcp,debug,packet tMax-DHCP-Message-Size = 1500
10:43:14 dhcp,debug,packet tClass-Id = "HUAWEI:android:TAS"
10:43:14 dhcp,debug,packet tHost-Name = "HUAWEI_Mate_30_5G-7203a0c"
文章很值,打赏犒劳作者一下