适用于: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 winsockTo 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.

Network Shell (Netsh)相关推荐

  1. 【CyberSecurityLearning 附】批处理命令拓展(netsh/netstat/net)

    目录 1.netsh修改ip,网关,dns: (1)备份网络配置: (2)设置静态ip: (3)设置dhcp: 2.netsh修改防火墙设置: (1)开启/关闭: (2)规则设置: 3.netsh查看 ...

  2. windows下用netsh工具设置笔记本wifi热点

    硬件:含有无线网卡的电脑或笔记本 系统:Windows7内核的系统,Windows8,Windows Server 2008 等 目的:将Win7的无线网卡作为wifi热点,让其他含有WIFI电子设备 ...

  3. 【批处理DOS-CMD命令-汇总和小结】-上网和网络通信相关命令(netsh)

    一.netsh命令的简介 netsh(Network Shell)是一个windows系统本身提供的功能强大的网络配置命令行工具,可用来修改windows的ip.网关.dns等信息. netsh是一个 ...

  4. Windows下使用Netsh Winsock reset命令解决网络连接问题

    什么是Netsh Winsock reset? netsh (Network Shell) 是一个windows系统本身提供的功能强大的网络配置命令行工具. Winsock是Windows网络编程接口 ...

  5. 内网转发之Netsh端口转发的使用学习

    Netsh是什么 netsh(Network Shell) 是一个windows系统本身提供的功能强大的网络配置命令行工具.自Windows XP开始,Windows中就内置网络端口转发的功能.任何传 ...

  6. netsh查看wifi密码

    netsh(Network Shell) 是一个windows系统本身提供的功能强大的网络配置命令行工具.Netsh 是命令行脚本实用工具,它允许从本地或远程显示或修改当前正在运行的计算机的网络配置. ...

  7. 使用netsh来进行端口转发

    文章首发公众号:无心的梦呓 此处文章不好排版,请移步到公众号查看 在历史消息中搜索:使用netsh来进行端口转发 目录 0x00 简介 0x01 2003命令介绍 0x02 2003以后命令介绍(以0 ...

  8. 【技巧】windows下网络抓包-netsh技巧(文末附免费学习资料)

    相信大家做一些项目,在获取到pc权限后,翻翻文件,查查浏览器记录,但是有些浏览器的账户密码,读取不出来,一些基于key验证的应用提取不出来,如果权限比较高或者过uac的情况下,我们也可以抓取用户的流量 ...

  9. netsh 获取计算机名,Windows中Netsh命令的典型应用

    netsh命令已经推出很长时间,在Windows 2000/XP/2003中均带有Netsh命令.Windows Server 2008只是对netsh的参数项做了些扩展.日常工作中,很多管理员对ne ...

最新文章

  1. LeetCode 589. N-ary Tree Preorder Traversal-多子节点树前序遍历--递归,迭代--反向压栈--C++解法
  2. 入门干货之Grpc的.Net 封装-MagicOnion
  3. Linux查看时间段文件,Linux查看特定时间段内修改过的文件
  4. java连接oracle数据库 -- jdbc连接
  5. 如何查看交换机某端口下接什么设备
  6. .net mvc 一个Action的 HttpGet 和 HttpPost
  7. Java - HashMap源码解析
  8. goeasy java_Java GoEasy 实现服务端推送和Web端推送
  9. fences卸载_fences是什么意思?WIN10专业版彻底删除fences的技巧
  10. Chapter6 CMOS组合逻辑门设计
  11. 橡胶材料特性和本构关系【转】_51CAE_新浪博客
  12. STA series --- 3.Standard cell library(PART-I)
  13. power 相关:(二)功耗的分析 —— power compiler
  14. Android智能电视焦点控制
  15. 【数学思维】最大值与上确界
  16. GPU CPU NPU
  17. Vue 官方成员 Hcy:怎么才能有尤雨溪一半强,该怎么学习?
  18. TCO-PNB ester,1438415-89-4, 反式环辛烯-对硝基苯
  19. [笔记分享] [SCons] Qualcomm SCons User Guide
  20. 本科计算机仿真试题,试题模板2005-计算机仿真

热门文章

  1. EffecientDet论文学习2
  2. HBASE 2.0 hbck使用
  3. 3月22日,30秒知全网,精选7个热点///国内首艘500千瓦氢燃料电池动力船下水​///中航京能光伏REIT正式成立
  4. 【bzoj4631】踩气球
  5. [附源码]计算机毕业设计汽车美容店管理系统Springboot程序
  6. Unity游戏开发文档(3.1.3):滚动式关卡选择菜单
  7. [VCAP5] VCAP5-DCA DCD学习资料汇总 存储(VDCA510为主)
  8. bcc校验c语言实现,Linux BCC(异或校验)计算命令行工具
  9. iPhone手机记事用什么软件哪个好用方便?
  10. C语言初学者必看--动态定义二维数组的方法