Useful Windows network commands

1 ping

Usually, it can be used for testing the connectivity and the network latency in millisecond (ms)

TTL: Time To Live

ping <host name>
ping <domain name>
ping <IP address>
ping google.com
ping google.com

1.1 ping 127.0.0.1: Check if the Network interface controller (NIC), TCP/IP protocol, subnet mask works.

1.2 ping the current host’s IP address: Check if local configuration/installation are correct. (If not, we can check network equipment and cables.)

1.3 ping IP within the current subnet: Check if the NIC works in local area network (LAN), if there is no reply, it means that the subnet mask may be incorrect, network cable issue, configuration issue etc.

1.4 ping default gateway: Check if the gateway works.

1.5 ping remote IP address: Check if the default gateway works, if the device can get on to internet.

1.6 ping localhost: localhost is an operating system (OS) reserved host name. It resolves to 127.0.0.1. Usually, devices should be able to resolve this to such address, otherwise there can be something wrong with the host file (/Window/host for Windows) (/etc/host for Linux)

1.7 ping www.google.com: It will be resolved to IP address first via querying DNS server, if not resolved, it can be the DNS server is not configured correctly or DNS server is not working. Sometimes it can be the domain is blocked by firewall in local area network. (ping can be blocked completely by firewall as well.) Or simply, the domain does not exist.

ping IP -t: ping the IP address continuously until Ctrl + C is pressed.

ping IP -l 1000: ping with specified length (1000 bytes) (default is 32 byte)

ping IP -f -l 1492: ping with specified length without fragmenting the packet.

ping IP -n 10: execute the ping command 10 times.

Note: Ping command can be blocked by firewall deployed in the LAN, while it is a useful and helpful command for troubleshooting the network issues most of the time, but do not rely on it entirely and draw conclusion completely from ping command. Better to use it as a reference.

2 ipconfig

Used for checking TCP/IP configuration. Release, Renew DHCP leasse. Flush DNS cache etc.

2.1 ipconfig: Show IP address, Subnet Mask, Default Gateway of the interface

2.2 ipconfig /all: Show all details including DNS, WINS and extra information, MAC address, DHCP server IP address, DHCP lease obtained time, expire time etc.

2.3 ipconfig /release: Release all IP addresses obtained from DHCP server

2.4 ipconfig /renew: Renew the IP address from DHCP server, usually it will be the same IP address before “ipconfig /release”

2.5 ipconfig /flushdns: Flush DNS cache in Windows

2.6 ipconfig /displaydns: Print DNS cache from local machine on screen. (We can use ipconfig /displaydns > C:\dns-cache.txt to save output to text file for easier diagnostic)

3 tracert (traceroute)

Windows: tracert

Linux: traceroute

Used for checking routing condition/path and latency etc.

tracert <host name>
tracert <domain name>
tracert <IP address>
tracert google.com
tracert google.com

Output with 5 columns

Column 1: The number of the hop

Column 2: Round Trip Time 1 (RTT 1)

Column 3: RTT 2

Column 4: RTT 3

Column 5: IP address, name of the router

If any packet loss happen, “*” will be used instead of time in “ms”

4 arp (Address Resolution Protocol)

Used to check the corresponding Media Access Control Address (MAC address) of the IP address.

Can be used to output ARP cached information from current device or other devices. Manually set the MAC/IP pair.

arp -a
arp -a <IP>
arp -s <IP>
arp -d <IP>

4.1 arp -a: Show all data in ARP cache

4.2 arp -a IP: Only show all ARP cache from one of the NIC associated with the specified IP address

4.3 arp -s IP MAC: Manually add the IP MAC pair as static ARP cache to the system (Persistent across reboots)

4.4 arp -d IP: Manually delete a static ARP cache

5 route

Used for checking and configuring routing information.

route print
route add
route change

5.1 route print: Show current routing table

5.2 route add:

e.g. To configure a routing table for reaching 192.168.1.11, through 5 networks, via one of the route on local network which is 192.168.2.22, where the subnet is 255.255.255.224, then the following command will be used

route add 192.168.1.11 mask 255.255.255.224 192.168.2.22 metric 5

5.3 route change:

