Curl ошибка could not resolve host

when I try to load a web page to terminal it gives curl: (6) Could not resolve host error.

I have internet in my PC and trying from my home internet connection. So as I there is no any proxy involve here.

[root@localhost kevin]# curl http://google.com
curl: (6) Could not resolve host: google.com; Name or service not known

clean all and tried again but no lucky.

But if I use IP instead of the domain name, it works fine.

[root@localhost kevin]# curl http://173.194.46.0

any clue please?

Sathish's user avatar

Sathish

3,7301 gold badge16 silver badges28 bronze badges

asked Jul 26, 2014 at 5:26

Nayana Adassuriya's user avatar

Nayana AdassuriyaNayana Adassuriya

23.4k30 gold badges104 silver badges146 bronze badges

5

Issues were:

  1. IPV6 enabled
  2. Wrong DNS server

Here is how I fixed it:

IPV6 Disabling

  • Open Terminal
  • Type su and enter to log in as the super user
  • Enter the root password
  • Type cd /etc/modprobe.d/ to change directory to /etc/modprobe.d/
  • Type vi disableipv6.conf to create a new file there
  • Press Esc + i to insert data to file
  • Type install ipv6 /bin/true on the file to avoid loading IPV6 related modules
  • Type Esc + : and then wq for save and exit
  • Type reboot to restart fedora
  • After reboot open terminal and type lsmod | grep ipv6
  • If no result, it means you properly disabled IPV6

Add Google DNS server

  • Open Terminal
  • Type su and enter to log in as the super user
  • Enter the root password
  • Type cat /etc/resolv.conf to check what DNS server your Fedora using. Mostly this will be your Modem IP address.
  • Now we have to Find a powerful DNS server. Luckily there is a open DNS server maintain by Google.
  • Go to this page and find out what are the «Google Public DNS IP addresses»
  • Today those are 8.8.8.8 and 8.8.4.4. But in future those may change.
  • Type vi /etc/resolv.conf to edit the resolv.conf file
  • Press Esc + i for insert data to file
  • Comment all the things in the file by inserting # at the begin of the each line. Do not delete anything because can be useful in future.
  • Type below two lines in the file

    nameserver 8.8.8.8
    nameserver 8.8.4.4

    -Type Esc + : and then wq for save and exit

  • Now you are done and everything works fine (Not necessary to restart).
  • But every time when you restart the computer your /etc/resolv.conf will be replaced by default. So I’ll let you find a way to avoid that.

Here is my blog post about this:
http://codeketchup.blogspot.sg/2014/07/how-to-fix-curl-6-could-not-resolve.html

Jahan Zinedine's user avatar

answered Jul 28, 2014 at 1:29

Nayana Adassuriya's user avatar

Nayana AdassuriyaNayana Adassuriya

23.4k30 gold badges104 silver badges146 bronze badges

4

Perhaps you have some very weird and restrictive SELinux rules in place?

If not, try strace -o /tmp/wtf -fF curl -v google.com and try to spot from /tmp/wtf output file what’s going on.

answered Jul 26, 2014 at 11:12

Sathish's user avatar

5

I have today similar problem. But weirder.

  • host — works host pl.archive.ubuntu.com
  • dig — works on default and on all other DNS’s dig pl.archive.ubuntu.com, dig @127.0.1.1 pl.archive.ubuntu.com
  • curl — doesn’t work! but for some addresses it does. WEIRD! Same in Ruby, APT and many more.
