Trending March 2024 # How To Use The Dig Command In Linux # Suggested April 2024 # Top 3 Popular

You are reading the article How To Use The Dig Command In Linux updated in March 2024 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 How To Use The Dig Command In Linux

Dig is a simple yet powerful tool in Linux that looks up Domain Name System (DNS) information about a specific remote server. Unlike tcpdump, it allows you to gain an insight on how a machine interacts with name servers. This tutorial will teach you the the basics of how to use the dig utility in Ubuntu and how to use the dig utility to understand how DNS works.

What Is DNS and How Does dig Work?

At its core, DNS is a system that allows a machine to seamlessly translate a human-readable domain name to its appropriate IP address. In that regard, DNS is similar to a phone directory where it lists a machine’s address along with an easy-to-remember label.

The Domain Name System works by storing domain records on a set of hierarchical name servers, which announce these records whenever a user attempts to resolve a domain name.

The dig utility unmasks this process by showing you how your computer communicates with name servers. It labels and prints every step that it takes from the initial connection to name resolution. This makes dig helpful in understanding any potential DNS issues with your server.

Installing dnsutils on Linux

The dig command is preinstalled in most Linux distributions. If it is not found in your system, you need to install the dnsutils package to access the dig command.

On Ubuntu and Debian systems, install it with the command:





On Fedora:


yum install


On Arch Linux and its derivatives:




bind-tools Querying DNS Servers With dig in Linux

One of the most basic actions you can do with dig in Linux is to query the A record for a Web address. The A record contains the primary IPv4 address for a domain name and is what your web browser queries whenever it tries to access a website.

To query the A record using dig, run the following command:


chúng tôi will print a long string of text that will show the actions that dig took to resolve the domain. For the most part, you can divide this string into four sections: the header, question, answer and nameserver.

The header section shows a brief summary of the command that you ran. The “opcode” value shows the action that dig did. Meanwhile, the “status” value prints overall result of the query.

The question section shows a list of queries that you made through dig. The first column prints the complete domain name followed by the query class and DNS record type.

The answer section shows the result of your query. The first column contains the complete domain name followed by its “Time To Live” value. The third and fourth columns show the query class and DNS record type, while the fifth column prints the result.

The nameserver section contains details about the DNS server that dig used for this command. The “QUERY TIME” is the amount of time that it took for the server to process the query. The “SERVER” value is the IP address of the name server, and the “MSG SIZE” shows the size of the query in bytes.

If you just want to quickly find the IP address of a website, include the +short option for it to only return the IP addresses.


+short chúng tôi a Custom DNS Record Type

Aside from doing A queries, it is also possible to use dig for looking up other DNS types. You can run the following command to check whether the domain has any IPv6 record:


chúng tôi aaaa

Querying a custom DNS type is also helpful if you are doing reconnaissance work during a penetration test. For example, you can use dig to check whether a domain name is also being used in a mail server:


chúng tôi mx

Lastly, dig can also be incredibly useful in learning more about the upstream services for a domain. Both the “CNAME” and the “NS” records will show more details about the server and the nameserver it is using:


chúng tôi cname


chúng tôi ns

Tip: learn how to enable DNS over HTTPS in various browsers.

Custom Dig Queries in Linux

By default, dig works by connecting to a name server and asking it for a domain name’s details. However, the program also provides a number of additional features that can help in resolving DNS issues.

One of the most useful features of dig is +trace. Similar to traceroute, it looks at all the hops that your machine makes whenever it connects to a domain.


chúng tôi +trace

You can also customize the name servers that dig uses to poll a specific domain name. This is useful if you have a name server and want to check if it is working correctly.

To force a custom name server, run the following command:


chúng tôi A


Lastly, dig is also a highly flexible program that can work in a Bash script. To do this, force dig to only print the result of your query:

Batch Processing dig Queries

Aside from processing individual domain names, it is also possible to use dig to resolve multiple web addresses. This is especially helpful if you are a network engineer and want to check on multiple domains at once.


+qr chúng tôi ns chúng tôi a