Can be used to change the path for the routing table but not the routing destination.

e.g. Change the above example from metric 5 to metric 2

route change 192.168.1.11 mask 255.255.255.224 metric 2

5.4 route delete: Delete routing table.

route delete 192.168.1.11

6 nslookup

Used to find out domain name/IP address of an host. Usually require DNS server.

6.1 nslookup: Show current configured DNS server on the host

nslookup

6.2 nslookup google.com: Use the default DNS server to check DNS records

nslookup goolge.com

6.3 nslookup google.com 8.8.8.8: Use the google DNS server (8.8.8.8) to resolve domain (google.com)

nslookup google.com 8.8.8.8
nslookup google.com 8.8.8.8
nslookup google.com 8.8.8.8

6.4 nslookup <IP address> <DNS server>: Reverse lookup

nslookup 8.8.8.8 8.8.8.8
nslookup 8.8.8.8 8.8.8.8
nslookup 8.8.8.8 8.8.8.8

7 netstat

Get current network information from current host.

Show active TCP connections, Ports the host listening on, Ethernet information, IP routing table, IPv4 information (IP, ICMP, TCP, UDP protocol), IPv6 information (IPv6, ICMPv6, TCP, UDP over IPv6).

7.1 netstat

Show active TCP connections

netstat

7.2 netstat -a: Show all connections, including “ESTABLISHED”, “LISTENING” states. (With host name/domain)

7.3 netstat -n: List the detail in IP address rather than host name/domain name.

7.4 netstat -e: Show statistical data about Network interface. (Total Bytes transferred, Errors, Discards, Unicast packets, Unknown protocols, Non-unicast packets)

7.5 netstat -r: Similar to route print, the output is similar to rout print command as well. Output routing table information.

Network DestinationDestination network
0.0.0.0Unknown network (Added automatically when using default gateway)
127.0.0.0Local host network address
224.0.0.0Multicast address
255.255.255.255Broadcast address
NetmaskNetmask address
GatewayGateway address
InterfaceInterface address
MetricHops

8 nbtstat

Used to troubleshoot NetBIOS.

8.1 nbtstat -n: Show information about your workgroup.

8.2 nbtstat -a <IP Aaddress>: Show NetBIOS information about that device

9 net

Used for service related, network related.

9.1 net help: Get more help

9.2 net hep <command> e.g. net help accounts: To get help on that specific net command (accounts in this case)

CommandExampleDescription
NET ACCOUNTSNET ACCOUNTSShow current accounts information
NET CONFIGNET CONFIG SERVER (or WORKSTATION)Show network configuration
NET GROUPNET GROUPShow groups (Only available on Domain Controller)
NET SENDNET SEND server1 “test message”Send broadcast message to other computers
NET SHARENET SHAREShow shared files/folders from local host
NET STARTNET START FaxStart service
NET STOPNET STOP FaxStop service
NET STATISTICSNET STATISTICS WORKSTATION (or SERVER)Show network statistics
NET USENET USE x:\serverFolderMap network drive with letter
NET USERNET USERShow accounts/users on local host
NET VIEWNET VIEWShow available computers on network

Windows Operating System Penetration – Disable security measures via commands

We must have obtained admin privilege first, then execute following commands under administrator privilege.

  • Disable built-in firewall
netsh advfirewall set allprofiles state off
Disable Windows firewall
Disable Windows firewall

  • Disable Windows Defender (Via sc stop or net stop command, or via registry)

  • Disable DEP
bcdedit.exe /set {current} nx AlwaysOff 

  • Disable Bitlocker
manage-bde -off C:

(Use following command to check Bitlocker status)

manage-bde -status C:
manage-bde
manage-bde

How to: Check Windows Storage Space, Storage pool virtual disk Columns

Using PowerShell

Get-VirtualDisk "name of the virtual disk" | Select-Object *

To get general information, use following command instead

Get-VirtualDisk "name of the virtual disk"

Using Server Manager

1 Launch Windows “Server Manager”

2 In Windows Server 2019, navigate to “Server Manager -> File and Storage Services -> Storage Pools -> Virtual Disks”

3 Right click on the virtual disk, select “Property”

4 Click on “Details”

