Windows系统网络配置命令详细指南

Windows系统网络配置命令详细指南

在Windows操作系统中,通过命令行工具可以执行各种网络配置和管理任务。以下是常用的Windows网络配置命令及其详细说明,包括查看和配置网络接口、诊断网络连接、管理防火墙、共享和远程访问配置、网络服务管理等。

一、查看和配置网络接口

1. ipconfig

用于显示和刷新网络接口的IP配置。

  • 查看当前网络配置

    ipconfig
    
    • 输出示例
      Windows IP Configuration
      
      Ethernet adapter Ethernet:
      
         Connection-specific DNS Suffix  . :
         Link-local IPv6 Address . . . . . : fe80::1c6e:7ff:fe4e:1d5%3
         IPv4 Address. . . . . . . . . . . : 192.168.1.10
         Subnet Mask . . . . . . . . . . . : 255.255.255.0
         Default Gateway . . . . . . . . . : 192.168.1.1
      
  • 查看详细的网络配置

    ipconfig /all
    
    • 输出示例
      Windows IP Configuration
      
         Host Name . . . . . . . . . . . . : my-pc
         Primary Dns Suffix  . . . . . . . :
         Node Type . . . . . . . . . . . . : Hybrid
         IP Routing Enabled. . . . . . . . : No
         WINS Proxy Enabled. . . . . . . . : No
         DNS Suffix Search List. . . . . . : example.com
      
      Ethernet adapter Ethernet:
      
         Connection-specific DNS Suffix  . :
         Description . . . . . . . . . . . : Intel(R) Ethernet Connection (7) I219-V
         Physical Address. . . . . . . . . : 1C-6E-4E-1D-05
         DHCP Enabled. . . . . . . . . . . : Yes
         Autoconfiguration Enabled . . . . : Yes
         Link-local IPv6 Address . . . . . : fe80::1c6e:7ff:fe4e:1d5%3(Preferred)
         IPv4 Address. . . . . . . . . . . : 192.168.1.10(Preferred)
         Subnet Mask . . . . . . . . . . . : 255.255.255.0
         Lease Obtained. . . . . . . . . . : Monday, June 1, 2023 10:00:00 AM
         Lease Expires . . . . . . . . . . : Monday, June 1, 2023 10:00:00 PM
         Default Gateway . . . . . . . . . : 192.168.1.1
         DHCP Server . . . . . . . . . . . : 192.168.1.1
         DNS Servers . . . . . . . . . . . : 8.8.8.8
                                             8.8.4.4
         NetBIOS over Tcpip. . . . . . . . : Enabled
      
  • 刷新DNS缓存

    ipconfig /flushdns
    
  • 释放所有接口的IP地址

    ipconfig /release
    
  • 更新所有接口的IP地址

    ipconfig /renew
    
2. netsh

用于配置和管理网络接口、路由、防火墙等。

  • 查看网络接口列表

    netsh interface show interface
    
    • 输出示例
      Admin State    State          Type             Interface Name
      -----------------------------------------------------------------
      Enabled        Connected      Dedicated        Ethernet
      Enabled        Disconnected   Dedicated        Wi-Fi
      Enabled        Connected      Dedicated        Local Area Connection* 10
      
  • 启用网络接口

    netsh interface set interface "Ethernet" admin=enable
    
  • 禁用网络接口

    netsh interface set interface "Ethernet" admin=disable
    
  • 设置静态IP地址

    netsh interface ip set address name="Ethernet" static 192.168.1.100 255.255.255.0 192.168.1.1
    
  • 设置静态DNS服务器

    netsh interface ip set dns name="Ethernet" static 8.8.8.8
    

二、网络诊断和测试

1. ping

用于测试网络连接和响应时间。

  • 测试连接到特定主机

    ping www.example.com
    
    • 输出示例
      Pinging www.example.com [93.184.216.34] with 32 bytes of data:
      Reply from 93.184.216.34: bytes=32 time=12ms TTL=55
      Reply from 93.184.216.34: bytes=32 time=13ms TTL=55
      Reply from 93.184.216.34: bytes=32 time=12ms TTL=55
      Reply from 93.184.216.34: bytes=32 time=12ms TTL=55
      
      Ping statistics for 93.184.216.34:
          Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
      Approximate round trip times in milli-seconds:
          Minimum = 12ms, Maximum = 13ms, Average = 12ms
      
  • 发送指定数量的请求

    ping -n 5 www.example.com
    
2. tracert

