dhcp authoritative参数作用

文章探讨了在遇到DHCP客户端长时间等待IP分配的问题时,如何通过设置DHCP服务器的authoritative参数来解决。该参数使得DHCP服务器在遇到非己分配的IP请求时直接拒绝,从而避免客户端超时,改善网络中多个DHCP服务器的协作。此外,还提及了Android手机热点代码层的修改建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

遇到过这样一个问题,手机作为热点,用笔记本去连接 始终处于分配IP阶段,而其它大多数机器又是可以的。

最后调查发现是authoritative缺失,导致客户端长时间等待dhcp分配ip超时。

authoritative;

指定当一个客户端试图获得一个不是该DHCP服务器分配的IP信息,DHCP将发送一个拒绝消息,而不会等待请求超时。当请求被拒绝,客户端会重新向当前DHCP发送IP请求获得新地址。

当网络中有其他的DHCP服务器时,加上此参数可以忽略其他DHCP服务器。

可把此参数加在dhcp.conf配置文件的第一行。


android手机热点代码层修改:

diff --git a/TetherController.cpp b/TetherController.cpp

index 743742c..32a0b43 100644
--- a/ TetherController.cpp
+++ b/ TetherController.cpp
@@ -96,6 +96,8 @@ bool TetherController::getIpFwdEnabled() {
return (enabled == '1' ? true : false);
}
+#define TETHER_START_CONST_ARG 8
+
int TetherController::startTethering(int num_addrs, struct in_addr* addrs) {
if (mDaemonPid != 0) {
ALOGE("Tethering already started");
@@ -134,19 +136,20 @@ int TetherController::startTethering(int num_addrs, struct in_addr* addrs) {
close(pipefd[0]);
}
- int num_processed_args = 7 + (num_addrs/2) + 1; // 1 null for termination
+ int num_processed_args = TETHER_START_CONST_ARG + (num_addrs/2) + 1;
char **args = (char **)malloc(sizeof(char *) * num_processed_args);
args[num_processed_args - 1] = NULL;
args[0] = (char *)"/system/bin/dnsmasq";
args[1] = (char *)"--keep-in-foreground";
args[2] = (char *)"--no-resolv";
args[3] = (char *)"--no-poll";
+ args[4] = (char *)"--dhcp-authoritative";
// TODO: pipe through metered status from ConnService
- args[4] = (char *)"--dhcp-option-force=43,ANDROID_METERED";
- args[5] = (char *)"--pid-file";
- args[6] = (char *)"";
+ args[5] = (char *)"--dhcp-option-force=43,ANDROID_METERED";
+ args[6] = (char *)"--pid-file";
+ args[7] = (char *)"";
- int nextArg = 7;
+ int nextArg = TETHER_START_CONST_ARG;
for (int addrIndex=0; addrIndex < num_addrs;) {
char *start = strdup(inet_ntoa(addrs[addrIndex++]));
char *end = strdup(inet_ntoa(addrs[addrIndex++]));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值