
lwresd Command in Linux
Managing DNS (Domain Name System) queries in Linux is crucial for network operations. One of the tools that help in resolving DNS queries is lwresd. This command is part of the bind-utils package and is used as a lightweight resolver daemon. It enables the DNS client libraries to interact with a DNS resolver service.
Table of Contents
Here is a comprehensive guide to the options available with the lwresd command −
- What is lwresd Command?
- Syntax of lwresd Command
- lwresd Command Options
- Installation of lwresd Command
- How to Use the lwresd Command in Linux?
What is lwresd Command?
lwresd stands for "Lightweight Resolver Daemon". It is a small and efficient DNS resolver that can be used to query DNS records. It runs as a daemon and listens for DNS resolution requests from clients, which helps them resolve domain names to IP addresses.
Lwresd is a lighter version of the BIND (Berkeley Internet Name Domain) software. Unlike full DNS servers like named, it doesn't use as many resources. It's used in systems that only need basic DNS resolution without the extra load of running a full DNS server. It usually works with liblwres, a library that handles lightweight DNS resolutions.
Syntax of lwresd Command
To use the lwresd command in Linux, the following command is used −
lwresd [options]
The lwresd command can be executed with or without options. Generally, it is invoked with options that determine its behavior, such as specifying the port it listens on or configuring logging settings.
lwresd Command Options
Some commonly used options with lwresd command are listed below −
Options | Description |
---|---|
-d | This option is used to debug in the foreground. By default, lwresd runs as a background service (daemon), but using -d allows you to see debug output in the terminal instead. |
-p <port> | By default, lwresd command listens on port 53. However, we can use the -p option to specify the port number for the daemon to listen on. |
-t | Set the maximum time (in seconds) the daemon will wait before it cancels a request. |
-v | Turn on detailed output to log more information about operations and possible problems. |
-c <config_file> | It is used to specify a custom configuration file instead of the default one. |
Installation of lwresd Command
Since the lwresd command is part of the BIND tools, you need to install the bind-utils package to use it. You can execute the following command to install lwresd on Debian-based systems −
sudo apt install bind9-utils

To install it on CentOS/RHEL-based systems, you can use the yum package manager as follows −
sudo yum install bind-utils
Fedora users can use the dnf package manager to install lwresd command on Linux −
sudo dnf install bind-utils
How to Use the lwresd Command in Linux?
The lwresd daemon usually runs in the background, either started manually or by system tools like systemd. It handles DNS requests from clients that connect to it.
Starting lwresd
To start the lwresd service, you can either start it directly from the command line or configure it to start at boot using a service manager. For debugging purposes, you can start it in the foreground −
sudo lwresd -d
This command will print logs directly to the terminal. To start it as a background service, run the following command −
sudo lwresd
By default, this command starts lwresd in the background, listening on port 53 for incoming DNS resolution requests.
Configuring lwresd
You can configure the lwresd daemon through its configuration file. This file is usually located at "/etc/lwresd.conf". It enables you to set various parameters, including the address to bind to and logging settings. The following configuration ensures that lwresd listens only on the local loopback address (127.0.0.1) and accepts queries only from local clients −
# /etc/lwresd.conf listen-on { 127.0.0.1; }; allow-query { 127.0.0.1; };
Specifying a Different Port
If you want lwresd to listen on a port different from the default (53), you can use the -p option. For example, the following command uses port 5353 −
sudo lwresd -p 5353
Setting a Timeout
You can execute the lwresd command with the -t option to configure a timeout for DNS queries. For example, the following command sets a 10-second timeout −
sudo lwresd -t 10
This tells lwresd to wait for a maximum of 10 seconds before timing out a query.
Specifying a Custom Configuration File
You can use the -c option with the lwresd command to specify a custom configuration file −
sudo lwresd -c /path/to/custom/lwresd.conf
This command starts lwresd using the specified configuration file.
Conclusion
In this tutorial, we explored how to manage DNS queries using the lwresd command on Linux. This lightweight resolver daemon is part of the BIND tools and offers a simple, resource-efficient way to handle DNS resolution requests. We covered how to install lwresd on different Linux systems, explained its basic syntax with common options, and demonstrated practical usage with examples.
By using lwresd, you can configure DNS settings, manage ports, set timeouts, and work with custom configuration files to meet your system's needs.