用于跟踪数据包到达目标主机的路由路径。

  • 跟踪到特定主机的路由
    tracert www.example.com
    
    • 输出示例
      Tracing route to example.com [93.184.216.34]
      over a maximum of 30 hops:
      
        1     1 ms     1 ms     1 ms  192.168.1.1
        2    10 ms    10 ms    10 ms  10.0.0.1
        3    20 ms    20 ms    20 ms  192.168.0.1
        4    30 ms    30 ms    30 ms  example.com [93.184.216.34]
      
      Trace complete.
      
3. pathping

结合ping和tracert的功能,提供详细的网络路径分析。

  • 分析到特定主机的路径
    pathping www.example.com
    
    • 输出示例
      Tracing route to example.com [93.184.216.34]
      over a maximum of 30 hops:
      0  my-pc [192.168.1.100]
      1  192.168.1.1
      2  10.0.0.1
      3  192.168.0.1
      4  example.com [93.184.216.34]
      
      Computing statistics for 100 seconds...
      Source to Here   This Node/Link
      Hop  RTT    Lost/Sent = Pct  Lost/Sent = Pct  Address
        0                                           my-pc [192.168.1.100]
        1    1ms     0/ 100 =  0%   |                192.168.1.1
                                     0/ 100 =  0%   |
        2   10ms     0/ 100 =  0%   |                10.0.0.1
                                     0/ 100 =  0%   |
        3   20ms     0/ 100 =  0%   |                192.168.0.1
                                     0/ 100 =  0%   |
        4   30ms     0/ 100 =  0%   |                example.com [93.184.216.34]
      
      Trace complete.
      
4. nslookup

用于查询DNS记录。

  • 查询特定域名的DNS信息
    nslookup www.example.com
    
    • 输出示例
      Server:  google-public-dns-a.google.com
      Address:  8.8.8.8
      
      Non-authoritative answer:
      Name:    www.example.com
      Address: 93.184.216.34
      
5. netstat

用于显示网络连接、路由表和接口状态等。

  • 查看所有活动连接

    netstat
    
    • 输出示例
      Active Connections
      
        Proto  Local Address          Foreign Address        State
      
      
        TCP    192.168.1.100:1234     example.com:80         ESTABLISHED
        TCP    192.168.1.100:5678     another.com:443        TIME_WAIT
      
  • 显示所有端口的监听状态

    netstat -an
    
    • 输出示例
      Active Connections
      
        Proto  Local Address          Foreign Address        State
        TCP    0.0.0.0:80             0.0.0.0:0              LISTENING
        TCP    192.168.1.100:1234     93.184.216.34:80       ESTABLISHED
      
  • 显示应用程序和端口的对应关系

    netstat -ab
    
    • 输出示例
      Active Connections
      
        Proto  Local Address          Foreign Address        State           PID
        TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       1234
          [apache.exe]
        TCP    192.168.1.100:1234     93.184.216.34:80       ESTABLISHED     5678
          [chrome.exe]
      

三、管理Windows防火墙

1. 查看防火墙状态
netsh advfirewall show allprofiles
  • 输出示例
    Domain Profile Settings:
    ----------------------------------------------------------------------
    State                                 ON
    Firewall Policy                       BlockInbound,AllowOutbound
    LocalFirewallRules                    N/A (GPO-store only)
    LocalConSecRules                      N/A (GPO-store only)
    InboundUserNotification               Enable
    RemoteManagement                      Disable
    UnicastResponseToMulticast            Enable
    
    Private Profile Settings:
    ----------------------------------------------------------------------
    State                                 ON
    Firewall Policy                       BlockInbound,AllowOutbound
    LocalFirewallRules                    N/A (GPO-store only)
    LocalConSecRules                      N/A (GPO-store only)
    InboundUserNotification               Enable
    RemoteManagement                      Disable
    UnicastResponseToMulticast            Enable
    
    Public Profile Settings:
    ----------------------------------------------------------------------
    State                                 ON
    Firewall Policy                       BlockInbound,AllowOutbound
    LocalFirewallRules                    N/A (GPO-store only)
    LocalConSecRules                      N/A (GPO-store only)
    InboundUserNotification               Enable
    RemoteManagement                      Disable
    UnicastResponseToMulticast            Enable
    
2. 启用防火墙
netsh advfirewall set allprofiles state on
3. 禁用防火墙
netsh advfirewall set allprofiles state off
4. 允许应用程序通过防火墙
netsh advfirewall firewall add rule name="允许应用程序" dir=in action=allow program="C:\path\to\app.exe" enable=yes
5. 阻止特定端口的入站流量
netsh advfirewall firewall add rule name="阻止端口" dir=in action=block protocol=TCP localport=8080
6. 删除防火墙规则
netsh advfirewall firewall delete rule name="阻止端口"

