Windows Networking, Netsh & Firewall
Your quick-reference toolkit for Windows network troubleshooting: IP & DNS commands, Windows Defender Firewall rules via PowerShell & netsh, port diagnostics, SMB file shares, and safe firewall hygiene.
0 Anatomy of a PowerShell Firewall Rule
Modern Windows firewall rules filter traffic by Direction, Port/Protocol, Profile, and Action:
New-NetFirewallRule -DisplayName "Web-HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
01 IP & DNS CLI
Start here whenever a machine loses internet, gets a self-assigned 169.254.x.x APIPA address, or resolves a stale DNS record.
ipconfig /all
ipconfig /all | findstr /i "IPv4 DNS"ipconfig /flushdns
ipconfig /displaydnsipconfig /release
ipconfig /renew right after.ipconfig /renew
ipconfig /renew "Ethernet"Get-NetIPAddress
ipconfig that lets you filter by interface, IPv4/IPv6, or prefix length.Get-NetAdapter (link speed & status)Resolve-DnsName
nslookup. Supports A, AAAA, MX, TXT, CNAME, and custom DNS servers.Resolve-DnsName shekharit.com -Server 1.1.1.102 Windows Defender Firewall (PowerShell & Netsh)
Manage firewall profiles and inbound/outbound rules cleanly from an elevated terminal without clicking through dozens of GUI dialogs.
Get-NetFirewallProfile
Get-NetConnectionProfileNew-NetFirewallRule
8080 only on Private networks (not Public Wi-Fi).Remove-NetFirewallRule -DisplayName "Allow-App-8080"Get-NetFirewallRule
Get-NetFirewallRule -DisplayName "*SSH*"netsh advfirewall
netsh int ip reset & netsh winsock reset03 Diagnostics, Ports & Routing
Pinpoint whether a connection is blocked by DNS, a router hop, a local listening port, or a firewall.
Test-NetConnection -Port
443, 22, 3389, or 445) is open and reachable โ far better than plain ping.tnc 192.168.1.10 -Port 3389netstat -ano
-a = all connections, -n = numeric IPs/ports (fast), -o = Process ID (PID) so you can find which app owns a port.tasklist /fi "pid eq 4120"arp -a
arp -d *route print
0.0.0.0 gateway, VPN split-tunnel routes, and interface metrics).Get-NetRoute -AddressFamily IPv4pathping
tracert and ping over ~25 seconds to show which exact router hop is dropping packets.-n to skip slow reverse-DNS lookups.04 SMB File Sharing & Hosts File
Connect to shared folders on a LAN, audit what your PC is sharing, and override local DNS names with the Windows hosts file.
net use
net use * /deleteGet-SmbShare
C$ and ADMIN$).Get-SmbSessionhosts file
C:\Windows\System32\drivers\etc\hosts. Checked before external DNS โ great for local dev or testing migrations.127.0.0.1 myapp.localTest-NetConnection -Port beats ping because firewalls often drop ICMP ping while allowing TCP 443.
05 Danger Zone โ Network & Firewall Mistakes
Misconfiguring firewall profiles or SMB exposure can leave a Windows machine vulnerable on untrusted networks or lock you out of remote sessions.
Set-NetFirewallProfile -Profile Domain,Public -Enabled False)New-NetFirewallRule scoped to the exact port and profile you need.445 to the Public Network or Internet445 (SMB file sharing) is a prime target for lateral movement and ransomware. Keep File and Printer Sharing restricted to Private or Domain profiles only โ never Public or Any.ipconfig /release or netsh int ip reset over RDP