dnslookup — A simple Ruby CLI tool for querying DNS records
dnslookup is a Ruby CLI for querying A, MX, CNAME, and TXT records from default or custom DNS servers. It wraps dig with a small command-line interface that is useful for quick troubleshooting, scripting, and day-to-day DNS checks.
Please use GitHub Issues to report bugs.
Requirements
- Ruby 3.0 or newer
- The
digexecutable available on yourPATH
If dig is not already installed, common package names are:
brew install bindsudo apt-get install dnsutilsInstallation
To add dnslookup to an existing project, add this line to your project's Gemfile:
gem 'dnslookup'And then execute:
bundle installOr to install the CLI locally:
gem install dnslookupUsage
Lookup DNS records for a domain:
dnslookup example.com -aIf you omit a record-type option, dnslookup queries A records by default:
dnslookup example.comBy default, dnslookup queries Google's public resolvers: 8.8.8.8 and 8.8.4.4. Use -s to query a specific resolver.
Options
| Option | Description |
|---|---|
-m, --mx
|
Return only MX records |
-a, --aname
|
Return only A records |
-c, --cname
|
Return only CNAME records |
-t, --txt
|
Return only TXT records |
-A, --all
|
Return A, MX, CNAME, and TXT records |
-s, --server=IP
|
Query a specific name server IP |
-h, --help
|
Show help message |
-v, --version
|
Show gem version |
Examples
Lookup the default A record:
dnslookup example.comLookup a CNAME record explicitly:
dnslookup ftp.victorkeenan.com -cQuery a specific name server:
dnslookup example.com -a -s1.1.1.1Query all supported record types at once:
dnslookup example.com --allIf dig cannot complete the lookup, dnslookup reports the query as failed instead of showing an empty result:
dnslookup example.com -a -s203.0.113.53Depending on the failure, the output will include either (query failed) or (query failed: ...).
Help with usage and options:
dnslookup -hContributing
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the terms specified in the CODE OF CONDUCT.
License
dnslookup is copyright © 2016-2026 Victor S. Keenan. It is free software and may be redistributed under the terms specified in the LICENSE file.
Coded With Love
Code crafted by me, Victor S. Keenan. Find me on Twitter @VictorSK or hire me to design, develop, and grow your product or service.