5 Select “NumberOfColumns” from “Property:”

6 The number of columns will be displayed underneath.

Note

If after rebooting, virtual disks are not attaching automatically, follow this guide to make them auto attach on reboot.

How to fix: Windows Storage Space/Storage Pool physical disk lost communication, replace dead physical disk

Keywords: Windows Server, Windows Server 2019, Windows Server Storage Space, Windows Server Storage Pool, physical disk, lost communication, Warning, Error, replace, replace disk

If you are running Windows Storage Space on USB disks, when you change disk cache settings, or accidentally disconnected one of the USB disk from Windows Storage Space (With minimum 1 disk fault tolerance, e.g. Parity, Mirror), or due to other reasons that caused one of the physical disk showing error or warning from Windows Server Manager

For simply reattaching the physical disk, check our this guide: Windows Server Storage Space/Storage Pool Reattach straightway after physical disk retired

Warning: Always backup all data on the storage pool if possible or at least important data

Replace the physical disk

1 Launch “Windows PowerShell” in admin mode

2 Use following command to list all physical disks

Get-PhysicalDisk
Windows PowerShell - Get-PhysicalDisk
Windows PowerShell – Get-PhysicalDisk

3 If you have multiple physical disks with same name, use following command to distinguish among them, you probably can find serial number on the label from hard drive

Get-PhysicalDisk | select-object serialnumber, uniqueid, friendlyname, operationstatus, healthstatus
Windows PowerShell - Get-PhysicalDisk | select-object serialnumber, uniqueid, friendlyname, operationstatus, healthstatus
Windows PowerShell – Get-PhysicalDisk | select-object serialnumber, uniqueid, friendlyname, operationstatus, healthstatus

(Before mark the physical disk as retired you might want to check which virtual disks will be affected, you can use following command to check virtual disks)

Get-Virtual-Disk

4 Mark the disk we want to remove as “retired”

  • Using Friendly Name
Set-PhysicalDisk -FriendlyName 'PhysicalDiskName' -Usage Retired

e.g.

 Set-PhysicalDisk -FriendlyName 'Contoso Disk' -Usage Retired 
  • Using Serial Number
Set-PhysicalDisk -uniqueid 'Serial Number' -Usage Retired

e.g.

Set-PhysicalDisk -uniqueid '{29e928d2-2793-11ea-a6db-000c29b85813}' -Usage Retired
Windows PowerShell - Set-PhysicalDisk -uniqueid 'Serial Number' -Usage Retired
Windows PowerShell – Set-PhysicalDisk -uniqueid ‘Serial Number’ -Usage Retired

5 Once the disk is marked to be removed.  We need to rebuild each of our virtual disks

Repair-VirtualDisk -FriendlyName 'Name of the virtual disk within the pool'

e.g.

Repair-VirtualDisk -FriendlyName 'my disk on pool'

6 We can monitor the repairing progress

Get-StorageJob
Windows PowerShell - Get-StorageJob
Windows PowerShell – Get-StorageJob

7 Once everything is done, we can remove the disk from the pool

Remove-PhysicalDisk -FriendlyName 'PhysicalDiskName'

Note: If you have many physical disks with same name we can use “Server Manager” to remove it, follow step 7.1 to

7.1 Launch “Server Manager”

Windows Server 2019 - Server Manager - Dashboard
Windows Server 2019 – Server Manager – Dashboard

7.2 Find the disk with exclamation mark and showing “Retired” as operational Status

Windows Server 2019 - Server Manager -> File and Storage Services -> Storage Pools -> Physical Disks
Windows Server 2019 – Server Manager -> File and Storage Services -> Storage Pools -> Physical Disks

7.3 Right click on the disk then click on “Remove Disk”, you will see following window

Windows Server 2019 - Server Manager -> File and Storage Services -> Storage Pools -> Physical Disks -> Remove Disk
Windows Server 2019 – Server Manager -> File and Storage Services -> Storage Pools -> Physical Disks -> Remove Disk

7.4 When it’s done, following windows will appear

Windows Server 2019 - Server Manager -> File and Storage Services -> Storage Pools -> Physical Disks -> Remove Disk
Windows Server 2019 – Server Manager -> File and Storage Services -> Storage Pools -> Physical Disks -> Remove Disk