四、共享和远程访问配置

1. net use

用于连接和断开共享资源。

  • 连接共享资源

    net use X: \\服务器\共享
    
    • 示例
      net use X: \\192.168.1.1\shared_folder
      
  • 断开共享资源

    net use X: /delete
    
2. mstsc

用于启动远程桌面连接。

  • 连接到远程计算机
    mstsc /v:远程IP地址
    
    • 示例
      mstsc /v:192.168.1.1
      

五、网络服务管理

1. 查看网络服务状态
net start
  • 输出示例
    These Windows services are started:
    
       Application Layer Gateway Service
       Background Intelligent Transfer Service
       Base Filtering Engine
       COM+ Event System
       DHCP Client
       DNS Client
       ...
    
2. 启动网络服务
net start 服务名称
  • 示例
    net start "DHCP Client"
    
3. 停止网络服务
net stop 服务名称
  • 示例
    net stop "DHCP Client"
    

六、其他网络配置命令

1. route

用于查看和配置路由表。

  • 查看路由表

    route print
    
    • 输出示例
      ===========================================================================
      Interface List
       15...00 1c 42 00 00 08 ......Intel(R) Ethernet Connection (7) I219-V
        1...........................Software Loopback Interface 1
       11...00 1c 42 00 00 09 ......Microsoft Wi-Fi Direct Virtual Adapter
      ===========================================================================
      
      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    331
              127.0.0.1  255.255.255.255       On-link      127.0.0.1    331
        127.255.255.255  255.255.255.255       On-link      127.0.0.1    331
            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
      ===========================================================================
      
  • 添加静态路由

    route add 目标网络 MASK 子网掩码 网关
    
    • 示例
      route add 192.168.2.0 MASK 255.255.255.0 192.168.1.1
      
  • 删除静态路由

    route delete 目标网络
    
    • 示例
      route delete 192.168.2.0
      
2. arp

用于查看和管理ARP缓存。

  • 查看ARP缓存

    arp -a
    
    • 输出示例
      Interface: 192.168.1.100 --- 0x15
        Internet Address      Physical Address      Type
        192.168.1.1           00-14-22-01-23-45     dynamic
        192.168.1.255         ff-ff-ff-ff-ff-ff     static
      
  • 添加静态ARP条目

    arp -s IP地址 MAC地址
    
    • 示例
      arp -s 192.168.1.200 00-11-22-33-44-55
      
  • 删除ARP条目

    arp -d IP地址
    
    • 示例
      arp -d 192.168.1.200
      

总结

以上命令涵盖了Windows系统中常用的网络配置和管理操作。通过掌握这些命令,网络管理员可以有效地配置网络接口、诊断网络问题、管理防火墙规则和共享资源,从而确保网络的正常运行和安全性。

相关推荐

  1. Windows系统网络配置命令详细指南

    2024-07-13 21:58:04       18 阅读
  2. 网络配置以及命令详解

    2024-07-13 21:58:04       41 阅读
  3. MySQL在Windows系统上的详细安装指南

    2024-07-13 21:58:04       17 阅读
  4. linux系统安全配置命令详解

    2024-07-13 21:58:04       37 阅读
  5. Centos---命令详解 vi 系统服务 网络

    2024-07-13 21:58:04       21 阅读
  6. Linux网络配置命令

    2024-07-13 21:58:04       57 阅读
  7. ovs网络配置命令

    2024-07-13 21:58:04       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-13 21:58:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-13 21:58:04       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-13 21:58:04       58 阅读
  4. Python语言-面向对象

    2024-07-13 21:58:04       69 阅读

热门阅读

  1. PHP语言教程与实战案例

    2024-07-13 21:58:04       23 阅读
  2. 在线课程平台

    2024-07-13 21:58:04       24 阅读
  3. @Autowired 和 @Resource 的区别

    2024-07-13 21:58:04       17 阅读
  4. 基于深度学习的语言生成

    2024-07-13 21:58:04       22 阅读
  5. 华为OD机考题(HJ6 质数因子)

    2024-07-13 21:58:04       22 阅读
  6. (day11)1614. 括号的最大嵌套深度

    2024-07-13 21:58:04       19 阅读
  7. anaconda常用指令学习

    2024-07-13 21:58:04       18 阅读