networking
Common networking commands for interfaces, ports, DNS, routing, firewalls and connectivity troubleshooting.
Most Used
Start here for local network details, open ports and connection failures.
Show network interfaces and local IP addresses
Identify network interfaces and the IP addresses assigned to them.
scutil --nwiifconfig | awk '/^[a-zA-Z0-9]/ { iface=$1; sub(/:$/, "", iface) } /inet / { print iface, $2 } /inet6 / && $2 !~ /^fe80:/ { print iface, $2 }'ip -brief address show upip -brief address show up | awk '{ for (i=3; i<=NF; i++) if ($i ~ /^[0-9a-fA-F:.]+\/[0-9]+$/) print $1, $i }'ipconfigGet-NetIPAddress -AddressFamily IPv4,IPv6 -ErrorAction SilentlyContinue | Where-Object { $_.AddressState -eq 'Preferred' -and $_.IPAddress -notmatch '^127\.|^::1$|^fe80:' } | ForEach-Object { "$($_.InterfaceAlias) $($_.IPAddress)" }Show listening ports
List TCP ports waiting for incoming connections and the processes using them.
lsof -nP -iTCP -sTCP:LISTENss -lntupGet-NetTCPConnection -State ListenGet-NetTCPConnection -State Listen | ForEach-Object { $p = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue; [PSCustomObject]@{ Address = $_.LocalAddress; Port = $_.LocalPort; Process = $p.ProcessName; PID = $_.OwningProcess } } | Sort-Object Port | Format-Table -AutoSizeCheck whether a local port is in use
Check a specific local port, replacing 3000 with the port you want to inspect.
lsof -nP -i :<port>lsof -nP -i :3000ss -lntup 'sport = :<port>'ss -lntup 'sport = :3000'Get-NetTCPConnection -LocalPort <port>Get-NetTCPConnection -LocalPort 3000Look up a domain's IP address
Check whether DNS can resolve a hostname to an IP address.
dig <domain>dig example.comResolve-DnsName <domain>Resolve-DnsName example.comTrace the route to a host
Show the network hops toward a destination; missing hops may simply ignore probes.
traceroute <host>traceroute example.comtracepath <host>tracepath example.comTest-NetConnection <host> -TraceRouteTest-NetConnection example.com -TraceRouteTest a remote port
Check whether a remote host accepts TCP connections on a specific port.
nc -vz -w 3 <host> <port>nc -vz -w 3 example.com 443Test-NetConnection <host> -Port <port>Test-NetConnection example.com -Port 443Inspect an HTTP or HTTPS request
Show DNS, connection, TLS and HTTP details to help locate a URL failure.
curl -v --connect-timeout 5 --max-time 15 <url>curl -v --connect-timeout 5 --max-time 15 https://example.com/curl.exe -v --connect-timeout 5 --max-time 15 <url>curl.exe -v --connect-timeout 5 --max-time 15 https://example.com/Network diagnostics
Troubleshoot and inspect system network configurations.
Show network status
List network interfaces and their current status.
networksetup -listallhardwareportsip -brief linkGet-NetAdapterShow interface details
Display detailed information for a specific network interface.
ifconfig <iface>ifconfig en0ip address show dev <iface>ip address show dev eth0Get-NetAdapter -Name <iface>Get-NetAdapter -Name EthernetSet interface state
Enable or disable a network interface.
sudo ifconfig <iface> downsudo ifconfig en0 downsudo ip link set <iface> downsudo ip link set eth0 downDisable-NetAdapter -Name <iface>Disable-NetAdapter -Name Ethernetsudo wdutil infoiw devnetsh wlan show interfacesShow configured DNS servers
Display DNS resolver configuration for the system.
scutil --dnsresolvectl statusGet-DnsClientServerAddressCapture network packets
Capture packets on a network interface; stop the capture with Ctrl+C.
sudo tcpdump -i <iface>sudo tcpdump -i en0pktmon start --captureFirewall
Inspect firewall status and manage inbound traffic rules.
Show UFW status
Display the status and rules of the UFW firewall.
sudo ufw status verboseList nftables rules
Display the active nftables ruleset.
sudo nft list rulesetShow application firewall status
Check whether the macOS application firewall is enabled.
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstateShow Windows firewall profiles
Display enabled state and default inbound and outbound actions for each profile.
Get-NetFirewallProfile | Select-Object Name, Enabled, DefaultInboundAction, DefaultOutboundActionAllow incoming traffic
Add a rule allowing incoming TCP traffic on a specific port.
sudo iptables -A INPUT -p tcp --dport <port> -j ACCEPTsudo iptables -A INPUT -p tcp --dport 22 -j ACCEPTNew-NetFirewallRule -DisplayName "Allow Port <port>" -Direction Inbound -Protocol TCP -LocalPort <port> -Action AllowNew-NetFirewallRule -DisplayName "Allow Port 22" -Direction Inbound -Protocol TCP -LocalPort 22 -Action AllowBlock incoming traffic
Add a rule blocking incoming TCP traffic on a specific port.
sudo iptables -A INPUT -p tcp --dport <port> -j DROPsudo iptables -A INPUT -p tcp --dport 80 -j DROPNew-NetFirewallRule -DisplayName "Block Port <port>" -Direction Inbound -Protocol TCP -LocalPort <port> -Action BlockNew-NetFirewallRule -DisplayName "Block Port 80" -Direction Inbound -Protocol TCP -LocalPort 80 -Action BlockRouting
Inspect the routing table and add or remove static routes.
Display routing table
Display the system routing table.
netstat -rnroute printAdd static route
Add a route to a destination subnet through a gateway.
sudo route -n add -net <subnet> <gateway>sudo route -n add -net {{SUBNET_VAR}} {{GATEWAY_IP_ADDRESS_VAR}}sudo ip route add <subnet> via <gateway>sudo ip route add {{SUBNET_VAR}} via {{GATEWAY_IP_ADDRESS_VAR}}New-NetRoute -DestinationPrefix <subnet> -NextHop <gateway> -InterfaceAlias <iface>New-NetRoute -DestinationPrefix {{SUBNET_VAR}} -NextHop {{GATEWAY_IP_ADDRESS_VAR}} -InterfaceAlias Ethernetnmap
Network discovery, port scanning and service identification.
Scan network for open port
Find devices on a network with a specific port open.
nmap -p <port> --open <subnet>nmap -p 22 --open {{SUBNET_VAR}}Discover active devices
Discover active devices on a network without scanning ports.
nmap -sn <subnet>nmap -sn {{SUBNET_VAR}}Detect service versions
Detect services and versions running on a host.
nmap -sV <host>nmap -sV {{CLIENT_IP_VAR}}Scan specific ports
Scan specific ports on a host.
nmap -p <ports> <host>nmap -p 22,80,443 {{CLIENT_IP_VAR}}Scan all TCP ports
Scan all TCP ports on a host.
nmap -p- <host>nmap -p- {{CLIENT_IP_VAR}}Identify operating system
Attempt to identify the operating system of a host.
nmap -O <host>nmap -O {{CLIENT_IP_VAR}}Comprehensive host scan
Perform OS detection, version detection, script scanning and traceroute.
nmap -A <host>nmap -A {{CLIENT_IP_VAR}}Scan for vulnerabilities
Check a host for known vulnerabilities using Nmap scripts.
nmap --script vuln <host>nmap --script vuln {{CLIENT_IP_VAR}}