HarmonyOS鸿蒙Next中如何给开发版配置静态IP,ethernet.setIfaceConfig配置静态IP未生效
HarmonyOS鸿蒙Next中如何给开发版配置静态IP,ethernet.setIfaceConfig配置静态IP未生效 使用ethernet.setIfaceConfig配置静态IP没生效,使用ifconfig查看还是原IP,大佬们有什么方案么?
SDK:OpenHarmony 5.0.0(12)
代码如下:
import { hilog } from '@kit.PerformanceAnalysisKit'
import ethernet from '@ohos.net.ethernet'
import { BusinessError } from '@kit.BasicServicesKit'
let ethConfig: ethernet.InterfaceConfiguration = {
mode: ethernet.IPSetMode.STATIC,
ipAddr: '192.168.5.9',
route: '192.168.5.0',
gateway: '192.168.5.1',
netMask: '255.255.255.0',
dnsServers: '192.168.5.1'
};
hilog.info(0x0000, 'SET_IP', 'ethConfig %{public}s', JSON.stringify(ethConfig));
let setConfigPromise = ethernet.setIfaceConfig('eth0', ethConfig);
setConfigPromise.then(() => {
hilog.info(0x0000, 'SET_IP', 'setIfaceConfig promise ok, promise: %{public}s', JSON.stringify(setConfigPromise));
}).catch((error: BusinessError) => {
hilog.error(0x0000, 'SET_IP', 'set ip error %{public}s', JSON.stringify(error));
});
UnsgnedReleasedProfileTemplate.json配置权限和提高应用等级
"apl":"system_core",
"app-feature":"hos_system_app"
"acls":{
"allowed-acls":[
"ohos.permission.CONNECTIVITY_INTERNAL",
"ohos.permission.GET_NETWORK_INFO"
]
},
更多关于HarmonyOS鸿蒙Next中如何给开发版配置静态IP,ethernet.setIfaceConfig配置静态IP未生效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
可以使用命令行临时修改静态ip或者直接修改配置文件配置静态ip。
更多关于HarmonyOS鸿蒙Next中如何给开发版配置静态IP,ethernet.setIfaceConfig配置静态IP未生效的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
ifconfig是能改的,但我要自动化配置,不能手工一个板子一个板子改。
看到了,已经找到问题了,和内核通讯失败了,没辙了,放弃。
111
在HarmonyOS Next中配置开发板静态IP,需使用ethernet.setIfaceConfig接口。若未生效,检查参数完整性:必须包含ipAddr(IP地址)、route(网关)、netMask(子网掩码)和dnsAddr(DNS)。确认权限已添加ohos.permission.INTERNET。确保网络接口名称正确,如eth0。配置后调用ethernet.setIfaceConfig并验证返回值,成功应返回0。重启网络服务或设备使配置生效。


