我有一台 IP 摄像头,带有以太网端口,连接到一台计算机。摄像头通过以太网线连接到以太网端口,而 PC 通过无线设备连接到互联网。我不想与摄像头共享 wifi,而是想将图像流发送到 NGINx 网络服务器。(我可以处理这个问题,只要我解决了网络问题。)
我曾尝试阅读一些教程,例如:动态主机配置协议 (DHCP)
但是 DHCP 服务器仍然无法在启动时启动。
Here is my current configuration:
# dhcpd.conf
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
# A slightly different configuration for an internal subnet.
subnet 192.168.42.0 netmask 255.255.255.0 {
pool {
range 192.168.42.10 192.168.42.50;
}
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
}
host rear_camera {
hardware ethernet C4:D6:55:3E:4E:72;
fixed-address 192.168.42.15;
option subnet-mask 255.255.255.0;
}
当我尝试手动启动服务时,我得到的结果如下。
$ sudo systemctl restart isc-dhcp-server.service
Job for isc-dhcp-server.service failed because the control process exited with error code.
See "systemctl status isc-dhcp-server.service" and "journalctl -xe" for details.
然后我看看journal -xe
哪个有这个:
Sep 23 04:34:43 linux dhclient[2472]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8
Sep 23 04:34:44 linux NetworkManager[489]: <warn> [1506141284.6473] dhcp4 (eth0): request timed out
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.6479] dhcp4 (eth0): state changed unknown -> timeout
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7137] dhcp4 (eth0): canceled DHCP transaction, DHCP client pid 2472
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7138] dhcp4 (eth0): state changed timeout -> done
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7146] device (eth0): state change: ip-config -> failed (reason 'ip-config-unavail
Sep 23 04:34:44 linux NetworkManager[489]: <warn> [1506141284.7159] device (eth0): Activation: failed for connection 'Wired connection 1'
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7177] device (eth0): state change: failed -> disconnected (reason 'none') [120 30
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7439] policy: auto-activating connection 'Wired connection 1'
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7504] device (eth0): Activation: starting connection 'Wired connection 1' (ccebad
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7525] device (eth0): state change: disconnected -> prepare (reason 'none') [30 40
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7590] device (eth0): state change: prepare -> config (reason 'none') [40 50 0]
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7641] device (eth0): state change: config -> ip-config (reason 'none') [50 70 0]
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7664] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
Sep 23 04:34:44 linux NetworkManager[489]: <info> [1506141284.7710] dhcp4 (eth0): dhclient started with pid 2503
Sep 23 04:34:44 linux dhclient[2503]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 6
Sep 23 04:34:45 linux systemd-networkd[230]: eth0: Gained IPv6LL
Sep 23 04:34:50 linux dhclient[2503]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
Sep 23 04:34:55 linux systemd-networkd[230]: eth0: Lost carrier
Sep 23 04:34:55 linux kernel: rk_gmac-dwmac ff290000.ethernet eth0: Link is Down
Sep 23 04:34:56 linux NetworkManager[489]: <info> [1506141296.3183] device (eth0): link connected
Sep 23 04:34:56 linux kernel: setLedConfiguration: #### before setting led, Reg26 = 0x91 , Reg28 = 0x9200
Sep 23 04:34:56 linux kernel: setLedConfiguration: #### after setting led, Reg26 = 0x91 , Reg28 = 0x9200
Sep 23 04:34:56 linux kernel: rk_gmac-dwmac ff290000.ethernet eth0: Link is Up - 100Mbps/Full - flow control off
Sep 23 04:34:56 linux systemd-networkd[230]: eth0: Gained carrier
Sep 23 04:34:57 linux dhclient[2503]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 14
我尝试使用以下命令在文件中设置界面/etc/default/isc-dhcp-server
:
INTERFACES="eth0"
这没用。我不知道还能做什么。请帮助我进行设置。
答案1
我想到两件事。
- 您没有在
eth0
设置 DHCP 的子网内设置静态 IP。 - 您正在连接相机直接地使用常规直截了当的电缆代替交叉电缆。
您链接的教程非常简单明了,但发布您的配置会更有帮助,/etc/default/isc-dhcp-server
因为它会有很大帮助。
如果您可以再次启动 DHCP 服务,并且当它失败时,立即运行sudo tail -n 50 /var/log/syslog
以及sudo systemctl status isc-dhcp-server.service
(无论哪个有效)并发布结果。
通常,阅读syslog
或输出systemctl status
将准确地告诉您哪里出了问题,而不是记录提供的活动journal -xe
。
该问题可能简单到缺少分号或新行上的缩进不正确,甚至可能是缺少右括号}
。
答案2
好吧,经过一整天的被这些胡言乱语困扰之后,我终于知道问题出在哪里了(我猜)。
我试过交叉电缆,但现在不用了。我还查看了 systemctl 和 syslog 的日志,但无济于事。最终发现这是一个配置错误的/etc/network/interfaces
文件。原始内容如下:
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
请注意,在检查 /etc/network/interfaces 文件之前,我曾尝试使用 和 打开和关闭ifup
eth0 ifdown
。
我查看了其他一些 Linux 机器上的同一个文件,并修改了该文件以反映我在故障计算机上设置的网络选项。
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.0.0.42
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.1
dns-nameservers 10.0.0.1 8.8.8.8
完成这些更改后,我执行了sudo ifdown
eth0,sudo ifup eth0
然后sudo service isc-dhcp-server start
服务启动时没有错误。
我现在可以连接到我的 IP 摄像头和无线网络。