Console9

How to Set Default Options with the .digrc File

Create and configure the .digrc file to apply default query options to every dig command automatically.

Configure default query options for Domain Information Groper (dig) by creating a .digrc file in the home directory.

Prerequisites

  • A Linux, macOS, or Windows (WSL) system with terminal access.
  • The dig command installed. On Debian/Ubuntu, install it with sudo apt install dnsutils. On RHEL/CentOS/Fedora, install it with sudo dnf install bind-utils.
  • Write permission to the home directory ( $HOME).

Step-by-Step: Configure Default dig Options with .digrc

  1. Create a .digrc file in the home directory. dig reads this file before processing command-line arguments and applies any query options it contains. Write the desired default options to the file using echo:
echo "+noall +answer" > ~/.digrc

dig applies +noall +answer to every subsequent query. The +noall option suppresses all output sections, and +answer re-enables the ANSWER section. This combination produces clean output showing DNS records without headers, comments, or statistics.

Modified digrc file using echo with noall and answer options

  1. Run dig to confirm the .digrc settings take effect. dig applies the options from .digrc automatically without requiring them on the command line:
dig example.com

dig displays the answer section only:

example.com.        86400   IN      A       93.184.216.34

Example of dig command after digrc has been modified with noall answer

  1. Add more default options to the .digrc file. dig supports any query option in this file. Append options to customize the default output further:
echo "+noall +answer +nocmd +nostats" > ~/.digrc

dig suppresses the command header, answer metadata, and statistics footer for every query.

  1. Override .digrc options on the command line when needed. dig processes command-line options after .digrc options, allowing temporary overrides. Request full output by passing +all:
dig example.com +all

dig displays the complete verbose output, overriding the +noall setting from .digrc for this single query.

  1. Remove the .digrc file to restore dig to its default behavior. Delete the file when the custom defaults are no longer needed:
rm ~/.digrc

dig reverts to displaying the full detailed output for all queries.

How to Verify the .digrc Configuration Is Active

Domain Information Groper (dig) confirms the .digrc file is active when the output format changes to match the options in the file. Run dig example.com and compare the output to the expected format. If +noall +answer is set in .digrc, dig shows the ANSWER section records without any headers or statistics. Running dig example.com +all should temporarily override the .digrc defaults and display the full output.

Common Issues When Using .digrc with dig

  • .digrc options not applied: Verify the file is located at ~/.digrc (the home directory). dig reads ${HOME}/.digrc on startup. Check the file path with ls -la ~/.digrc.
  • Options conflict between .digrc and command line: dig processes .digrc options first, then command-line options. Command-line options override conflicting .digrc settings. If +noall is in .digrc and +stats is on the command line, dig displays only the statistics section.
  • Unexpected output after creating .digrc: The .digrc file may contain extra whitespace or invalid options. Verify the file contents with cat ~/.digrc and ensure each option uses the +option format.
  • Batch scripts produce different output: Scripts that rely on specific dig output formatting may break if .digrc modifies the default output. Explicitly set all required options in the dig command within scripts to avoid dependency on .digrc.