You can also use the -f option to tell dig to get its instructions from an external file. However, you should only write this file in a “dig query” format. Knowing that, consider the following lines of text:

Frequently Asked Questions Is it possible to use dig on a local network?

Yes. In most cases, these queries will only be resolved in your local DNS server. This can be helpful if you have an internal DNS server and want to see if it is being recognized in the network.

Is it possible to hack websites and Linux servers using dig?

While dig is a highly useful tool, it is only a small part of a penetration tester’s toolkit. Its primary role is in helping you understand how a machine and its domain name interact with DNS servers. If you are concerned about server breaches, check out securing a Linux server.

My ISP does not support IPv6. Can I run dig purely in IPv4?

It is possible to run dig in either IPv4-only or IPv6-only modes. To do this, you need to add either -4 or -6 options to your dig command. For example, running dig -4 +qr chúng tôi mx will force dig to only use IPv4 in its queries.

What's the difference between dig and nslookup?

Both dig and nslookup are command-line tools that will query DNS servers. The main difference between them is that dig is a much more powerful tool with many more options. Nslookup is simpler to use but does not have as many features. However, for most basic DNS queries, either tool will work just fine.

Image credit: Unsplash. All alterations and screenshots by Ramces Red.

Ramces Red

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.

By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time.

You're reading How To Use The Dig Command In Linux

Looking Up: Mastering The Nslookup Command In Linux With Examples

Introduction to Nslookup

The nslookup command is a powerful network administration tool used in Linux for querying Domain Name System (DNS) records efficiently. Whether you are a novice or a professional, this command can help you troubleshoot and test DNS by mapping domain names to IP addresses, as well as providing valuable information on various resource records such as MX and NS.

Key Takeaways

The nslookup command is a powerful network administration tool in Linux used to query DNS records efficiently.

Basic usage includes looking up domain names and IP addresses, as well as retrieving MX records and DNS servers.

Advanced users can customize queries by changing the query type and class or specifying the server to query for troubleshooting network and DNS issues.

By using nslookup, IT professionals gain valuable insights into how domains are mapped to IP addresses, ensuring smooth operation of their network infrastructure.

Basic Usage of Nslookup Command with Examples

The basic usage of the nslookup command includes looking up domain names and IP addresses, as well as retrieving MX records and DNS servers.

Looking Up Domain Name and IP Address

Using the nslookup command in Linux is an efficient way to look up domain names and IP addresses, catering to both novice users and experienced professionals. Here are some examples and steps for using the command −

For reverse DNS lookup (finding the domain name corresponding to an IP address), enter “nslookup ip_address” in the terminal, replacing “ip_address” with the actual IP address you’re interested in. The result will show you the associated domain name.

In case of multiple A records for a single domain (for load balancing purposes, for instance), entering “nslookup chúng tôi will list all available IP addresses for that particular domain.

By following these simple guidelines, both novice users and experienced professionals can effectively utilize the nslookup command for looking up domains and IP addresses within their Linux environment.

Retrieving MX Records and DNS Servers

The nslookup command is a powerful tool for network administration in Linux that can help retrieve MX records and DNS servers. This information can be useful when troubleshooting DNS issues or performing other related tasks. Here are some examples of how to use the nslookup command for this purpose:

This will return a list of all MX records associated with the domain.

This will return a list of all name servers associated with the domain.

You can also retrieve the Start of Authority (SOA) record for a domain using the following command:

This will show information about the primary name server and other important details about the domain.

In addition to these specific queries, you can also use the nslookup command interactively to query Internet name servers for information. This allows you to explore DNS records in more detail and troubleshoot any issues that may arise.

Overall, the nslookup command is an essential tool for networking professionals and novices alike. By using it to retrieve MX records and DNS servers, you can gain valuable insights into how domains are mapped to IP addresses and ensure smooth operation of your network infrastructure.

Advanced Usage of Nslookup Command with Examples

Advanced users can customize their nslookup queries by changing the query type and class or specifying the server to query, making it a versatile tool for troubleshooting network and DNS issues.

