Windows Networking & Security

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.

โฑ๏ธ 10 min read๐ŸŸข Beginner Friendly๐Ÿ“… Updated: 2026

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
Direction Inbound Traffic entering PC
Protocol & Port TCP 443 HTTPS service port
Profile Scope Private Domain / Private / Public
Action Allow Allow or Block
Windows NIC Ethernet / Wi-Fi IP + DNS + Gateway Network Location Awareness DEFENDER FIREWALL PROFILES Domain Active Directory LAN Private Trusted Home / Office Public Untrusted (Blocks SMB) SMB File Shares TCP 445 (LAN Only) Internet / Cloud Outbound HTTPS (TCP 443) Unsolicited Inbound Blocked
Windows automatically assigns your NIC to Domain, Private, or Public โ€” enforcing stricter inbound blocks on Public networks.

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
Full IP, MAC, DHCP & DNS Details
Shows IPv4/IPv6, subnet mask, default gateway, DHCP lease times, and configured DNS servers for every adapter.
Example: ipconfig /all | findstr /i "IPv4 DNS"
ipconfig /flushdns
Clear Local DNS Resolver Cache
Forces Windows to discard cached domain-to-IP mappings and query your DNS server fresh.
Verify cache: ipconfig /displaydns
ipconfig /release
Drop Current DHCP IP Lease
Releases your DHCP-assigned IPv4 address back to the router/DHCP server.
Pair with ipconfig /renew right after.
ipconfig /renew
Request a Fresh DHCP IP Lease
Contacts the DHCP server to obtain a new IP, gateway, and DNS configuration.
Target one adapter: ipconfig /renew "Ethernet"
Get-NetIPAddress
Inspect IPs as PowerShell Objects
Modern replacement for ipconfig that lets you filter by interface, IPv4/IPv6, or prefix length.
Also see: Get-NetAdapter (link speed & status)
Resolve-DnsName
Query DNS Records (PowerShell)
Modern replacement for nslookup. Supports A, AAAA, MX, TXT, CNAME, and custom DNS servers.
Example: Resolve-DnsName shekharit.com -Server 1.1.1.1

02 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
Check Domain, Private & Public Profiles
Shows whether the firewall is enabled and its default inbound/outbound behavior for each profile.
Check active NIC profile: Get-NetConnectionProfile
New-NetFirewallRule
Allow an Inbound Port Safely Admin
Creates a scoped rule allowing TCP 8080 only on Private networks (not Public Wi-Fi).
Remove later: Remove-NetFirewallRule -DisplayName "Allow-App-8080"
Get-NetFirewallRule
Audit Active Inbound Rules
Lists all currently enabled inbound rules so you can spot unexpected open ports.
Filter by name: Get-NetFirewallRule -DisplayName "*SSH*"
netsh advfirewall
Classic CMD Firewall & Network Reset Admin
Works in batch scripts and legacy systems. Also useful for exporting/importing firewall policy.
Reset TCP/IP stack: netsh int ip reset & netsh winsock reset

03 Diagnostics, Ports & Routing

Pinpoint whether a connection is blocked by DNS, a router hop, a local listening port, or a firewall.

Test-NetConnection -Port
Test TCP Port Reachability (PowerShell)
Checks if a specific TCP port (like 443, 22, 3389, or 445) is open and reachable โ€” far better than plain ping.
Short alias: tnc 192.168.1.10 -Port 3389
netstat -ano
List Listening Ports & Owning PID
-a = all connections, -n = numeric IPs/ports (fast), -o = Process ID (PID) so you can find which app owns a port.
Find process by PID: tasklist /fi "pid eq 4120"
arp -a
View Local IP-to-MAC Address Table
Shows Layer-2 neighbors on your LAN subnet and helps detect duplicate IPs or ARP spoofing.
Clear cache (Admin): arp -d *
route print
Display the Windows Routing Table
Shows where traffic goes (default 0.0.0.0 gateway, VPN split-tunnel routes, and interface metrics).
PowerShell equivalent: Get-NetRoute -AddressFamily IPv4
pathping
Trace Route + Per-Hop Packet Loss
Combines tracert and ping over ~25 seconds to show which exact router hop is dropping packets.
Use -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
Map or List SMB Network Drives
Mounts a remote SMB share as a drive letter or lists active network connections.
Disconnect all: net use * /delete
Get-SmbShare
List Folders Shared by This PC Admin
Shows all active SMB shares (including hidden admin shares like C$ and ADMIN$).
See who is connected: Get-SmbSession
hosts file
Local DNS Override File Admin to Edit
Path: C:\Windows\System32\drivers\etc\hosts. Checked before external DNS โ€” great for local dev or testing migrations.
Format: 127.0.0.1 myapp.local
Memory Trick: Think of the 3 Windows Firewall profiles as D-P-P: Domain (work Active Directory), Private (your home router), and Public (coffee shop Wi-Fi โ€” lock it down!). And remember: Test-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.

โš ๏ธHigh-Risk Actions to Avoid
1. Disabling Domain or Public Firewall Profiles (Set-NetFirewallProfile -Profile Domain,Public -Enabled False)
Turning off the entire firewall instead of opening one specific port exposes every listening service on your PC. Always create a targeted New-NetFirewallRule scoped to the exact port and profile you need.
2. Exposing SMB Port 445 to the Public Network or Internet
Port 445 (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.
3. Running ipconfig /release or netsh int ip reset over RDP
If you are connected to a remote server via RDP or SSH, releasing its IP or resetting the TCP/IP stack will immediately sever your remote session.