How to Fix curl: (6) Could not resolve host Error in Linux

As Linux users continue to skillfully nurture and grow their user experience, they soon realize that they become more performant and productive while in the Linux command-line environment.

The Linux OS environment exposes its users to terminal-based tools like Curl for a non-interactive download and upload of targeted network/internet-based files, which is similar to the Wget utility and both share some similarities in their implementation and functionalities.

The primary role of the Curl utility as highlighted on its manual page is to transfer a targeted URL.

$ man curl 

It supports numerous protocols with the common ones being FTP, FTPS, HTTP, HTTPS, SCP, SFTP, SMTP, and SMTP.

The Curl command syntax is as follows:

$ curl [options / URLs]

We can show its implementation by using it with a random URL.

$ curl https://google.com -o linuxshelltips.txt

In the above command, Curl’s findings from accessing the highlighted URL are saved in the succeeding text file.

Curl File Download
Curl File Download

curl: (6) could not resolve host Error

Mostly, such an error occurs when there is an issue with a Linux server’s DNS resolver. A Linux administrator will categorize/define this challenge as a server management service issue.

This error is likely to take several forms when the curl command is executed from the Linux terminal and the most popular ones include:

  • curl: (6) could not resolve host: domain_name.extension; Name or service not known
  • curl: (6) could not resolve host: domain_name.extension e.g. linuxshelltips.com
  • curl: (6) could not resolve host: application

Now that we have highlighted the primary reason that might be behind the stated curl command error during its execution on a Linux terminal, it’s time to fix the problem.

Solution 1: Missing Working DNS Nameserver

A nameserver is basically a bridge between a working/purchased domain name and the IP address of a server. When you purchase or subscribe to a domain name, and before you use/link this domain name to your remote Linux server, you need to configure a DNS nameserver. A DNS nameserver enables a user to use a domain name to access a remote server instead of using its IP address.

On your Linux server/machine, the file /etc/resolv.conf is responsible for the DNS nameserver entries auto-generated by NetworkManager.

$ sudo nano /etc/resolv.conf

This file can hold more than one DNS nameserver entry. As you might have noted, the syntax for adding a DNS nameserver entry in this file should resemble the following:

nameserver   IP.ADDRESS

For instance, if you were to add Google public nameservers to this file, it would look like the following:

nameserver   192.168.100.1
nameserver   8.8.8.8
nameserver   8.8.4.4
Add DNS Name Servers in Linux
Add DNS Name Servers in Linux

If you are using a private DNS nameserver, add it to the /etc/resolv.conf file. Update or reboot the system if possible and the host should start resolving.

Solution 2: Curl Syntax Errors

Make sure the curl command execution adheres to its correct syntax usage. A syntax error can arise from something as simple as the misuse of an escape sequence (/) or an illegal spacing on the URL.

The curl: (6) could not resolve host error in Linux primarily relates to wrongful/missing DNS nameserver setup or a random syntax error that can be scanned and fixed.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.