Post

Commands I Use on My Mac

A collection of macOS command-line commands for DNS lookups, network testing, certificates, serial consoles, packet captures, IP information, and speed tests.

Commands I Use on My Mac

This post contains command-line tools I frequently use on macOS for troubleshooting DNS, network connectivity, certificates, serial connections, packet captures, public IP information, and internet speed.

DNS Lookups with dig

Perform a basic DNS lookup for a host or domain:

1
dig <host.domain>

Query a specific DNS record type:

1
2
3
dig <domain> TXT
dig <domain> MX
dig <domain> NS

Query a Specific DNS Server

To query a domain using a specific DNS server, specify the server with the @ symbol:

1
dig @9.9.9.9 <host.domain>

The example above uses Quad9’s public DNS resolver.

Check Open Ports

Use curl to test whether a TCP service is reachable:

1
curl -v mail.test.com:22

You can also use nc (netcat) to test a specific host and port:

1
nc -vz 192.168.13.4 25

The options used above mean:

  • -v: Enable verbose output.
  • -z: Scan for listening services without sending data.

Test an SSL/TLS Certificate

Use OpenSSL to connect to a service and display the certificates presented by the server:

1
openssl s_client -connect <serverFQDN>:443 -showcerts

For example:

1
openssl s_client -connect example.com:443 -showcerts

This is useful when troubleshooting certificate chains, TLS connectivity, and certificate expiration.

Access a Serial Console

List USB-related device files:

1
ls /dev/*usb*

After identifying the correct serial device, connect to it with screen:

1
screen /dev/<DEVICE_NAME> 9600

Replace <DEVICE_NAME> with the name of the serial device and adjust 9600 if the device uses a different baud rate.

To end a screen session, press:

1
Ctrl-A, then Ctrl-\

Confirm the session termination when prompted.

Capture ICMP Traffic with tcpdump

Capture ICMP traffic on the default network interface:

1
sudo tcpdump -n icmp

The options used above mean:

  • sudo: Run the command with elevated privileges.
  • -n: Do not resolve IP addresses to hostnames.
  • icmp: Capture only ICMP traffic.

To stop the capture, press Ctrl-C.

Find My Public IP Address

Display your public IP address:

1
curl http://ifconfig.co

Display the country associated with your public IP address:

1
curl http://ifconfig.co/country

You can also use HTTPS:

1
2
curl [https://ifconfig.co](https://ifconfig.co)
curl [https://ifconfig.co/country](https://ifconfig.co/country)

Test Internet Speed

The following commands download and execute Python-based speed-test scripts:

1
curl -s [https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py](https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py) | python -

An alternative script is:

1
curl -s [https://raw.githubusercontent.com/khodaeifard/speedtest/master/speedtest.py](https://raw.githubusercontent.com/khodaeifard/speedtest/master/speedtest.py) | python -

Security note: Piping a script directly from the internet to an interpreter executes content without giving you an opportunity to review it first. For production or security-sensitive systems, download and inspect the script before running it.

A safer workflow is to download the script first:

1
curl -o speedtest.py [https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py](https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py)

Review the file and run it with Python:

1
python3 speedtest.py
This post is licensed under CC BY 4.0 by the author.