Windows:重新启动时网络接口号更改

发布于 2025-01-30 06:00:47 字数 238 浏览 2 评论 0原文

我想将路线添加到网络,从原则上讲,它可以正常工作。 但是,接口号一直在变化,因此我需要在重新启动后修改路线。

示例:

route ADD 10.0.0.0 MASK 255.0.0.0 8.8.8.8 METRIC 5 IF 14

这起作用,直到接口ID从更改为14为,如果15 。 是否可以将接口编号固定,或者如果没有,则可以从接口名称中动态检索接口号。

I want to add routes to a network and in principle it works fine.
However, the interface numbers keep changing and so I need to adapt the routes after every reboot.

Example:

route ADD 10.0.0.0 MASK 255.0.0.0 8.8.8.8 METRIC 5 IF 14

This works until the interface ID changed from IF 14 to IF 15.
Is it possible to keep the interface numbers fixed, or if not, dynamically retrieve the interface number from the interface name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花ソ最美的依靠 2025-02-06 06:00:47

您是否考虑过使用PowerShell?

$nic = Get-NetAdapter | where {$_.Name -like '*Ether*'}

New-NetRoute -DestinationPrefix "10.0.0.0/8" -InterfaceIndex $nic.ifIndex -NextHop "8.8.8.8" -RouteMetric 5

一个人可以使用批次脚本来做这项工作.....
这是一个开始:(

FOR /F "tokens=*" %g IN ('netsh int ipv4 show interfaces ^| findstr Ethernet') do (SET VAR=%g)
set /A IF_ID = %VAR:~0,4%
echo %IF_ID%

以太网*Ether*,是我获取所需的NIC的方式。在我的情况下,仅其名称包含Ether

注意 - 如果您选择批处理解决方案(不建议使用..),
从批处理文件运行时,必须在%g中使用另一个'%'逃脱“%”。

Have you considered using Powershell?

something like

$nic = Get-NetAdapter | where {$_.Name -like '*Ether*'}

New-NetRoute -DestinationPrefix "10.0.0.0/8" -InterfaceIndex $nic.ifIndex -NextHop "8.8.8.8" -RouteMetric 5

one could make this work using Batch scripting.....
here's a start:

FOR /F "tokens=*" %g IN ('netsh int ipv4 show interfaces ^| findstr Ethernet') do (SET VAR=%g)
set /A IF_ID = %VAR:~0,4%
echo %IF_ID%

(Ethernet, or *Ether*, is my way to get the desired NIC. in my case, only its name contains Ether)

Note - if you opt for the Batch solution (not recommended..),
when running from a batch file, you must escape the '%' using another '%', in %g.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文