Changing Query Type and Class

nslookup command allows Linux users to change the query type and class as needed. This can be a useful tool when troubleshooting DNS issues and trying to retrieve specific information from domain name servers. Here are some examples of how to change the query type and class using nslookup command −

Changing the query class − DNS queries are typically performed in the IN (Internet) class by default. However, it is possible to specify a different class using nslookup command such as CH (Chaosnet) or HS (Hesiod). To specify a different class, use the -class option followed by the desired class name when querying.

Overall, changing query type and class with nslookup command can help network administrators troubleshoot and retrieve specific information about DNS servers more effectively in Linux environments.

Specifying the Server to Query

The nslookup command in Linux can be used to query DNS servers for information about a specific domain or IP address. One of the key features of this tool is its ability to specify the server you want to query. Here are some important points to keep in mind:

To specify the server, use the following syntax: `nslookup `

For example, if you wanted to query the DNS server at IP address for information about chúng tôi you would type: `nslookup chúng tôi`

You can also specify multiple servers by separating their IP addresses with spaces.

If you do not specify a server, nslookup will use the default DNS server configured on your system.

Specifying a server can be useful for troubleshooting DNS issues, as it allows you to check if a particular server is responding properly.

Keep in mind that not all DNS servers will give you the same results for a given query, so it may be worthwhile to try multiple servers if you’re having trouble getting the answers you need.

By learning how to specify which DNS server to query when using nslookup, network administrators and other IT professionals can more effectively troubleshoot DNS issues and ensure their systems are running smoothly.


To sum up, nslookup command is a vital network administration tool for querying DNS records in Linux. It helps to retrieve information about IP addresses and domain names by querying name servers.

Although being an old-school networking tool, there are still many practical uses of nslookup command for DNS lookup that make it relevant even today.

6 Useful Linux Command Line Tools For System Administrators

The command line is seriously powerful. With it users can execute powerful actions on computers and even servers in quick succession without the need to fuss with heavy GUI tools, and even invoke automated scripts that can do massive amounts of actions at once. This is especially useful when it comes to doing serious system administration.

With a terminal-based tool, users can gain access to massive amounts of information remotely and with ease. What are some of the best command-line based tools on Linux? Let’s find out!


When programs operate, they often have access to certain files on the system. These files could be images, video files, or even just library files being accessed. This tool is useful because it allows the user to view a list of any and all open files, along with processes from the programs accessing them.

Since Lsof is so well known, users don’t need to go out and install it. Chances are it’s already installed on the system. To test it out just run the lsof command.


Nmap (Network mapper) is a command line tool that allows the user to create a map of a network. Despite being just a command line tool, Network mapper has many, many options. It can discover network hosts, operating systems, and scan ports, check firewall security, and even find network exploits that may be present.

Like many of the tools on this list, Nmap is found in most Linux distributions’ software repositories. To install it, search for nmap and install it.


Tcpstat is a terminal program that can read and report back network interface information to the user. The program can do this by directly monitoring one specific device in real time or by reading data from a dump file. A simple, but useful utility especially for system administrators looking to find out the performance of specific network cards.

To install Tcpstat, check your Linux distributions’ package repository. Alternatively, download a package of it at chúng tôi or get the source code directly from the developer.


Htop is an improvement on a terminal-based tool known as “Top.” It offers improvements on top such as better visual readouts (menus and user interfaces), more user-friendly and interactive than Top, etc. This program allows users to view running programs, processes, memory usage, and pretty much everything you’d see in a normal task management GUI tool on the Linux desktop.

This tool is especially helpful for system administrators who look for easy ways to kill, restart or suspend unresponsive programs over a remote connection. It also comes in handy when checking in on the overall CPU and Memory performance. The program is available in most Linux distributions’ package repositories. Open up a terminal window and search for “htop” to install it.


For those looking for a way to look over network packets there is Tcpdump. It’s a simple package analyzing tool that can show TCP/IP network traffic as it happens. Using Tcpdump allows users to view detailed information about the contents of packets both coming (and leaving) through the network in real time and dump it into files for further viewing later.