$ curl -v http://google.com/
*   Trying 172.217.18.78...
* Connected to google.com (172.217.18.78) port 80 (#0)
> GET / HTTP/1.1
> Host: google.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 302 Found
< Cache-Control: private
< Content-Type: text/html; charset=UTF-8
< Referrer-Policy: no-referrer
< Location: http://www.google.pl/?gfe_rd=cr&ei=pt9UWfqXL4uBX_W5n8gB
< Content-Length: 256
< Date: Thu, 29 Jun 2017 11:08:22 GMT
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.pl/?gfe_rd=cr&ei=pt9UWfqXL4uBX_W5n8gB">here</A>.
</BODY></HTML>
* Connection #0 to host google.com left intact

$ curl -v http://pl.archive.ubuntu.com/
* Could not resolve host: pl.archive.ubuntu.com
* Closing connection 0
curl: (6) Could not resolve host: pl.archive.ubuntu.com

Revelation

Eventually I used strace on curl and found that it was connection to nscd deamon.

connect(4, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = 0

Solution

I’ve restarted the nscd service (Name Service Cache Daemon) and it helped to solve this issue!

systemctl restart nscd.service

answered Jun 29, 2017 at 11:29

Chris Suszyński's user avatar

3

There is no need to disable IPv6 as the answer suggests. The reason curl fails is simply because the DNS resolution is missing.

There is one liner solution to this.

If you care about what is inside /etc/resolv.conf then append it:

echo 'nameserver 1.1.1.1' | sudo tee -a /etc/resolv.conf >/dev/null

I usually don’t care and just replace the content of the file:

echo 'nameserver 1.1.1.1' | sudo tee /etc/resolv.conf >/dev/null

answered Oct 11, 2021 at 17:33

Houman's user avatar

HoumanHouman

63.8k87 gold badges274 silver badges458 bronze badges

1

Try nslookup google.com to determine if there’s a DNS issue.
192.168.1.254 is your local network address and it looks like your system is using it as a DNS server. Is this your gateway/modem router as well?
What happens when you try ping google.com. Can you browse to it on a Internet web browser?

answered Jul 26, 2014 at 13:25

Benjamin B's user avatar

2

In Our case, the command was passed through mail/skype and the person who needs to execute copied an extra space.

we found that extra space after an hour and removing that made it work.

answered Aug 6, 2022 at 3:20

nikhil2000's user avatar

nikhil2000nikhil2000

1583 silver badges14 bronze badges

I had an issue with IPV6 that suddenly showed up in wordpress admin where curl failed to connect to wordpress.org etc giving

An unexpected error occurred. Something may be wrong with WordPress.org

and also

Installation failed: Download failed. cURL error 28: Resolving timed out after 10005 milliseconds

I eventually sorted by adding the following as a php file in mu-plugins:

add_action( 'http_api_curl', function( $curl_handle ) { curl_setopt( $curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );});

and also when using curl directly in php by using the following option in the options array:

curl_setopt_array($curl, array(CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4));

The OS is IBM i (OS400/i5OS) v7.2 running on Power 6 and the php version is 8.1.10. Interestingly IPV6 is not active on the box.

answered Sep 17, 2022 at 11:37

jez001's user avatar

My case on MacOS was simple: I closed the iTerm window I was using and opened a new one.

It seems likely that this is an issue with CURL cacheing DNS responses given that I was messing around with my DNS when I ran into the same error as the OP.

answered Apr 8 at 20:49

AJB's user avatar

AJBAJB

7,37114 gold badges57 silver badges88 bronze badges

In my case, the problem was in the Static Route Table. Must be removed if a static route was previously added

answered May 11 at 20:35

ilgnv88's user avatar

1

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.

Are you curious to know why does the error ‘curl (6) could not resolve host ubuntu’ appear?

Usually, such curl errors happen when there are problems with DNS resolvers on the server.

At Bobcares, we often get requests from our customers to fix curl (6) could not resolve host Ubuntu as part of our Server Management Services.

Today, let’s discuss why this error occurs and see how our Support Engineers fix it.

What is curl (6) could not resolve host?

Many of our customers have experienced this error ‘curl (6) could not resolve host’ while trying to connect to a webpage from the terminal.

This error mainly occurs due to a wrong DNS set up or bad settings on the server.

Also, we’ve seen this error appearing in different ways which include.

  1. curl: (6) Could not resolve host: application
  2. curl: (6) Could not resolve host: domain.com
  3. curl: (6) Could not resolve host: google.com; Name or service not known

This essentially means the server was not able to connect to the remote host.

How we fixed the error curl (6) could not resolve host in ubuntu

At Bobcares, where we have more than a decade of expertise in managing servers, we see many customers face problems while managing a server.

Now, let’s see the major reasons for curl errors and how our Support Engineers fix this error.

1. Missing working DNS nameserver

Sometimes, users may receive a problem when trying to install packages like wget, apt-get not being able to resolve hosts.

For example, when executing a command apt-get install wget.

Users may get an error as curl#6 - "Could not resolve host: repo.xxx.com; Unknown error"

This mainly occurs when we don’t have nameservers in the /etc/resolv.conf

So, we added the following line in the file.

nameserver 8.8.8.8

Then, this fixed the error and the host started resolving.

2. Syntax error

Recently, one of our customers had a problem while executing the command curl on his terminal. He used the command as below,

curl -X 'GET https://www.mywebsite.com/Web2/PDF.aspx?page=1' 

Also, the error said Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36 OPR/51.0.2830.26'
curl: (6) Could not resolve host:

On checking, our Support Engineers found that the error was due to the incorrect syntax used to access the website.

So, we corrected the syntax as below. This happened as he had included space after one of the / escape sequences.

curl -X GET https://www.mywebsite.com/Web2/PDF.aspx?page=1/

Similarly, an error happened when running the following command

curl -i -H 'Content-Type: application/json' -d '{"Code":"FR","Name":"France"}' http://127.0.0.1:8080/countries

The error said Curl: (6) Could not resolve host: application.

This error was also due to the syntax error in the command. Thus, we resolved this problem editing like this in windows:

"{/"Code/":/"FR/"}"

In another case, we corrected it by deleting an extra space from the command.

curl -H Content-Type:application/json ~

Finally, this fixed the error.

[Need more help to solve curl error?- We’ll fix it for you.]

Conclusion

In short, an error curl (6) could not resolve host on ubuntu happens due to syntax error or due to the wrong DNS set up. Today, we saw how our Support Engineers assisted our customers to solve this error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

Linux is an Operating System whose core functionality revolves around the use of the command line terminal. Almost all of the tasks can be performed through the Linux terminal. Downloading from the web is one of these features. This is often accomplished using the curl command in the terminal. When utilizing this feature, an error can be encountered that has the statement “curl:(6) Could not resolve host”.

This article will shed some light on what is prompting these errors as well as what can be done to fix these issues.

There may be numerous reasons which will invoke this error. This section will not only elaborate on what these reasons are but also explain the necessary steps you can take to fix this problem.

Reason 1: Syntax Problem

The first and most obvious reason for a problem like this is that there is some issue with the curl command’s syntax. Usually, the syntax to curl is very simple to follow but even the slightest mistake can invoke the error as is shown in the snippet below:

It is very clearly seen that the syntax for the command above is incorrect. It is a very simple mistake that there is an unnecessary space in the link provided after curl.

Solution: Use the Correct Syntax

The only way to fix this issue is to follow the correct syntax of any curl command. The standard syntax for any curl command is as follows:

curl [options] [URL]

Now, let’s implement this syntax for the link shown above:

Now that the syntax problem has been avoided, we can see that the curl command works without any errors.

Reason 2: No DNS Nameserver

Nameservers act as a link between the domain name and the remote server of any web page. Instead of using the IP addresses, nameservers are utilized. But if the Nameserver is missing from your /etc/resolv.conf file then this error will be prompted.

Solution: Add DNS Nameserver

The simple solution to this issue is to add the nameserver of the URL to the file and save it. To add the nameserver, first, open the file using this command in the terminal:

$ sudo nano /etc/resolv.conf

This should open the file and we need to add the nameserver to the file using the following format:

nameserver ip.address

Check out the sample below to verify:

Once the nameserver is added, you can run the curl command with the link and the error will be resolved.

Conclusion

The “curl:(6) Could not resolve host” error occurs when the curl command is used with incorrect syntax or the DNS nameserver is missing. To fix it, you need to verify and check the syntax of the command or add a nameserver for the URL into your /etc/resolv.conf file. This article has provided a detailed guide on why the error “curl:(6) Could not resolve host” occurs and also the possible solutions to fix it.

Curl: (6) could not resolve host – What’s wrong?

If you are using Linux, you are not too unfamiliar with Terminal, which is a software program that allows the user to communicate with the computer by running pre-installed commands. When you are trying to install a new application for using Terminal, you may get the error Curl: (6) could not resolve host.

If you are facing the error Curl: (6) could not resolve host, there may be 2 reasons for that. First of all, IPV6 was enabled. And another one is the wrong DNS server. So, if you are troubled because of one of the two reasons above, we will bring you the ways to disable IPV6 and add a Google DNS server to deal with this error. Let’s get started now!

Recommended WordPress themes that are free, responsive and stable

How to fix Curl: (6) could not resolve host

As we mentioned above, the first solution we will show you is how to disable IPV6 to solve the error Curl: (6) could not resolve host. Here is the detailed instruction:

  • Open Terminal -> Type su and enter in order to log in as the super user.
  • Fill out the root password.
  • Change the directory cd/etc/modprobe.d/ to /etc/modprobe.d/
  • Type vi disableipv6.conf and generate a new file.
  • Press the combination key Esc + I to insert data into the file you have already created.
  • Enter install ipv6 /bin/true on the file in order to avoid loading modules related to IPV6.
  • Type Esc + : -> Type wp to save and exit.
  • Enter reboot to restart fedora -> Open terminal -> Type lsmod | grep ipv6
  • Now, if there is no result, you succeed in disabling IPV6.

The second method to deal with this error Curl: (6) could not resolve host is to add Google DNS server. Let’s follow the steps below:

  • Open Terminal -> Type su and enter in order to log in as the super user.
  • Fill out the root password.
  • In order to check what DNS server you are using, let’s type cat /etc/resolv.conf.
  • An open DNS server maintained by Google can help you to address this trouble. They are 8.8.8.8 and 8.8.4.4 but they may change in the future. Learn more here.
  • Enter vi /etc/resolv.conf in order to modify the file resolv.conf.
  • Press the combination key Esc + I to insert data into the file.
  • Insert # at the beginning of each line -> Fill out the two following lines in the file:

nameserver 8.8.8.8
nameserver 8.8.4.4

  • Type Esc + : -> Type wp to save and exit.

Everything is done and you don’t need to restart. The error will disappear now!

Trendy WordPress themes that you must try, it’s FREE!

Conclusion

To sum up, they are the two helpful solutions that are rated by many users. So, we hope that they will also support you to tackle the error Curl: (6) could not resolve host effectively. If you have any questions, please leave your comment below and we will answer you as soon as possible.

Furthermore, if you are finding some fast-loading speed, SEO-friendly and responsive free WordPress themes and Joomla 4 Templates, don’t hesitate to visit our site and explore the collection.

  • Author
  • Recent Posts

Lt Digital Team (Content &Amp; Marketing)

Welcome to LT Digital Team, we’re small team with 5 digital content marketers. We make daily blogs for Joomla! and WordPress CMS, support customers and everyone who has issues with these CMSs and solve any issues with blog instruction posts, trusted by over 1.5 million readers worldwide.

Lt Digital Team (Content &Amp; Marketing)

  • Cureit код ошибки 1746
  • Cups ошибка добавления принтера
  • Cups внутренняя ошибка сервера
  • Cups waiting for job completed ошибка linux
  • Cuphead ошибка при запуске