引言
在日常的网络管理和故障排查中,CMD(命令提示符)是一个非常强大的工具。通过使用一些常用的网络命令,你可以轻松地进行网络诊断、配置和监控。本文将详细介绍一些常用的网络CMD命令,并通过示例说明它们的用法。
常用的网络CMD命令
1. ping
用途:测试网络连接和延迟。 语法:ping <目标IP地址或域名>
示例:
ping www.google.com
输出:
Pinging www.google.com [172.217.16.46] with 32 bytes of data:
Reply from 172.217.16.46: bytes=32 time=24ms TTL=55
Reply from 172.217.16.46: bytes=32 time=23ms TTL=55
Reply from 172.217.16.46: bytes=32 time=22ms TTL=55
Reply from 172.217.16.46: bytes=32 time=24ms TTL=55
Ping statistics for 172.217.16.46:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 22ms, Maximum = 24ms, Average = 23ms
2. ipconfig
用途:显示和配置网络接口的详细信息。 语法:ipconfig [参数]
常用参数:
/all
:显示所有网络适配器的详细信息。/release
:释放指定适配器的IP地址。/renew
:更新指定适配器的IP地址。
示例:
ipconfig /all
输出:
Windows IP Configuration
Host Name . . . . . . . . . . . . : DESKTOP-PC
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : home
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . : home
Description . . . . . . . . . . . : Realtek PCIe GBE Family Controller
Physical Address. . . . . . . . . : 1A-2B-3C-4D-5E-6F
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::1a2b:3c4d:5e6f%11(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.1.100(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Tuesday, October 10, 2023 10:00:00 AM
Lease Expires . . . . . . . . . . : Wednesday, October 11, 2023 10:00:00 AM
Default Gateway . . . . . . . . . : 192.168.1.1
DHCP Server . . . . . . . . . . . : 192.168.1.1
DHCPv6 IAID . . . . . . . . . . . : 12345678
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-23-45-67-89-AB-CD-EF-01
DNS Servers . . . . . . . . . . . : 8.8.8.8
8.8.4.4
NetBIOS over Tcpip. . . . . . . . : Enabled
3. tracert
用途:跟踪数据包从本地计算机到目标主机所经过的路由。 语法:tracert <目标IP地址或域名>
示例:
tracert www.google.com
输出:
Tracing route to www.google.com [172.217.16.46]
over a maximum of 30 hops:
1 1 ms 1 ms 1 ms 192.168.1.1
2 2 ms 2 ms 2 ms 10.0.0.1
3 3 ms 3 ms 3 ms 192.168.0.1
4 4 ms 4 ms 4 ms 10.0.0.2
5 5 ms 5 ms 5 ms 192.168.0.2
6 6 ms 6 ms 6 ms 10.0.0.3
7 7 ms 7 ms 7 ms 192.168.0.3
8 8 ms 8 ms 8 ms 10.0.0.4
9 9 ms 9 ms 9 ms 192.168.0.4
10 10 ms 10 ms 10 ms 10.0.0.5
11 11 ms 11 ms 11 ms 192.168.0.5
12 12 ms 12 ms 12 ms 10.0.0.6
13 13 ms 13 ms 13 ms 192.168.0.6
14 14 ms 14 ms 14 ms 10.0.0.7
15 15 ms 15 ms 15 ms 192.168.0.7
16 16 ms 16 ms 16 ms 10.0.0.8
17 17 ms 17 ms 17 ms 192.168.0.8
18 18 ms 18 ms 18 ms 10.0.0.9
19 19 ms 19 ms 19 ms 192.168.0.9
20 20 ms 20 ms 20 ms 10.0.0.10
21 21 ms 21 ms 21 ms 192.168.0.10
22 22 ms 22 ms 22 ms 10.0.0.11
23 23 ms 23 ms 23 ms 192.168.0.11
24 24 ms 24 ms 24 ms 10.0.0.12
25 25 ms 25 ms 25 ms 192.168.0.12
26 26 ms 26 ms 26 ms 10.0.0.13
27 27 ms 27 ms 27 ms 192.168.0.13
28 28 ms 28 ms 28 ms 10.0.0.14
29 29 ms 29 ms 29 ms 192.168.0.14
30 30 ms 30 ms 30 ms 10.0.0.15
Trace complete.
4. nslookup
用途:查询DNS以获取域名或IP地址的相关信息。 语法:nslookup <目标IP地址或域名>
示例:
nslookup www.google.com
输出:
Non-authoritative answer:
Name: www.google.com
Addresses: 2607:f8b0:4002:801::200e
172.217.16.46
5. netstat
用途:显示网络连接、路由表、接口统计等信息。 语法:netstat [参数]
常用参数:
-a
:显示所有连接和监听端口。-n
:显示数字形式的地址和端口号。-r
:显示路由表。
示例:
netstat -an
输出:
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 0.0.0.0:139 0.0.0.0:0 LISTENING
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING
TCP 0.0.0.0:443 0.0.0.0:0 LISTENING
TCP 192.168.1.100:139 0.0.0.0:0 LISTENING
TCP 192.168.1.100:445 0.0.0.0:0 LISTENING
TCP 192.168.1.100:135 0.0.0.0:0 LISTENING
TCP 192.168.1.100:80 0.0.0.0:0 LISTENING
TCP 192.168.1.100:443 0.0.0.0:0 LISTENING
UDP 0.0.0.0:137 *:*
UDP 0.0.0.0:138 *:*
UDP 0.0.0.0:500 *:*
UDP 0.0.0.0:1900 *:*
UDP 192.168.1.100:137 *:*
UDP 192.168.1.100:138 *:*
UDP 192.168.1.100:500 *:*
UDP 192.168.1.100:1900 *:*
6. route
用途:查看和修改IP路由表。 语法:route [参数]
常用参数:
print
:显示当前的路由表。add
:添加新的路由。delete
:删除现有的路由。
示例:
1route print
输出:
===========================================================================
Interface List
12...00 15 5d 00 00 00 ......Intel(R) 82579LM Gigabit Network Connection
1...........................Software Loopback Interface 1
===========================================================================
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.100 25
127.0.0.0 255.0.0.0 On-link 127.0.0.1 306
127.0.0.1 255.255.255.255 On-link 127.0.0.1 306
127.255.255.255 255.255.255.255 On-link 127.0.0.1 306
192.168.1.0 255.255.255.0 On-link 192.168.1.100 281
192.168.1.100 255.255.255.255 On-link 192.168.1.100 281
192.168.1.255 255.255.255.255 On-link 192.168.1.100 281
224.0.0.0 240.0.0.0 On-link 127.0.0.1 306
224.0.0.0 240.0.0.0 On-link 192.168.1.100 281
255.255.255.255 255.255.255.255 On-link 127.0.0.1 306
255.255.255.255 255.255.255.255 On-link 192.168.1.100 281
===========================================================================
Persistent Routes:
None
7. telnet
用途:用于远程登录到其他计算机。 语法:telnet <目标IP地址或域名> <端口号>
示例:
telnet www.google.com 80
输出:
Trying 172.217.16.46...
Connected to google.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.google.com
HTTP/1.1 200 OK
Date: Tue, 10 Oct 2023 10:00:00 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2023-10-10-10; expires=Wed, 09-Nov-2023 10:00:00 GMT; path=/; domain=.google.com; Secure
Set-Cookie: NID=20231010100000; expires=Wed, 09-Nov-2023 10:00:00 GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="...">...</script></head><body><div id="lga"></div><div id="mngb"></div><div id="main"><div id="cnt"><div id="rcnt"><div class="med card-section" id="center_col"><div class="logo-hp" id="logocont"><a href="/"><img alt="Google" aria-label="Google" id="hplogo" src="//www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" style="height: 92px; width: 272px;"></a></div><form action="/search" aria-label="Search" method="GET" role="search"><input aria-label="Search" autocomplete="off" maxlength="2048" name="q" title="Search" type="text" value=""><div class="sfib"><input aria-label="Google Search" name="btnK" type="submit" value="Google Search"><input aria-label="I'm Feeling Lucky" name="btnI" type="submit" value="I'm Feeling Lucky"></div></form></div></div></div></div></body></html>
Connection to host lost.
8. ftp
用途:用于文件传输协议(FTP)客户端,上传和下载文件。 语法:ftp <目标IP地址或域名>
示例:
ftp ftp.example.com
输出:
Connected to ftp.example.com.
(vsFTPd 3.0.11)
Name (ftp.example.com:username): user
Please specify the password.
Password:
Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
Entering Passive Mode (192,168,1,1,192,168).
Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Sep 25 12:00 pub
Directory send OK.
ftp> get file.txt
local: file.txt remote: file.txt
Entering Passive Mode (192,168,1,1,192,168).
Opening BINARY mode data connection for file.txt (1024 bytes).
Transfer complete.
1024 bytes received in 0.00 secs (1.00 MB/s)
ftp> quit
Goodbye.
9. netsh
用途:配置和显示网络设置。 语法:netsh [参数]
常用参数:
interface ip show config
:显示IP配置信息。interface ip set address "本地连接" static 192.168.1.100 255.255.255.0 192.168.1.1 1
:设置静态IP地址。interface ip set dns "本地连接" static 8.8.8.8
:设置DNS服务器。
示例:
netsh interface ip show config
输出:
Configuration for interface "以太网"
DHCP enabled: Yes
IP Address: 192.168.1.100
Subnet Prefix: 192.168.1.0/24 (mask 255.255.255.0)
InterfaceMetric: 25
Type: Dedicated
DNS servers configured through DHCP: 8.8.8.8
Register with which suffix: Primary only
WINS servers configured through DHCP: None
10. arp
用途:显示和修改ARP(地址解析协议)缓存。 语法:arp [参数]
常用参数:
-a
:显示ARP缓存表。-d <IP地址>
:删除指定IP地址的ARP条目。-s <IP地址> <MAC地址>
:添加静态ARP条目。
示例:
1arp -a
输出:
Interface: 192.168.1.100 --- 0x1
Internet Address Physical Address Type
192.168.1.1 00-1A-2B-3C-4D-5E dynamic
192.168.1.2 00-67-89-AB-CD-EF dynamic
11. nbtstat
用途:显示NetBIOS over TCP/IP (NBT) 统计数据。 语法:nbtstat [参数]
常用参数:
-a <IP地址>
:显示远程计算机的NetBIOS名称表。-c
:显示NetBIOS名称缓存的内容。-n
:列出本地NetBIOS名称。
示例:
nbtstat -a 192.168.1.1
输出:
Node IpAddress: [192.168.1.1] Scope Id: []
NetBIOS Remote Machine Name Table
Name Type Status
------------------------------------------------------------
WORKGROUP <00> UNIQUE Registered
WORKGROUP <1D> UNIQUE Registered
DESKTOP-PC <00> GROUP Registered
DESKTOP-PC <1D> UNIQUE Registered
DESKTOP-PC <1C> GROUP Registered
DESKTOP-PC <20> UNIQUE Registered
..__MSBROWSE__. <01> GROUP Registered
12. hostname
用途:显示或设置主机名。 语法:hostname [参数]
常用参数:
hostname
:显示当前主机名。hostname <新主机名>
:设置新的主机名(需要管理员权限)。
示例:
hostname
输出:
DESKTOP-PC
13. systeminfo
用途:显示系统详细信息,包括网络配置。 语法:systeminfo
示例:
systeminfo
输出:
Host Name: DESKTOP-PC
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19041 N/A Build 19041
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Registered Owner: User
Registered Organization:
Product ID: 00330-80000-00000-AA875
Original Install Date: 10/01/2023, 12:00:00 PM
System Boot Time: 10/10/2023, 10:00:00 AM
System Manufacturer: Dell Inc.
System Model: Inspiron 3670
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
BIOS Version: Dell Inc. A10, 07/01/2020
Windows Directory: C:\Windows
System Directory: C:\Windows\system32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi
Total Physical Memory: 16,384 MB
Available Physical Memory: 12,345 MB
Virtual Memory: Max Size: 20,480 MB
Virtual Memory: Available: 15,678 MB
Virtual Memory: In Use: 4,802 MB
Page File Location(s): C:\pagefile.sys
Domain: WORKGROUP
Logon Server: \\DESKTOP-PC
Hotfix(s): 3 Hotfix(s) Installed.
[01]: KB4567890
[02]: KB1234567
[03]: KB7654321
Network Card(s): 1 NIC(s) Installed.
[01]: Realtek PCIe GBE Family Controller
Connection Name: Ethernet
DHCP Enabled: Yes
IP address(es)
[01]: 192.168.1.100
[02]: fe80::1a2b:3c4d:5e6f%11
[03]: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
14. ipconfig /flushdns
用途:清除DNS缓存。 语法:ipconfig /flushdns
示例:
ipconfig /flushdns
输出:
Windows IP Configuration
Successfully flushed the DNS Resolver Cache.
15. tasklist
用途:显示当前运行的任务列表。 语法:tasklist [参数]
常用参数:
/S <远程计算机名>
:指定要连接的远程计算机。/U <用户名>
:使用指定的用户名连接到远程计算机。/P <密码>
:使用指定的密码连接到远程计算机。
示例:
tasklist
输出:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 8 K
System 4 Services 0 2,432 K
smss.exe 488 Services 0 1,168 K
csrss.exe 576 Services 0 5,056 K
wininit.exe 600 Services 0 1,200 K
services.exe 612 Services 0 2,600 K
lsass.exe 628 Services 0 1,800 K
svchost.exe 640 Services 0 1,840 K
svchost.exe 700 Services 0 1,880 K
svchost.exe 724 Services 0 1,920 K
...
结语
通过以上介绍和示例,你应该已经掌握了常用的网络CMD命令及其用法。这些命令在日常的网络管理和故障排查中非常有用。希望这篇文章能帮助你更好地理解和使用这些命令。如果你有任何问题或需要进一步的帮助,请随时留言交流!
希望这篇技术博文能够为你提供有用的信息,并激发起你对网络管理的兴趣!如果有任何进一步的问题或需要更多的功能,请评论区留言或私信。
阿里云百炼大模型
https://bailian.console.aliyun.com/
通义灵码_智能编码助手面向用户上线个人和企业版产品
https://tongyi.aliyun.com/lingma/pricing?userCode=jl9als0w
云工开物_阿里云高校计划助力高校科研与教育加速。
https://university.aliyun.com/mobile?userCode=jl9als0w
无影云电脑个人版简单易用、安全高效的云上桌面服务
https://www.aliyun.com/product/wuying/gws/personal_edition?userCode=jl9als0w
云服务器ECS省钱攻略五种权益,限时发放,不容错过
https://www.aliyun.com/daily-act/ecs/ecs_trial_benefits?userCode=jl9als0w