Network Shell (Netsh)

适用于:Windows Server 2022、Windows Server 2019、Windows Server 2016、Azure Stack HCI、版本 21H2 和 20H2

Network shell (netsh) 是一个命令行实用程序,允许您在将各种网络通信服务器角色和组件安装到运行 Windows Server 的计算机上后配置和显示它们的状态。

某些客户端技术,例如动态主机配置协议 (DHCP) 客户端和 BranchCache,还提供了允许您配置运行 Windows 10 的客户端计算机的 netsh 命令。

在大多数情况下,netsh 命令提供的功能与您对每个网络服务器角色或网络功能使用 Microsoft 管理控制台 (MMC) 管理单元时可用的功能相同。例如,您可以使用 NPS MMC 管理单元或netsh nps上下文中的 netsh 命令配置网络策略服务器 (NPS)。

此外,还有一些用于网络技术的 netsh 命令,例如 IPv6、网桥和远程过程调用 (RPC),这些命令在 Windows Server 中作为 MMC 管理单元不可用。

网络外壳 (Netsh) 技术参考
Netsh 技术参考提供了全面的 netsh 命令参考,包括 netsh 命令的语法、参数和示例。您可以使用 Netsh 技术参考来构建脚本和批处理文件,方法是使用 netsh 命令在运行 Windows Server 和 Windows 10 的计算机上对网络技术进行本地或远程管理。

Netsh 命令语法、上下文和格式

适用于:Windows Server 2022、Windows Server 2019、Windows Server 2016、Azure Stack HCI、版本 21H2 和 20H2

Netsh 是一个命令行脚本实用程序,它允许您显示或修改当前正在运行的计算机的网络配置。Netsh 命令可以通过在 netsh 提示符下键入命令来运行,它们可以在批处理文件或脚本中使用。可以使用 netsh 命令配置远程计算机和本地计算机。

Netsh 还提供了一个脚本功能,允许您以批处理模式对指定的计算机运行一组命令。使用 netsh,您可以将配置脚本保存在文本文件中以用于存档或帮助您配置其他计算机。

Netsh 上下文

Netsh 通过使用动态链接库 (DLL) 文件与其他操作系统组件进行交互。

每个 netsh 帮助程序 DLL 都提供了一组广泛的功能,称为context,它是一组特定于网络服务器角色或功能的命令。这些上下文通过为一个或多个服务、实用程序或协议提供配置和监视支持来扩展 netsh 的功能。例如,Dhcpmon.dll 为 netsh 提供了配置和管理 DHCP 服务器所需的上下文和命令集。

获取上下文列表

您可以通过在运行 Windows Server 2016 或 Windows 10 的计算机上打开命令提示符或 Windows PowerShell 来获取 netsh 上下文列表。键入命令 netsh并按 Enter。输入/? ,然后按 ENTER。

以下是运行 Windows Server 2016 Datacenter 的计算机上这些命令的示例输出。

PS C:\Windows\system32> netsh
netsh>/?

The following commands are available:

