XiaTools

Mac Terminal Networking Commands: How to Check IP Hostnames

Updated 09 Oct 2026

Checking an IP hostname in macOS is essential for network troubleshooting, verifying DNS propagation, and auditing server connections. You can easily find hostnames using native command-line tools like host, nslookup, and dig right inside the Terminal application.

Whether you need to perform a forward lookup on a domain name or a reverse lookup to find the pointer record of an IP address, the built-in macOS networking utilities give you direct access to raw DNS data. For a quick web-based alternative without launching the console, you can use the Reverse DNS Lookup tool on XiaTools to instantly query PTR records and inspect IP ownership details.

Understanding IP Hostnames and DNS Records

Before diving into Terminal commands, it helps to understand what an IP hostname actually represents in the Domain Name System (DNS). Every device connected to a network has a numeric IP address (such as 192.0.2.1 or 2001:db8::1), but humans prefer easy-to-remember names like example.com.

DNS translates between these two formats using different types of resource records:

  • A Records: Map a hostname to an IPv4 address.
  • AAAA Records: Map a hostname to an IPv6 address.
  • PTR Records (Pointer Records): Used for reverse DNS, mapping an IP address back to a canonical hostname.

When you run a command to check an IP hostname, your Mac queries configured DNS resolvers (like your local router, 1.1.1.1, or 8.8.8.8) to retrieve these records.

Essential Mac Terminal Commands to Check IP Hostnames

macOS comes pre-installed with several powerful command-line utilities for querying DNS. Open your Terminal app (found in Applications > Utilities) and try the following commands.

1. Using the host Command

The host utility is a simple, streamlined tool for performing DNS lookups. It works well for both forward lookups (finding an IP from a hostname) and reverse lookups (finding a hostname from an IP).

To look up the IP address of a hostname, run:

host example.com

Sample output:

example.com has address 192.0.2.1
example.com has IPv6 address 2001:db8::1

To perform a reverse lookup and check the hostname of an IP address, pass the IP directly to the command:

host 192.0.2.1

Sample output:

1.2.0.192.in-addr.arpa domain name pointer ns1.example.com.

2. Using the nslookup Command

nslookup is a classic interactive and non-interactive tool used to query internet domain name servers. It is universally available across macOS, Linux, and Windows.

To check the hostname associated with a specific IP address:

nslookup 192.0.2.1

Sample output:

Server:		192.168.1.1
Address:	192.168.1.1#53

Non-authoritative answer:
1.2.0.192.in-addr.arpa	name = ns1.example.com.

If you want to query a specific DNS server rather than your default local resolver, append the server IP to your command:

nslookup example.com 8.8.8.8

3. Using the dig Command

dig (Domain Information Groper) is the gold standard for network engineers. It provides detailed, verbose output that shows you exactly how DNS queries are resolved, including TTL (Time to Live) values, flags, and response times.

To check standard DNS records for a domain:

dig example.com

To perform a reverse lookup for an IP address using dig, use the -x flag:

dig -x 192.0.2.1

Sample output:

; <<>> DiG 9.10.6 <<>> -x 192.0.2.1
;; global options: +cmd
;; Got answer:
;; -> `--> HEADER opcode: QUERY, status: NOERROR, status: ANSWER
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;1.2.0.192.in-addr.arpa.		IN	PTR

;; ANSWER SECTION:
1.2.0.192.in-addr.arpa.	3600	IN	PTR	ns1.example.com.

;; Query status: 
;; Query names:
;; ...

Comparing DNS Lookup Utilities on macOS

Tool Best Used For Pros Cons
host Quick lookups & scripts Clean, single-line human-readable output Limited advanced query control
nslookup General troubleshooting Interactive mode, widely recognized syntax Verbose output layout can be clunky
dig Deep diagnostics & audits Extremely detailed, highly flexible flags Steeper learning curve for beginners

Step-by-Step Guide: Flushing DNS Cache on macOS

If you have updated your DNS records or IP pointer records but your Terminal commands are still returning stale hostnames, your Mac is likely serving cached results. Follow these steps to clear your local DNS cache depending on your macOS version.

  1. Open the Terminal application.
  2. Type the appropriate flush command for your system. For modern macOS versions, run:
    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
    
  3. Enter your local Mac login password when prompted (note that characters will not appear on screen as you type).
  4. Press Enter. A successful execution will silently clear the resolver cache.
  5. Re-run your host or dig command to fetch fresh DNS records from the authoritative name servers.

Common Mistakes and How to Fix Them

  • Forgetting the Reverse IP Order in Manual PTR Queries: If you manually construct an in-addr.arpa query without using the -x flag in dig, you must reverse the IP octets. For example, 192.0.2.1 becomes 1.2.0.192.in-addr.arpa. Always use dig -x or the host command to let your system handle the inversion automatically.
  • Querying Local Cache Instead of Authoritative Servers: If your local ISP resolver has old records, your terminal commands might return outdated hostnames. Fix this by specifying a public recursive resolver in your command, such as @8.8.8.8 or @1.1.1.1.
  • Confusing Local Hostnames with Public PTR Records: Running hostname in your terminal returns the local identifier of your Mac on your private LAN, not your public internet IP hostname. Use dig or host with your public IP address to check external pointer records.

Network Troubleshooting Checklist

  • Verify your active internet connection and local gateway settings.
  • Confirm you are querying the correct IP address format (IPv4 vs IPv6).
  • Test resolution against both local routers and public DNS providers (8.8.8.8, 1.1.1.1).
  • Flush your local macOS DNS resolver cache if results appear inconsistent.
  • Check for firewall or VPN restrictions that might block standard DNS port 53 traffic.

Frequently asked questions

How do I find my own Mac's hostname in the Terminal?

You can find your local computer name by simply typing `hostname` or `scutil --get ComputerName` in the Terminal window. If you want to check your local network hostname, use `scutil --get LocalHostName`.

Why does my reverse DNS lookup return NXDOMAIN?

An NXDOMAIN (Non-Existent Domain) error means that no PTR record has been configured for that specific IP address in the reverse DNS tables. Many consumer and hosting IP addresses do not have PTR records assigned by default.

Can I check multiple IP hostnames at once in Terminal?

While native commands like `dig` and `host` accept only one argument at a time, you can loop through a list using a simple bash loop. For example, use `for ip in 192.0.2.1 192.0.2.2; do host $ip; done` to check multiple IPs sequentially.

How do I query IPv6 addresses for hostnames?

You can query IPv6 hostnames using the exact same tools by supplying an IPv6 address. For example, run `host 2001:db8::1` or `dig -x 2001:db8::1` to resolve IPv6 pointer records.

What is the difference between forward and reverse DNS lookups?

A forward DNS lookup translates a human-readable domain name (like example.com) into a numeric IP address. A reverse DNS lookup does the exact opposite, taking an IP address and querying the PTR record to find the associated hostname.

Free tools