This sort of tool is a favorite for forensic and security professionals, as it allows the ability to “spy” on Internet traffic from any computer it can connect with. To install Tcpdump, open up a terminal and search and use the package manager to install Tcpdump. It’s most likely in the default repositories.


System administrators on Linux might find themselves in a command line for most of their work from managing servers or even client computers and other things. That’s why it’s very important to find out the best command line-based tools to make the job easier. Each tool featured on this list does exactly that: makes system administration easier on Linux, each in its own way.

Derrik Diener

Derrik Diener is a freelance technology blogger.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.

By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time.

How To Setup Firewall In Linux?

Firewalls are an integral component of every contemporary computer system, safeguarding the network and protecting the system from illegal access. We’ll take a deep dive into the realm of Linux firewalls and learn how to configure one in this post.

Before we involve into the technical details of establishing a firewall in Linux, let us clarify what a firewall is and why it is so important!

A firewall is a network security device that monitors and restricts network traffic based on predefined security rules. A firewall’s principal function is to block unauthorised access to a computer system or network while still allowing authorised access. It functions as a gatekeeper, controlling who and what may enter and depart a network.

There are two major choices for configuring a firewall in Linux: iptables and firewalld.

‘iptables’ is a command-line programme for managing the Linux kernel firewall. For many years, it was the default firewall for Linux servers and is still extensively used today.

‘firewalld’ is a more modern approach to managing firewalls in Linux. It is a dynamic daemon that provides a D-Bus interface for managing firewall rules, and it is used by many Linux distributions as the default firewall.

Now let’s dive into the steps required to set up a firewall in Linux using both iptables and firewalld.

Using ‘iptables’ to Create a Firewall

To begin setting an iptables firewall, first ensure that it is already installed on your system. Although iptables is present in most Linux distributions, it is always a good idea to double-check.

Open a terminal and type the following command to see if iptables is installed on your system: sudo iptables -L

If iptables is not already installed on your machine, use the following command to install it: sudo apt-get install iptables

You may begin setting the firewall once you have validated that iptables is installed on your system.

The initial step in iptables configuration is to establish the default policies for incoming and outgoing traffic. The default policy determines what happens to packets that do not match any of the rules in the firewall.

To set the default policies to drop all incoming and outgoing traffic, run the following commands −

sudo iptables -P INPUT DROP sudo iptables -P OUTPUT DROP

Once you have set the default policies, you can start adding rules to allow or block specific types of traffic. The basic syntax for adding a rule to iptables is as follows −

sudo iptables -A [CHAIN] -p [PROTOCOL] --dport [PORT] -j [ACTION]

Let’s break down the components of the rule −

CHAIN − This specifies the chain in the firewall where the rule will be added. The three default chains in iptables are INPUT, OUTPUT, and FORWARD.

PROTOCOL − This specifies the protocol for the traffic. Common protocols include TCP, UDP, and ICMP.

PORT − This specifies the port number for the traffic.

ACTION − This specifies what should happen to traffic that matches the rule. Common actions include ACCEPT, DROP, and REJECT.

The following command, for example, would accept incoming SSH traffic (port 22) on the INPUT chain −

sudo iptables -A INPUT -p tcp —dport 22 -j ACCEPT

Similarly, the following command would enable OUTPUT chain HTTP traffic (port 80) −

sudo iptables -A OUTPUT -p tcp —dport 80 -j ACCEPT Using ‘firewalld’ to Create a Firewall

Another option for setting up a firewall in Linux is by using firewalld. Firewalld is a modern dynamic daemon that is used by several Linux distributions, such as CentOS, Fedora, and Red Hat Enterprise Linux, as the default firewall management tool.

The first step in configuring a firewall with firewalld is to see if it is already installed on your system.

Most recent Linux distributions come with firewalld pre-installed, however you may validate its presence in the terminal by typing the following command −

sudo firewall-cmd —state

