windows两种添加路由的方法

windows使用netsh添加netsh路由

netsh interface ipv4 add route 1.1.1.1/32 "接口名称" <网关IP>

请将 <接口名称> 替换为你想要路由的接口的名称,以及 <网关IP> 替换为相应的网关IP地址。例如:

 
netsh interface ipv4 add route 1.1.1.1/32 "Ethernet" 192.168.1.1

这将向IPv4路由表中添加一个将 1.1.1.1/32 网络流量路由到名为 "Ethernet" 的接口,并将其网关设置为 192.168.1.1。

 

怎么确定"Ethernet" 这个名称是什么

 

要确定网络接口的名称,你可以使用 netsh interface ipv4 show interfaces 命令列出系统中的所有网络接口及其相关信息,包括名称。例如,在命令提示符或 PowerShell 中运行以下命令:

 
netsh interface ipv4 show interfaces

然后,你会看到类似以下的输出:

Idx   Met   MTU        State          Name
---  ----  ----------  ------------  ---------------------------
  1     75  4294967295  connected     Loopback Pseudo-Interface 1
 11     15   1500        connected     Ethernet

在这个示例中,"Ethernet" 是一个网络接口的名称。你可以根据列出的接口名称来确定要在路由中使用的正确名称。

成功添加实例:

C:\Users\Administrator>netsh interface ipv4 show interfaces

Idx     Met         MTU          状态                名称
---  ----------  ----------  ------------  ---------------------------
  1          75  4294967295  connected     Loopback Pseudo-Interface 1
 77           5        1500  disconnected  VirtualNet
 24         100        1500  connected     WLAN
  4         100        1500  disconnected  以太网
  2          25        1500  disconnected  本地连接
 27          25        1500  disconnected  本地连接* 2
 20           1        1500  connected     iNode VPN
 13          25        1500  connected     VirtualBox Host-Only Network
 10          35        1500  disconnected  以太网 4
 30          35        1500  connected     VMware Network Adapter VMnet1
 22          25        1500  connected     以太网 3
 21          35        1500  connected     VMware Network Adapter VMnet8

 添加netsh路由

C:\WINDOWS\system32>netsh interface ipv4 add route  1.1.1.1/32 "VMware Network Adapter VMnet8" 192.168.16.1
确定。

 添加普通路由,对比netsh路由

C:\WINDOWS\system32>route add 1.1.1.1 mask 255.255.255.255 192.168.0.100
 操作完成!

 查看路由表

C:\WINDOWS\system32>route print
===========================================================================
接口列表
 20...02 50 f2 00 00 02 ......iNode VPN Virtual NIC
 77...........................Hillstone Virtual Network Adapter Tunnel
 13...0a 00 27 00 00 0d ......VirtualBox Host-Only Ethernet Adapter
 22...02 00 4c 4f 4f 50 ......Microsoft KM-TEST 环回适配器
  2...00 ff 01 f9 27 3b ......Virtual Network Adapter
 27...ac 2b 6e b4 01 64 ......Microsoft Wi-Fi Direct Virtual Adapter #2
 10...00 ff 37 e3 93 b0 ......TAP-Windows Adapter V9
 30...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
 21...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
  1...........................Software Loopback Interface 1
  4...1c 39 47 cd 7b 58 ......Realtek PCIe GBE Family Controller
 24...ac 2b 6e b4 01 63 ......Intel(R) Dual Band Wireless-AC 3165
===========================================================================

IPv4 路由表
===========================================================================
活动路由:
网络目标        网络掩码          网关       接口   跃点数
          0.0.0.0          0.0.0.0    192.168.0.100    192.168.0.148    200
          1.1.1.1  255.255.255.255            在链路上      192.168.16.1    291
          1.1.1.1  255.255.255.255            在链路上     192.168.0.100     26

 

 

 

 

posted on 2024-04-30 17:23  叶子在行动  阅读(101)  评论(0编辑  收藏  举报

导航