我已通过两个以太网电力线适配器 TP-Link TL-PA4010 将 HikVision 摄像机连接到树莓派。
我已将树莓派的 eth0 接口配置为静态 IP 地址。在/etc/dhcpcd.conf
:
interface eth0
static ip_address=192.168.0.10/24
我已经使用 dnsmasq 配置了一个 DHCP 服务器,其配置如下:
# Disable DNS
port=0
# Configuring the DHCP server
interface=eth0
dhcp-leasefile=/var/lib/misc/dnsmasq.leases
# The MAC address of the IP camera
dhcp-host=xx:xx:xx:xx:xx:xx,192.168.0.11
# I've added this later, didn't do anything
dhcp-authoritative
# Some logging
log-dhcp
log-queries
log-facility=/var/log/dnsmasq.log
此设置短暂地起作用了,我可以从中获取图像。但现在相机无法连接:无法获取 IP。它正确连接到我的家庭网络,我可以加载相机的网页。尝试将相机重置为出厂默认设置并重新配置 DHCP,但没有成功。
尝试使用 tcmdump 捕获通过 eth0 的数据包,我看到一些来自摄像头的流量,一些与路由器请求相关的内容和一些其他内容,但我还看到:
17:46:36.725552 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from xx:xx:xx:xx:xx:xx (oui Unknown), length 284
17:46:39.726180 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from xx:xx:xx:xx:xx:xx (oui Unknown), length 284
17:46:42.727918 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from xx:xx:xx:xx:xx:xx (oui Unknown), length 284
我已经使用 dhcpdump 过滤了日志,这就是我看到的全部,在 eth0 上的其他流量中,这些是唯一与 DHCP 相关的。
但 dnsmasq 没有给出任何答复。dnsmasq 的日志中没有任何内容:
Apr 29 17:33:57 dnsmasq[590]: started, version 2.85 DNS disabled
Apr 29 17:33:57 dnsmasq[590]: compile time options: IPv6 GNU-getopt DBus no-UBus i18n IDN2 DHCP DHCPv6 no-Lua TFTP conntrack ipset auth cryptohash DNSSEC loop-detect inotify dumpfile
/var/lib/dhcp/dhclient.leases
我根据在网上读到的内容,删除了租约文件( ),该文件最初包含我之前成功尝试的条目。
服务运行正常:
● dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server
Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-04-29 17:33:57 CEST; 15min ago
Process: 538 ExecStartPre=/etc/init.d/dnsmasq checkconfig (code=exited, status=0/SUCCESS)
Process: 570 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=0/SUCCESS)
Process: 594 ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf (code=exited, status=0/SUCCESS)
Main PID: 590 (dnsmasq)
Tasks: 1 (limit: 779)
CPU: 435ms
CGroup: /system.slice/dnsmasq.service
└─590 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsmasq -r /run/dnsmasq/resolv.conf -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new --local-service --trust-anchor=.,20326,8,2,e06d44b80b8f1d3>
Apr 29 17:33:55 raspberrypi systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
Apr 29 17:33:57 raspberrypi systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.
我认为问题出在以下事实:
- 我们看到了流量,所以 PL 适配器正在工作
- 摄像头可以从我的互联网网关的 DHCP 服务器获取 IP
Raspberry 运行的是 raspbian (Debian GNU/Linux 11 (bullseye)),非常标准。没有防火墙(至少据我所知)。
pi@raspberrypi:~ $ sudo systemctl stop firewall
Failed to stop firewall.service: Unit firewall.service not loaded.
我已经束手无策了。您知道问题出在哪里吗?我还可以进一步调查什么?
答案1
您的dnsmasq
配置没有DHCP
正确提供服务,只需DHCP
在配置文件中指定范围和其他选项dnsmasq
,例如:
port=0
interface=eth0
dhcp-range=192.168.0.11,192.168.0.20,255.255.255.0,1h
dhcp-option=3,192.168.0.10 # Gateway
dhcp-option=6,8.8.8.8,8.8.4.4 # DNS servers
dhcp-leasefile=/var/lib/misc/dnsmasq.leases
dhcp-authoritative
log-dhcp
log-queries
log-facility=/var/log/dnsmasq.log
我们重新启动,它应该可以工作sudo systemctl restart dnsmasq
如果仍然存在问题,请检查您的 Raspberry Pi 上是否正在运行另一个 DHCP 服务器sudo systemctl list-units --type=service | grep -i dhcp
并将其禁用。