
Managing network settings and configurations on macOS can be a straightforward process with the right commands. Here’s a detailed guide on essential network commands that can help troubleshoot, configure, and optimize your macOS network settings.
netstat – Show Network Status
The netstat command symbolically displays the contents of various network-related data structures. There are a number of output formats, depending on the options for the information presented. The first form of the command displays a list of active sockets for each protocol.
View information on all sockets
$ netstat -at
Network info for IPv6
$ netstat -lt
Per protocol network statistics
$ netstat -s
Statistics for a specific network protocol
$ netstat -p igmp
Statistics for network interfaces
$ netstat -i
ntop
View real-time network information
$ ntop
traceroute – Print the route packets take to a network host
The traceroute command utilizes the IP protocol time to live field and attempts to elicit an ICMP TIME_EXCEEDED response from each gateway along the path to a host. The only mandatory parameter is the destination host name or IP number. The default probe datagram length is 40 bytes but can be increased by specifying a packet size.
Trace the path packets take to a destination
$ traceroute google.com
Without resolving domain names
$ traceroute -n google.com
Run traceroute in debug mode
$ traceroute -d google.com
nc – Arbitrary TCP and UDP connections and listen
The nc (or netcat) utility can be used for almost anything involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary ports, perform port scanning, and handle both IPv4 and IPv6. Unlike telnet, nc scripts nicely and separates error messages onto standard error.
Establish a network connection
$ nc -v google.com 443
Connect over port 443 with a timeout of 15 seconds
$ nc -v -w 15 google.com 443
Force IPv4-only connection
$ nc -v -4 google.com 443
Setup a network listener on port 2195 for testing
$ nc -l 443
tcpdump – Dump traffic on a network
tcpdump prints out a description of the contents of packets on a network interface that match the Boolean expression. The description is preceded by a time stamp, printed by default as hours, minutes, seconds, and fractions of a second since midnight.
Capture some packets
$ tcpdump -nS
Capture all packets
$ tcpdump -nnvvXS
Capture packets for a specific port
$ tcpdump -nnvvXs 443
Capture packets for a given port destined for 192.168.1.160
$ tcpdump -nnvvXs 443 dst 192.168.1.1
Capture packets and save to a pcap file
$ tcpdump -nnvvXs 443 dst 192.168.1.1 -w /tmp/dump.pcap
Read and analyze captured packets
$ tcpdump -qns 0 -A -r /tmp/dump.pcap
networkQuality – Network quality testing tool
networkQuality measures different aspects of network quality, including:
- Maximal capacity (speed)
- Responsiveness (measured in roundtrips per minute (RPM) under working conditions)
Note: This tool connects to the Internet to perform its tests, using data from your Internet service plan.
Verbose output
$ networkquality -v
Test upload/download in sequential instead of parallel
$ networkquality -s
Using Private Relay
$ networkquality -v -p
nslookup – Query Internet name servers interactively
nslookup allows users to query Internet domain name servers. It has two modes:
- Interactive mode: Query name servers for information about hosts and domains or print lists of hosts.
- Non-interactive mode: Print just the name and requested information for a host or domain.
$ nslookup
nettop – Display updated information about the network
The nettop program displays a list of sockets or routes, providing real-time network statistics.
Display updated network information
$ nettop
Disable address to name resolution
$ nettop -n
Less intensive CPU usage (draws less often)
$ nettop -c
dns-sd – Multicast DNS (mDNS) & DNS Service Discovery (DNS-SD) Test Tool
The dns-sd command is a network diagnostic tool similar to ping or traceroute. Unlike those tools, most of its functionality is implemented in library code, making it available to any application.
Return a list of domains recommended for registering (advertising) services
$ dns-sd -E
Return a list of domains recommended for browsing services
$ dns-sd -F
Follow TexArxs more insights on macOS management, security, and more!