If firewalld is not already installed on your machine, use the following command to install it: sudo yum install firewalld

Once you confirmed that firewalld is installed on your system, you start configuring the firewall.

The first step in configuring firewalld is to check the default zone. The default zone is a predefined set of rules that govern the traffic allowed on the system. To check the default zone, run the following command −

sudo firewall-cmd --get-default-zone

By default, the default zone is set to “public”. You can change the default zone by running the following command −

sudo firewall-cmd --set-default-zone=zone

where “zone” is the name of the zone you want to set as default.

To allow incoming HTTP traffic, for example, you can use the following command −

The “–permanent” option makes the rule permanent, so it survives a reboot. If you do not use the “–permanent” option, the rule will be removed when the system is rebooted.

You can also allow specific ports by using the “–add-port” option. For example, the following command allows incoming traffic on port 22 for SSH −

sudo firewall-cmd --add-port=22/tcp --permanent

After adding the necessary rules, make sure to reload the firewall for the changes to take effect −

sudo firewall-cmd --reload

How To Switch The Control And Command Keys In Mac Os X

If you have just switched to using Mac OS X from the regular Windows OS that you have been using all your life, you might have difficulty adjusting to the keyboard, particularly the Control and Command keys.

In Windows most of the keyboard shortcuts are done with the Control key. You press “Ctrl + A” to select all, “Ctrl + C” to copy and “Ctrl + V” to paste. When it comes to Mac OS X, the configuration is totally opposite. Even though the keyboard comes with a Control button, the “Command” button is used for most keyboard shortcuts. You have to press “Cmd + A” to select all, “Cmd + C” to copy and “Cmd + V” to paste.

If you are not used to the keyboard configuration, Mac OS X comes with a setting that allows you to remap the modifier key. This way you can switch the functionality of “Control” and “Command” and make it work like Windows.

1. In Mac OS X open “System Preferences” from the Launchpad.

If you are planning to switch to Mac OS X permanently, it might be better for you to continue using Command as the modifier key and get used to it. It will only take a while for you to become accustomed to the new system. If, however, you are often switching between different OS, like Windows on an office PC and Mac OS X on a home laptop, then switching the Control and Command buttons might just save your sanity.

Image credit: a swedish campground


Damien Oh started writing tech articles since 2007 and has over 10 years of experience in the tech industry. He is proficient in Windows, Linux, Mac, Android and iOS, and worked as a part time WordPress Developer. He is currently the owner and Editor-in-Chief of Make Tech Easier.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.

By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time.

How To Rename A File In Linux

When you start learning something new, even the simplest tasks feel confusing, and that can be frustrating for anyone. Say renaming a file is one of the most basic tasks for file management, but newbies might face difficulty in renaming a file or batch renaming files in Linux. To help you with it, we have explained four easy ways to rename a file or even multiple files in Linux using the command line interface (CLI) as well as the GUI.

Renaming Files in Linux (2023)

First, we will explain how to use the mv and rename commands to rename files using the Command Line (or Terminal) in Linux. And then, we will learn how to rename or batch rename files using GUI tools, including GPRename and the native file manager in your Linux distro.

Rename Files Using the Command Line

Even though using the command line for the simplest of tasks might sound intimidating at first, it boasts a lot of features and is the fastest way to rename files in Linux. Here, we are using the mv and rename commands, and both of them will work in any Linux distribution.

Rename Files Using mv Command

The mv command stands for “move” with its primary purpose being to move both files and directories in the Linux file system. But we can also use the mv command to rename files. The syntax for the mv command is:

Note: If you use any of the -i, -f, -n flags more than once, only the final one takes effect.

Rename Single File Using the mv Command

To rename a single file using the mv command, use the below-given syntax:

The command results in the output below as confirmation, and you can verify the changes made using the ls command.

In the above example, we are renaming the file “mini-course-10.pdf” to “test-1.pdf” using the mv command. Here, the syntax looks like this:

mv -v chúng tôi test-1.pdf

After that, you can verify the change from the output of the mv command (highlighted in the image above), or you can further verify the output using the ls command. You will see the renamed file in the list of files in that directory.