Commands in this context:
..            - Goes up one context level.
?             - Displays a list of commands.
abort         - Discards changes made while in offline mode.
add           - Adds a configuration entry to a list of entries.
advfirewall   - Changes to the `netsh advfirewall' context.
alias         - Adds an alias.
branchcache   - Changes to the `netsh branchcache' context.
bridge        - Changes to the `netsh bridge' context.
bye           - Exits the program.
commit        - Commits changes made while in offline mode.
delete        - Deletes a configuration entry from a list of entries.
dhcpclient    - Changes to the `netsh dhcpclient' context.
dnsclient     - Changes to the `netsh dnsclient' context.
dump          - Displays a configuration script.
exec          - Runs a script file.
exit          - Exits the program.
firewall      - Changes to the `netsh firewall' context.
help          - Displays a list of commands.
http          - Changes to the `netsh http' context.
interface     - Changes to the `netsh interface' context.
ipsec         - Changes to the `netsh ipsec' context.
ipsecdosprotection - Changes to the `netsh ipsecdosprotection' context.
lan           - Changes to the `netsh lan' context.
namespace     - Changes to the `netsh namespace' context.
netio         - Changes to the `netsh netio' context.
offline       - Sets the current mode to offline.
online        - Sets the current mode to online.
popd          - Pops a context from the stack.
pushd         - Pushes current context on stack.
quit          - Exits the program.
ras           - Changes to the `netsh ras' context.
rpc           - Changes to the `netsh rpc' context.
set           - Updates configuration settings.
show          - Displays information.
trace         - Changes to the `netsh trace' context.
unalias       - Deletes an alias.
wfp           - Changes to the `netsh wfp' context.
winhttp       - Changes to the `netsh winhttp' context.
winsock       - Changes to the `netsh winsock' context.

The following sub-contexts are available:
 advfirewall branchcache bridge dhcpclient dnsclient firewall http interface ipsec ipsecdosprotection lan namespace netio ras rpc trace wfp winhttp winsock

To view help for a command, type the command, followed by a space, and then type ?.

子上下文

Netsh 上下文可以包含命令和附加上下文,称为subcontexts。例如,在路由上下文中,您可以更改为 IP 和 IPv6 子上下文。
要显示可以在上下文中使用的命令和子上下文的列表,请在 netsh 提示符下键入上下文名称,然后键入/? 或帮助。例如,要显示可以在路由上下文中使用的子上下文和命令的列表,请在 netsh 提示符(即netsh>)处键入以下内容之一:

routing /?
routing help
要在另一个上下文中执行任务而不更改当前上下文,请在 netsh 提示符下键入要使用的命令的上下文路径。例如,要在 IGMP 上下文中添加一个名为“Local Area Connection”的接口而不首先更改为 IGMP 上下文,请在 netsh 提示符下键入:

routing ip igmp add interface "Local Area Connection" startupqueryinterval=21

运行 netsh 命令

要运行 netsh 命令,您必须从命令提示符启动 netsh,方法是键入netsh,然后按 ENTER。接下来,您可以更改为包含您要使用的命令的上下文。可用的上下文取决于您安装的网络组件。例如,如果您在 netsh 提示符下键入dhcp并按 ENTER,则 netsh 将更改为 DHCP 服务器上下文。但是,如果您没有安装 DHCP,则会出现以下消息:
未找到以下命令:dhcp

格式化图例

在 netsh 提示符或批处理文件或脚本中运行命令时,可以使用以下格式图例来解释和使用正确的 netsh 命令语法。
☑ 斜体文本是您在键入命令时必须提供的信息。例如,如果命令具有名为 - UserName的参数,则必须键入实际用户名。
☑ 粗体文本是您在键入命令时必须准确键入的信息。
☑ 后跟省略号 (…) 的文本是可以在命令行中重复多次的参数。
☑ 括号 [ ] 之间的文本是可选项目。
☑ 大括号 { } 之间的文本以及由竖线分隔的选项提供了一组选项,您必须从中仅选择一个选项,例如{enable|disable}.
☑ 使用 Courier 字体格式化的文本是代码或程序输出。

在命令提示符或Windows PowerShell中运行Netsh命令

要启动Network Shell并在命令提示符或Windows PowerShell中输入netsh,可以使用以下命令。
netsh
Netsh 是一个命令行脚本实用程序,可让您在本地或远程显示或修改当前正在运行的计算机的网络配置。不带参数使用时,netsh打开 Netsh.exe 命令提示符(即netsh>)。

Syntax

netsh[ -a AliasFile] [ -c Context ] [-r RemoteComputer] [ -u [ DomainName\ ] UserName ] [ -p Password | *] [{NetshCommand | -f ScriptFile}]

# Parameters
-a			Optional. Specifies that you are returned to the netsh prompt after running AliasFile.
AliasFile	Optional. Specifies the name of the text file that contains one or more netsh commands.
-c			Optional. Specifies that netsh enters the specified netsh context.
Context		Optional. Specifies the netsh context that you want to enter.
-r			Optional. Specifies that you want the command to run on a remote computer.
重要的
当您使用netsh -r参数在另一台计算机上远程使用某些netsh命令时,远程注册表服务必须在远程计算机上运行。如果它没有运行,Windows将显示“网络路径未找到”错误消息。

RemoteComputer		Optional. Specifies the remote computer that you want to configure.
-u					Optional. Specifies that you want to run the netsh command under a user account.
DomainName\\		Optional. Specifies the domain where the user account is located. The default is the local domain if DomainName\ is not specified.
UserName			Optional. Specifies the user account name.
-p					Optional. Specifies that you want to provide a password for the user account.
Password			Optional. Specifies the password for the user account that you specified with -u UserName.
NetshCommand		Optional. Specifies the netsh command that you want to run.
-f					Optional. Exits netsh after running the script that you designate with ScriptFile.
ScriptFile			Optional. Specifies the script that you want to run.
/?
Optional. Displays help at the netsh prompt.

笔记
如果您指定-r后跟另一个命令,netsh在远程计算机上运行该命令,然后返回到 Cmd.exe 命令提示符。如果您-r不指定其他命令,netsh将以远程模式打开。该过程类似于在 Netsh 命令提示符下使用set machine 。使用时-r,您只为当前的netsh实例设置目标计算机。退出并重新进入netsh后,目标计算机将重置为本地计算机。通过指定存储在 WINS 中的计算机名称、UNC 名称、要由 DNS 服务器解析的 Internet 名称或 IP 地址,您可以在远程计算机上运行netsh命令。

为 netsh 命令键入参数字符串值
在整个 Netsh 命令参考中,有些命令包含需要字符串值的参数。
如果字符串值包含字符之间的空格,例如包含多个单词的字符串值,则需要将字符串值用引号引起来。例如,对于名为interface且字符串值为Wireless Network Connection的参数,请在字符串值周围使用引号:

interface="Wireless Network Connection"

Things are complicated time is silent.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星光落入你灰蒙蒙的眼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值