8 Now we can attache our new physical disk then add it to the pool from “Server Manager” Window

Re-attach the physical disk

In case of human error caused the physical to be recognised as faulty but you are sure that the physical disk is in prefect condition, we need to re-attach the physical disk

(You might get “suspended 0” from “Get-StorageJob” just continue with the guide, usually the “suspended” will not resolve itself if we don’t do anything…)

2.1 Try to follow step 1 to 8, ignore errors if there is any

2.2 Try to “Reset Disk” if the exclamation mark is gone, try to repair the virtual disk, if it is still there after Reset, continue with step 2.3

Windows Server 2019 - Server Manager -> File and Storage Services -> Storage Pools -> Physical Disks -> Remove Disk
Windows Server 2019 – Server Manager -> File and Storage Services -> Storage Pools -> Physical Disks -> Remove Disk

2.3 Try to follow step 1 – 3 to find out the “serial number” or “friendly name” of the disk which we want to re-attach, then using following command to change the disk state from “Retired” to “Auto”

Set-PhysicalDisk -UniqueID "{3b3bbdf4-cc77-13bd-a8ba-429c9ce9957a}" -Usage AutoSelect

2.4 Now we can follow step 5 to repair the virtual disk in degraded mode (We can right click the virtual disk from “Server Manager” then select “Repair Virtual Disk” as well)

Bonus

Other useful commands

# Optimise the Storage Pool 
Get-StoragePool "pool name" | Optimize-StoragePool
# Update Storage Pool to latest version
Update-StoragePool -FriendlyName "pool name"

Quick steps from Microsoft technet (Not suitable for systems with physical disks with same names)

  1. Open PowerShell in admin mode (PowerShell ISE is better)
  2. To get the names of the disks, type the following command:
    Get-PhysicalDisk
  3. To get the names of the virtual disks, type the following command:
    Get-Virtual-Disk
  4. First mark the disk you want to remove as “retired” by the following command:
    Set-PhysicalDisk -FriendlyName ‘PhysicalDiskXX’ -Usage Retired
  5. Now your disk is mark to be removed.  You need to rebuild each of your virtual disks with the following command:
    Repair-VirtualDisk -FriendlyName ‘My Virtual Disk’
  6. You can monitor the progression of the process by typing the following command:
    Get-StorageJob
  7. Once everything is done, just remove the disk from the pool with this command:
    Remove-PhysicalDisk -FriendlyName ‘PhysicalDiskXX’
  8. That’s it!

How to resolve: Windows – “Destination Path Too Long” Error

Keywords: Microsoft Windows, Destination path too long, long file name, long path, Error, cmd, command prompt, run

When we are trying to rename, delete a folder or file which has very long length “Folder names + file name” or “Folder names” we will encounter following error

“The file name(s) would be too long for the destination folder. You can shorten the file name and try again, or try a location that has a shorter path.”

Microsoft Windows - Destinatoin Path Too Long
Microsoft Windows – Destinatoin Path Too Long

Try following methods

To Delete

1.1 Use Win + R launch “Run” window

Microsoft Windows - Run window
Microsoft Windows – Run window

1.2 Enter “cmd” in “Run” window, press Enter key to launch “Command Prompt” window

1.3 We use following command to delete the folder, including subfolders

rd /s /q "D:\FolderName"

e.g.

rd /s /q "D:\New Folder"

(The root folder “D:\New Folder” will be deleted too)

To Rename

2.1 Follow 1.1 to 1.2 to launch ” Command Prompt” window

2.2 Use following command to rename folder and file with long name which we can’t using windows file explorer

ren "D:\Folder Name" "D:\folder"

e.g.

ren "D:\my folder with very long name" "D:\newname"

ren "D:\folder\file with long name.txt" "D:\folder\file.txt"

e.g.

ren "D:\picture\my text file.txt" "D:\picture\my file.txt" 

How to change Windows proxy settings using cmd/command prompt/registry/.cmd/.bat

Keywords: Microsoft Windows proxy, proxy settings, Registry, regedit, Registry Editor, wildcard

Method 1: Using Registry directly

