问题描述

Surge 在正常运行过程中出现此问题,如下图:

surge-error

DHCP 日志如下:

Internet Systems Consortium DHCP Server 4.4.2
Copyright 2004-2020 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Config file: /Users/USERNAME/Library/Application Support/com.nssurge.surge-mac/dhcpd/dhcpd.conf
Database file: /Users/USERNAME/Library/Application Support/com.nssurge.surge-mac/dhcpd/lease
PID file: /Users/USERNAME/Library/Application Support/com.nssurge.surge-mac/dhcpd/pid
Wrote 0 deleted host decls to leases file.
Wrote 0 new dynamic host decls to leases file.
Wrote 65 leases to leases file.
Listening on BPF/en4/00:0e:c6:c2:35:54/192.168.31.0/24
Sending on   BPF/en4/00:0e:c6:c2:35:54/192.168.31.0/24
Can't bind to dhcp address: Address already in use
Please make sure there is no other dhcp server
running and that there's no entry for dhcp or
bootp in /etc/inetd.conf.   Also make sure you
are not running HP JetAdmin software, which
includes a bootp server.

If you think you have received this message due to a bug rather
than a configuration issue please read the section on submitting
bugs on either our web page at www.isc.org or in the README file
before submitting a bug.  These pages explain the proper
process and the information we find helpful for debugging.

exiting.

解决方法

查看 DHCP 占用

zhaochunqi in 🌐 Alexs-MacBook-Pro in ~ 
❯ sudo lsof -i :67
COMMAND  PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
launchd    1 root   15u  IPv4 0xe266e99ee0d4eae7      0t0  UDP *:bootps
launchd    1 root   25u  IPv4 0xe266e99ee0d4eae7      0t0  UDP *:bootps
launchd    1 root   54u  IPv4 0xe266e99ee0d4eae7      0t0  UDP *:bootps
launchd    1 root   55u  IPv4 0xe266e99ee0d4eae7      0t0  UDP *:bootps
bootpd  3970 root    0u  IPv4 0xe266e99ee0d4eae7      0t0  UDP *:bootps
bootpd  3970 root    1u  IPv4 0xe266e99ee0d4eae7      0t0  UDP *:bootps
bootpd  3970 root    2u  IPv4 0xe266e99ee0d4eae7      0t0  UDP *:bootps

可以看到 launchdbootpd 进程正在使用端口 67,这意味着两个端口可能存在冲突。但是之前已经多次 kill 3970 这个进程,但没有效果,需要处理掉 PID 为 1 的这个进程。

禁用开启启动服务

如果 bootpd 是一个服务,应该使用以下命令禁用它:

sudo launchctl unload -w /System/Library/LaunchDaemons/bootps.plist

这指的是关闭 bootpd 进程的开机启动。此步骤可能因 MacOS 版本而异。运行命令后,如果系统中没有这个文件或者服务,也请检查 /Library/LaunchDaemons/Library/LaunchAgents 目录,看看是否存在相关的服务。

通过上述方法成功解决了问题!

题外

之前在 Surge 社区问了一下,得到作者回复,但是没有完全解决问题,后续我发现了解决方法补充到了社区。

https://community.nssurge.com/d/1823-surge-dhcp