ZetCode

Windows Command Prompt Network Commands

last modified July 14, 2025

Windows Command Prompt provides powerful network commands for troubleshooting, configuration, and monitoring. These tools help diagnose connectivity issues, analyze network performance, and configure network settings. Network commands are essential for system administrators and IT professionals.

The commands range from basic connectivity testing to advanced configuration. They can reveal IP addresses, test connections, display routing tables, and more. Many network problems can be diagnosed without graphical tools using these commands. They work across all Windows versions from Windows XP to 11.

Network commands typically require administrative privileges for full functionality. Some commands provide real-time monitoring capabilities. Others generate statistics about network usage and performance. Learning these commands enhances your ability to manage Windows networks effectively.

This tutorial covers essential network commands with practical examples. We'll explore IP configuration, connectivity testing, DNS resolution, and more. Each example includes detailed explanations of command syntax and output interpretation.

Basic Network Definitions

Before diving into commands, let's define key network concepts. Understanding these terms helps interpret command output and diagnose issues.

IP Address: A unique identifier for devices on a network. IPv4 uses four octets (e.g., 192.168.1.1), while IPv6 uses hexadecimal.

Subnet Mask: Determines which portion of an IP address identifies the network and which identifies the host. Common masks include 255.255.255.0 (/24).

Gateway: The device (usually a router) that connects a local network to other networks, including the internet.

DNS: Domain Name System translates human-readable domain names (e.g., zetcode.com) to IP addresses.

MAC Address: A hardware identifier for network interfaces, unique to each device, formatted as six hexadecimal pairs.

Checking IP Configuration

The ipconfig command displays current network configuration. It shows IP addresses, subnet masks, gateways, and DNS servers for all network adapters.

ipconfig.bat
@echo off
echo Basic IP Configuration:
ipconfig
echo Detailed IP Configuration:
ipconfig /all
echo Flushing DNS Cache:
ipconfig /flushdns

This script demonstrates basic and detailed IP configuration output. It also shows how to clear the DNS resolver cache.

ipconfig

Displays basic IP configuration for all network adapters. Shows IPv4/IPv6 addresses, subnet masks, and default gateways. Output varies by system.

ipconfig /all

Shows complete network configuration including MAC addresses, DHCP status, DNS servers, and more. Essential for detailed troubleshooting.

ipconfig /flushdns

Clears the DNS resolver cache. Useful when troubleshooting DNS resolution problems after changing DNS settings.

C:\>ipconfig.bat
Basic IP Configuration:

Windows IP Configuration

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : localdomain
   IPv4 Address. . . . . . . . . . . : 192.168.1.100
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

Detailed IP Configuration:
...
DNS Resolver Cache has been flushed.

Output shows basic network info and confirms DNS cache was cleared. The /all output is truncated for brevity.

Testing Network Connectivity

The ping command tests connectivity to another network device. It sends ICMP echo requests and measures response times. Ping helps diagnose connection issues and measure latency.

pingtest.bat
@echo off
echo Testing connection to Google DNS:
ping 8.8.8.8
echo Testing connection to ZetCode:
ping zetcode.com
echo Continuous ping to gateway:
ping -t 192.168.1.1

This script demonstrates basic ping usage including continuous pinging. Press Ctrl+C to stop continuous ping.

ping 8.8.8.8

Tests connectivity to Google's public DNS server (8.8.8.8). By default sends four packets and shows response times. Successful replies indicate connectivity.

ping zetcode.com

Tests connectivity to a domain name, demonstrating DNS resolution. First resolves the name to IP, then pings that address. Useful for DNS testing.

ping -t 192.168.1.1

Pings continuously until stopped (Ctrl+C). The -t switch enables persistent testing. Useful for monitoring connection stability over time.

C:\>pingtest.bat
Testing connection to Google DNS:

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=15ms TTL=117
Reply from 8.8.8.8: bytes=32 time=16ms TTL=117
Reply from 8.8.8.8: bytes=32 time=14ms TTL=117
Reply from 8.8.8.8: bytes=32 time=15ms TTL=117

Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 14ms, Maximum = 16ms, Average = 15ms

Output shows successful pings with response times. Continuous ping output continues until manually stopped.

Tracing Network Routes

The tracert command traces the path packets take to reach a destination. It shows each hop (router) along the route and measures latency at each point. Tracert helps identify where connection problems occur.