Rename Multiple Files using the mv Command

The mv command can also be used to rename multiple files in a directory with some modifications. Here we will use some new commands along with the mv command. The command can prove to be difficult to understand with just raw syntax, so we have used it as an example below.

for i in *.pdf;do mv -v "$i" "${i/${i:0:4}/example}" done Rename Files Using rename Command

The rename command solves the complexity of the mv command with easy-to-use syntax for both single and multiple file renaming. The rename command generally comes pre-installed on most distros. If not, you can easily install it using a simple command:

For Debian-based systems –

sudo apt install rename

For Fedora-based systems –

sudo yum install prename

For Arch-based systems –

sudo pacman -S install rename

Since the rename command uses Perl in the backend, there are three types of regular expressions – match, substitute, and translate in Perl. The rename command uses the “substitute” and “translate” regular expressions. In the syntax above, the “s” is used to specify that you will use the substitute expression.

For RedHat, Fedora-based systems, you need to use the following command syntax:

OptionsDescription-vShows information about the current operation-nstands for “no action” and is used for testing to see how the files are going to get affected after the operation-fused to force overwrite the file name

Rename a Single File

The rename command works much like the mv command when renaming a single file. To rename a single file, use the following syntax:

Rename Multiple Files Rename Files Partially

Suppose you have used spaces in all your file names, and now, you want to replace the spaces with underscores. You can use the rename command and convert spaces to underscores using the syntax shown below:

For the above situation to replace spaces with underscores, use the given command:

Here, the is used to treat the underscore as a character and not a part of the command syntax.

Change The Case of The Filenames

With the rename command, you can even replace the lowercase characters with their respective uppercase characters and vice versa. To replace the lowercase characters with uppercase ones, use the following syntax:

And to replace uppercase characters with lowercase ones, use this syntax:

Rename Files using the GUI in Linux

The GUI method is probably a boon for those users who find the command line daunting. For the GUI method, we are using the Nautilus File manager and GPrename in Ubuntu 20.04 LTS, but rest assured that these methods will work on any distribution – albeit with slight modifications in some.

Rename Files Using File Manager

This is one of the easiest methods to rename files in Linux. Every Linux desktop distribution comes pre-installed with a file manager such as Nautilus, Dolphin, Thunar, etc. We have explained how you can use these file managers to rename files, so keep reading.

Rename A Single File Rename Multiple Files Using File Manager

2. In this context menu, select the “Rename” option. Or, you can press the F2 button on the keyboard to access the rename option.

3. This will open a new rename window, as shown below. Here, you get two options to rename the files, so let’s learn how to use both of them one by one.

Rename Using a Template:

3. Then, choose the order of naming the files from the “Automatic Number Order” drop-down menu. You can choose between Ascending, Descending, and more.

Find and replace text:

1. Enter the current common name in the “Existing Text” field. In the bottom pane, you will see the common name get highlighted.

2. In the “Replace With” text box, enter the new common name you want to replace the current name with.

Using GPRename to Rename Files

GPRename is a lightweight batch renaming tool that comes with several different options that can prove useful while renaming files using the Linux GUI. This tool can be helpful for users who find it difficult to batch rename files using their native file manager. Sadly, it doesn’t come pre-installed, but can easily be installed using the following commands:

For Debian-based systems –

For Fedora-bassed systems –

sudo dnf install gprename

For Arch-based systems –

sudo pacman -S gprename

Rename A Single File with GPRename

1. Open GPRename from the Applications menu or type gprename in the Linux Terminal.

2. Use the file system tree on the left to navigate to the desired folder. Then, select the file you want to rename in the right pane.

Rename Multiple Files with GPRename

1. As explained above, use the file system tree on the left to navigate to the desired folder. Then, select the files you want to rename and choose the appropriate option from the bottom pane.

Frequently Asked Questions

What does rm command do in Linux?

Easily Rename Files in Linux

Update the detailed information about How To Use The Dig Command In Linux on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!