Netsh 是命令行脚本实用工具,可让你显示或修改当前正在运行的计算机的网络配置。 可以通过在 netsh 提示符下键入命令来运行 Netsh 命令,并且可以在批处理文件或脚本中使用 Netsh 命令。 可以使用 netsh 命令来配置远程计算机和本地计算机。

Netsh 还提供脚本功能,可让你在批处理模式下对指定的计算机运行一组命令。 你可以使用 Netsh 将配置脚本保存在文本文件中,以便存档或者帮助你配置其他计算机。

一、如何正确使用netsh

  1. 当我们忘记netsh的相关命令时,可以直接使用netsh自带的帮助功能,就能看到一些可以使用的命令。
netsh /?C:\Users\ming Ming>netsh /?Usage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine] [-u [DomainName\]UserName] [-p Password | *][Command | -f ScriptFile]The following commands are available:Commands in this context:
?              - Displays a list of commands.
add            - Adds a configuration entry to a list of entries.
advfirewall    - Changes to the `netsh advfirewall' context.
bridge         - Changes to the `netsh bridge' context.
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.
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.
lan            - Changes to the `netsh lan' context.
mbn            - Changes to the `netsh mbn' context.
namespace      - Changes to the `netsh namespace' context.
netio          - Changes to the `netsh netio' context.
nlm            - Changes to the `netsh nlm' context.
p2p            - Changes to the `netsh p2p' context.
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.
wcn            - Changes to the `netsh wcn' context.
wfp            - Changes to the `netsh wfp' context.
winhttp        - Changes to the `netsh winhttp' context.
winsock        - Changes to the `netsh winsock' context.
wlan           - Changes to the `netsh wlan' context.The following sub-contexts are available:advfirewall bridge dhcpclient dnsclient firewall http interface ipsec lan mbn namespace netio nlm p2p ras rpc trace wcn wfp winhttp winsock wlanTo view help for a command, type the command, followed by a space, and thentype ?.
  1. 那知道有哪些可选功能后,我们就可以进一步输入二级命令去执行我们将要进行的操作,比如下边我就以查看当前tcp链接状态位列展示:

    $>netsh
    $netsh>int
    $netsh interface>ip
    $netsh interface ipv4>show tcpstatsTCP Statistics
    ------------------------------------------------------
    Timeout Algorithm:                      Van Jacobson's Algorithm
    Minimum Timeout:                        5
    Maximum Timeout:                        4294967295
    Maximum Connections:                    Dynamic
    Active Opens:                           3971
    Passive Opens:                          556
    Attempts Failed:                        1017
    Established Resets:                     407
    Currently Established:                  34
    In Segments:                            202193
    Out Segments:                           149657
    Retransmitted Segments:                 0
    In Errors:                              0
    Out Resets:                             845
    Fastopen Active Opens:                  0
    Fastopen Passive Opens:                 0
    Fastopen Attempts Failed:               0
    Retransmits Of First SYN:               644
    Retransmits Of First SYN (Fastopen):    0
    

二、netsh命令整理

1. 导出导入脚本

  1. 导出配置脚本:

    netsh -c interface ip dump > c:/interface.txt
    
  2. 导入配置脚本:

    netsh -f c:/interface.txt
    

2. 固定IP地址批处理

//SETIPDNS.bat( “本地连接”换成你网卡的名字, 具体的 ip 地址,网关,请自行修改 )

@echo offecho 正在修改本机IP...netsh interface ip set address name="本地连接" source=static 192.168.1.188  255.255.255.0 192.168.1.1 1echo 正在添加本机主DNS...netsh interface ip set dns "本地连接" static 18.0.0.10 primaryecho 正在添加本机副DNS...netsh interface ip add dns "本地连接" 18.0.0.10echo 设置完成...echo 检查当前本机配置...ipconfig /allecho 导出配置脚本...netsh -c interface ip dumppause

3. 自动获取 IP

@echo offecho 正在修改本机IP...netsh interface ip set address name="本地连接" source=dhcpecho 正在添加本机主DNS...netsh interface ip set dns "本地连接" dhcpecho 设置完成...echo 检查当前本机配置...ipconfig /allecho 导出配置脚本...netsh -c interface ip dumppause

4. netsh用法

  1. 查看网络配置

    netsh interface ip show {选项}{选项}可以是:
    address-显示IP地址配置。
    config-显示IP地址和更多信息。
    dns-显示DNS服务器地址。
    icmp-显示ICMP统计。
    interface-显示IP接口统计。
    ipaddress-显示当前IP地址。
    ipnet-显示IP的网络到媒体的映射。
    ipstats-显示IP统计。
    joins-显示加入的多播组。
    offload-显示卸载信息。
    tcpconn-显示TCP连接。
    tcpstats-显示TCP统计。
    udpconn-显示UDP连接。
    udpstats-显示UDP统计。
    wins-显示WINS服务器地址。
    
  2. 查看网络配置

    netsh interface ip show {选项}{选项}可以是:
    address-显示IP地址配置。
    config-显示IP地址和更多信息。
    dns-显示DNS服务器地址。
    icmp-显示ICMP统计。
    interface-显示IP接口统计。
    ipaddress-显示当前IP地址。
    ipnet-显示IP的网络到媒体的映射。
    ipstats-显示IP统计。
    joins-显示加入的多播组。
    offload-显示卸载信息。
    tcpconn-显示TCP连接。
    tcpstats-显示TCP统计。
    udpconn-显示UDP连接。
    udpstats-显示UDP统计。
    wins-显示WINS服务器地址。
    
  3. 配置接口IP/网关IP

    netsh interface ip set address "本地连接" static 10.1.2.90 255.255.255.0 10.1.2.254 1
    
  4. 配置自动换取IP地址,DNS地址及wins地址

    netsh interface ip set address "本地连接" dhcp
    netsh interface ip set dns "本地连接" dhcp
    netsh interface ip set wins "本地连接" dhcp
    
  5. 配置静态IP地址,DNS地址及wins地址

    netsh interface ip set address "本地连接" static 10.1.2.90
    netsh interface ip set dns "本地连接" static 202.99.160.68
    netsh interface ip set wins "本地连接" static 10.1.2.200
    
  6. 看网络配置文件

    C:>netsh -c interface dump
    
  7. 导出网络配置文件

    netsh -c interface dump > d:/1.txt
    
  8. 导入网络配置文件

    netsh -f d:/1.txt
    netsh exec d:/2.txt
    
  9. netsh 配置防火墙
    查看、开启或禁用系统防火墙

    # 查看防火墙的状态
    netsh firewall show state# 禁用系统防火墙
    netsh firewall set opmode disable# 启用防火墙
    netsh firewall set opmode enable
    

【一文搞懂】【WIN】【CMD】netsh用法整理相关推荐

  1. 一文搞懂 Traefik2.1 的使用

    原文链接:一文搞懂 Traefik2.1 的使用 一文搞懂 Traefik2.1 的使用 核心概念 安装 ACME 中间件 灰度发布 流量复制 TCP 简单 TCP 服务 带 TLS 证书的 TCP ...

  2. 一文搞懂Qt中的颜色渐变(QGradient Class)

    一文搞懂Qt中的颜色渐变(QGradient Class) 1, 快速开始! Qt中与颜色渐变有关的类是QGradient 其中它又有三个子类:QLinearGradient.QRadialGradi ...

  3. 都2021年了,再不学ES6你就out了 —— 一文搞懂ES6

    JS干货分享 -- 一文搞懂ES6 导语:ES6是什么?用来做什么? 1. let 与 const 2. 解构赋值 3. 模板字符串 4. ES6 函数(升级后更爽) 5. Class类 6. Map ...

  4. 一文搞懂property函数

    一文搞懂property函数 接下来我带大家了解一个函数的作用以及使用技巧,希望对大家都有帮助,话不多说,接下来就开始我的表演 特性 通过存取方法定义的属性通常称为特性(property) 让所有的属 ...

  5. 一文搞懂transient关键字

    一文搞懂transient关键字 1.序列化 1.1 什么是序列化 1.2 以文件存储为例实现序列化 2.transient关键字 2.1 添加transient关键字 2.2 静态变量不需要加tra ...

  6. 一文搞懂RNN(循环神经网络)

    基础篇|一文搞懂RNN(循环神经网络) https://mp.weixin.qq.com/s/va1gmavl2ZESgnM7biORQg 神经网络基础 神经网络可以当做是能够拟合任意函数的黑盒子,只 ...

  7. 一文搞懂 Python 的 import 机制

    一.前言 希望能够让读者一文搞懂 Python 的 import 机制 1.什么是 import 机制? 通常来讲,在一段 Python 代码中去执行引用另一个模块中的代码,就需要使用 Python ...

  8. python语言语句快的标记是什么_一文搞懂Python程序语句

    原标题:一文搞懂Python程序语句 程序流 Python 程序中常用的基本数据类型,包括: 内置的数值数据类型 Tuple 容器类型 String 容器类型 List 容器类型 自然的顺序是从页面或 ...

  9. 一文搞懂 Java 线程中断

    转载自   一文搞懂 Java 线程中断 在之前的一文<如何"优雅"地终止一个线程>中详细说明了 stop 终止线程的坏处及如何优雅地终止线程,那么还有别的可以终止线程 ...

  10. 一文搞懂HMM(隐马尔可夫模型)-Viterbi algorithm

    ***一文搞懂HMM(隐马尔可夫模型)*** 简单来说,熵是表示物质系统状态的一种度量,用它老表征系统的无序程度.熵越大,系统越无序,意味着系统结构和运动的不确定和无规则:反之,,熵越小,系统越有序, ...

最新文章

  1. 仅使用OpenCV实现活体检测!(附源码)
  2. R语言可视化堆叠(stack)的条形图并通过另外一个分类变量分离(dodge)条形图(stacking by one variable and dodging by another)实战
  3. Net设计模式实例之模板方法模式(Template Mothed Pattern)(1)
  4. android游戏开发框架libgdx的使用(四)--舞台和演员
  5. c语言用栈实现计算器加法运算,请问,用c语言做一个计算器 包括+-*/()的运算 用栈 该怎么做...
  6. Java 算法 一元一次方程
  7. Oracle 之 AIO (异步io)
  8. python加粗线宽代码_python-增加matplotlib中图例行的线宽
  9. Windows时间同步出错|无法获取服务器时间解决办法
  10. mysql修改时间为东八区,mysql时区设置为东八区
  11. windows下安装zookeeper以及监控中心
  12. 一笔画:五环,python-turtle。画圆圈
  13. android 在线预览pdf文件(目前最全)
  14. IBM X3550 m4 微码升级
  15. Android集成友盟推送功能
  16. 关于NFT房地产:2022年你所需要知道的一切
  17. 研发管理:与员工一对一交流的执行与反思
  18. .NetCore源码阅读笔记系列之Security (一) Authentication AddCookie
  19. Chrome中的GPU加速合成
  20. 对计算机学院祝福语,祝福学校发展的祝福语(精选60句)

热门文章

  1. C语言常用字符串函数详解
  2. vue子组件向父组件传值的三种方式
  3. itext 动态的填充pdf
  4. fiddler使用笔记
  5. Fiddler笔记(一)
  6. 【ubuntu】dpkg: 错误: 另外一个进程已经为 dpkg frontend 加锁
  7. Kubeflow第一篇--大致了解
  8. ExtJs中TextField与TextArea的只读属性设置
  9. 美国进口呼吸机PB560设计完整资料分享
  10. 遗传算法——基于Big Mart Sales数据集的TPOT库实现(python)