traceroute.bat
@echo off
echo Tracing route to Google DNS:
tracert 8.8.8.8
echo Tracing route with no DNS resolution:
tracert -d 8.8.8.8

This script demonstrates route tracing with and without DNS resolution. The -d switch speeds up tracing by skipping reverse DNS lookups.

tracert 8.8.8.8

Traces the network path to 8.8.8.8 showing all intermediate hops. Each hop shows three latency measurements and the router's hostname (if resolvable).

tracert -d 8.8.8.8

Performs the same trace but doesn't resolve IPs to hostnames. Faster as it skips DNS lookups for each hop. Shows only IP addresses.

C:\>traceroute.bat
Tracing route to 8.8.8.8 over a maximum of 30 hops

  1     1 ms     1 ms     1 ms  router.local [192.168.1.1]
  2    10 ms     9 ms    10 ms  isp-gateway.example.com [203.0.113.1]
  3    12 ms    11 ms    12 ms  72.14.203.25
  4    14 ms    13 ms    14 ms  8.8.8.8

Trace complete.

Output shows the path through the local network, ISP, and to destination. Each line represents one network hop with latency measurements.

Checking Network Statistics

The netstat command displays network connections, routing tables, and interface statistics. It helps monitor active connections and troubleshoot network issues. Netstat provides various views of network activity.

netstats.bat
@echo off
echo Active connections:
netstat
echo All listening ports:
netstat -ano
echo Statistics by protocol:
netstat -s

This script demonstrates different netstat views. The -a shows all ports, -n skips name resolution, and -o shows process IDs.

netstat

Displays active TCP connections and listening ports. Shows local/foreign addresses and connection state. Basic view without numeric IPs.

netstat -ano

Shows all listening ports (-a), numeric addresses (-n), and owning process IDs (-o). Essential for identifying which programs use network ports.

netstat -s

Displays statistics for each protocol (TCP, UDP, ICMP). Shows packets sent/ received, errors, and more. Useful for detecting network problems.

C:\>netstats.bat
Active connections:

  Proto  Local Address          Foreign Address        State
  TCP    192.168.1.100:49876    stackoverflow:https   ESTABLISHED
  TCP    192.168.1.100:49877    github:https          ESTABLISHED

All listening ports:
  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:80             0.0.0.0:0             LISTENING       4
  TCP    0.0.0.0:135            0.0.0.0:0             LISTENING       928

Output shows active connections and listening services. The -s statistics output is extensive and truncated here.

DNS Lookup and Troubleshooting

The nslookup command queries DNS servers to resolve domain names to IP addresses and vice versa. It helps diagnose DNS resolution problems and verify DNS records. Nslookup works in both interactive and non-interactive modes.

dnstest.bat
@echo off
echo Basic DNS lookup:
nslookup zetcode.com
echo Specific DNS server query:
nslookup zetcode.com 8.8.8.8
echo Reverse DNS lookup:
nslookup 172.217.14.206

This script demonstrates forward and reverse DNS lookups. It shows how to query specific DNS servers and check PTR records.

nslookup zetcode.com

Performs a standard DNS lookup for zetcode.com. Shows the resolved IP address and the DNS server used for the query.

nslookup zetcode.com 8.8.8.8

Queries a specific DNS server (8.8.8.8) instead of the default. Useful for testing if DNS problems are server-specific.

nslookup 172.217.14.206

Performs a reverse DNS lookup (PTR record query) for an IP address. Attempts to find the domain name associated with the IP.

C:\>dnstest.bat
Basic DNS lookup:
Server:  UnKnown
Address:  192.168.1.1

Non-authoritative answer:
Name:    zetcode.com
Addresses:  2606:4700:20::681a:9e5
          172.67.26.229
          104.26.9.229

Specific DNS server query:
Server:  dns.google
Address:  8.8.8.8

Non-authoritative answer:
Name:    zetcode.com
Addresses:  2606:4700:20::681a:9e5
          172.67.26.229
          104.26.9.229

Output shows successful DNS resolutions. The exact IPs may vary based on current DNS records and CDN configurations.

Source

Windows Command Reference

In this article, we have covered essential Windows Command Prompt network commands. These tools are invaluable for network troubleshooting and administration in Windows environments.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.