Warning: Changing other parameters from registry might cause damage to operating system, please modify carefully.

1 Use Win + R key combination open “Run” window

Microsoft Windows - Run window
Microsoft Windows – Run window

2 Enter “regedit” then press “OK” button

3 Find following path

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
Microsoft Windows - Registry Editor
Microsoft Windows – Registry Editor

4 Change/Create “DWORD” Key “ProxyEnable”, Set value to “0” to disable proxy, “1” to enable proxy

Registry Editor - ProxyEnable
Registry Editor – ProxyEnable

If you have enabled proxy from Step 4, follow below steps to continue configuration process

5 Change/Create “String Value” Key “ProxyServer”, Set value to <proxy address>:<port>. e.g.

127.0.0.1:1234 OR myproxyname.com:5678
Registry Editor - ProxyServer
Registry Editor – ProxyServer

Extra: If you need to exclude some addresses from proxy follow Step 6

6 Change/Create “String Value” Key “ProxyOverride”, Set value to include desired addresses which you want to exclude

10.0.0.1;google.com;localhost;*.bing.com;<local>;192.168.100.*
Registry Editor - ProxyOverride
Registry Editor – ProxyOverride

*.bing.com: Any domain under bing.com e.g. ads.bing.com, cdn.bing.com

192.168.100.*: Including the whole subnet (192.168.100.1-192.168.100.254)

<local>: Check the “Don’t use the proxy server for local (intranet) addresses” from Windows Settings

Windows Settings - Proxy
Windows Settings – Proxy

Method 2: Using command prompt

1 Use Win + R key combination open “Run” window

  • Enter following command and hit Enter key to disable proxy
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
  • Enable proxy
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
  • Set proxy IP address and port
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d 10.0.1.1:1234 /f
  • Bypass for selected addresses
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "10.0.0.1;google.com;localhost;*.bing.com;192.168.100.*;<local>" /f
  • Clean proxy settings
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /f
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /f

Method 3: Import proxy settings by using Registry file

1 Save desired proxy settings to a text file then change file extension from “.txt” to “.reg”

e.g. Save following text to “proxy.reg”

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=dword:00000001
"ProxyServer"="10.0.1.0:1234"
"ProxyOverride"="10.0.0.1;google.com;localhost;*.bing.com;192.168.100.*"

2 Double click on “proxy.reg”

proxy.reg
proxy.reg

3 Click on “Yes” if you see this Window

User Account Control (UAC) Window - Registry Editor
User Account Control (UAC) Window – Registry Editor

4 Click on “Yes” to continue

Registry Editor - "Adding information can unintentionally change of delete values and cause components to stop working correctly. If you do not trust the source of this information in .... .reg, do not add it to the registry." "Are you sure you want to continue?"
Registry Editor – “Adding information can unintentionally change of delete values and cause components to stop working correctly. If you do not trust the source of this information in …. .reg, do not add it to the registry.” “Are you sure you want to continue?”

5 Now the proxy settings is imported, click on “OK”.

Registry Editor - "The keys and values contained in .. .reg have been successfully added to the registry."
Registry Editor – “The keys and values contained in .. .reg have been successfully added to the registry.”

Method 4: Using “.cmd” “.bat” file

1 Create a text file

2 Add following content to the text file

reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d 10.0.1.0:1234 /f
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "10.0.0.1;google.com;localhost;*.bing.com;192.168.100.*" /f

3 Rename it to “enable-proxy.cmd” or “enable-proxy.bat”

4 Double click on enable-proxy.cmd” or “enable-proxy.bat”, now the proxy is configured (If not, run with administrator account)

To Disable proxy

1 Add following content to “disable-proxy.cmd” or “disable-proxy.bat”

reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f

2 Double click on “disable-proxy.cmd” or “disable-proxy.bat” to run the commands

To Clean proxy settings (Doesn’t matter enabled or disabled)

1 Add following content to “clean-proxy.cmd” or “clean-proxy.bat”

reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /f
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /f

2 Double click on “clean-proxy.cmd” or “clean-proxy.bat” to run the commands

Note: Using unknown proxy servers can be danger, especially when browsing websites or using apps which requires to login.