安装环境

软路由机器架构: x86_64
OpenWrt版本: 22.03
OpenWrt的IP: 192.168.88.3 (如果不同,后面涉及此地址全部需要修改)
主路由器的地址: 192.168.88.1(如果不同,后面涉及此地址全部需要修改)


目标

按下文配置好网关后,指定的设备走软路由,其余设备主软路由


0. 关闭主路由的DHCP

请参考主路由器的说明,关闭主路由的DHCP


1. 配置DHCP

使用putty登录openWrt,然后按顺序执行以下命令(大小写勿输错)

首先在DHCP文件中添加一个tag,

uci set dhcp.iot='tag'
uci add_list dhcp.iot.dhcp_option='6,8.8.4.4,114.114.114.114'
uci add_list dhcp.iot.dhcp_option='3,192.168.88.1'
uci set dhcp.iot.force='1'
uci commit dhcp

单独为每一个主机配置一个,其中设备名称自定义,MAC地址不区分大小写

uci add dhcp host
uci commit dhcp

uci set dhcp.@host[0].dns='1'
uci set dhcp.@host[0].ip='IP地址1'  
uci set dhcp.@host[0].leasetime='infinite'
uci set dhcp.@host[0].name='设备名称1'
uci set dhcp.@host[0].mac='MAC地址1'
uci set dhcp.@host[0].tag='iot'
uci commit dhcp

uci add dhcp host
uci commit dhcp

uci set dhcp.@host[1].dns='1'
uci set dhcp.@host[1].ip='IP地址2'  
uci set dhcp.@host[1].leasetime='infinite'
uci set dhcp.@host[1].name='设备名称2'
uci set dhcp.@host[1].mac='MAC地址2'
uci set dhcp.@host[1].tag='iot'
uci commit dhcp

uci add dhcp host
uci commit dhcp

uci set dhcp.@host[2].dns='1'
uci set dhcp.@host[2].ip='IP地址3'  
uci set dhcp.@host[2].leasetime='infinite'
uci set dhcp.@host[2].name='设备名称3'
uci set dhcp.@host[2].mac='MAC地址3'
uci set dhcp.@host[2].tag='iot'
uci commit dhcp

指定设备配置结束后,重启dhcp,然后设备重新连接无线即可。

service dhcp restart

3. 说明

如何查看设备的MAC地址

  • iPhone
    设置->无线局域网->无线局域网地址

  • Windows操作系统
    开始->运行->输入cmd,执行ipconfig /all 命令,物理地址就是MAC地址


全文完