Netsh ist ein Befehlszeilen-Skriptdienstprogramm, mit dem Sie die Netzwerkkonfiguration des aktuell ausgeführten Computers anzeigen oder ändern können. Sie können Netsh-Befehle ausführen, indem Sie sie an der Netsh-Eingabeaufforderung eingeben, und Sie können Netsh-Befehle in Batchdateien oder Skripts verwenden. Sie können Netsh-Befehle verwenden, um Remote- und lokale Computer zu konfigurieren.
Netsh bietet außerdem eine Skriptfunktion, mit der Sie eine Reihe von Befehlen auf einem bestimmten Computer im Batch-Modus ausführen können. Sie können Netsh verwenden, um Konfigurationsskripts zur Archivierung in Textdateien zu speichern oder um Sie bei der Konfiguration anderer Computer zu unterstützen.
1. So verwenden Sie es richtignetsh
- Wenn wir die relevanten Befehle von Netsh vergessen, können wir direkt die mit Netsh gelieferte Hilfefunktion verwenden und einige Befehle sehen, die verwendet werden können.
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 wlan
To view help for a command, type the command, followed by a space, and then
type ?.
-
Nachdem wir wissen, welche optionalen Funktionen verfügbar sind, können wir weitere sekundäre Befehle eingeben, um die von uns auszuführenden Vorgänge auszuführen. Beispielsweise zeige ich den aktuellen TCP-Verbindungsstatus wie folgt an:
$>netsh $netsh>int $netsh interface>ip $netsh interface ipv4>show tcpstats TCP 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
2. netsh
Befehlsanordnung
1. Skript exportieren und importieren
-
Konfigurationsskript exportieren:
netsh -c interface ip dump > c:/interface.txt
-
Konfigurationsskript importieren:
netsh -f c:/interface.txt
2. Feste IP-Adress-Stapelverarbeitung
//SETIPDNS.bat (ersetzen Sie „Lokale Verbindung“ durch den Namen Ihrer Netzwerkkarte, spezifische IP-Adresse, Gateway, bitte ändern Sie es selbst)
@echo off
echo 正在修改本机IP...
netsh interface ip set address name="本地连接" source=static 192.168.1.188 255.255.255.0 192.168.1.1 1
echo 正在添加本机主DNS...
netsh interface ip set dns "本地连接" static 18.0.0.10 primary
echo 正在添加本机副DNS...
netsh interface ip add dns "本地连接" 18.0.0.10
echo 设置完成...
echo 检查当前本机配置...
ipconfig /all
echo 导出配置脚本...
netsh -c interface ip dump
pause
3. IP automatisch beziehen
@echo off
echo 正在修改本机IP...
netsh interface ip set address name="本地连接" source=dhcp
echo 正在添加本机主DNS...
netsh interface ip set dns "本地连接" dhcp
echo 设置完成...
echo 检查当前本机配置...
ipconfig /all
echo 导出配置脚本...
netsh -c interface ip dump
pause
4. Netsh-Nutzung
-
Netzwerkkonfiguration anzeigen
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服务器地址。
-
Netzwerkkonfiguration anzeigen
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服务器地址。
-
Konfigurieren Sie die Schnittstellen-IP/Gateway-IP
netsh interface ip set address "本地连接" static 10.1.2.90 255.255.255.0 10.1.2.254 1
-
Konfigurieren Sie den automatischen Austausch von IP-Adresse, DNS-Adresse und Wins-Adresse
netsh interface ip set address "本地连接" dhcp netsh interface ip set dns "本地连接" dhcp netsh interface ip set wins "本地连接" dhcp
-
Konfigurieren Sie die statische IP-Adresse, DNS-Adresse und Wins-Adresse
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
-
siehe Netzwerkkonfigurationsdatei
C:>netsh -c interface dump
-
Netzwerkkonfigurationsdatei exportieren
netsh -c interface dump > d:/1.txt
-
Netzwerkkonfigurationsdateien importieren
netsh -f d:/1.txt netsh exec d:/2.txt
-
netsh configure firewall
System-Firewall anzeigen, aktivieren oder deaktivieren# 查看防火墙的状态 netsh firewall show state # 禁用系统防火墙 netsh firewall set opmode disable # 启用防火墙 netsh firewall set opmode enable