when I try đồ sộ load a trang web page đồ sộ terminal it gives curl: (6) Could not resolve host
error.
I have mạng internet in my PC and trying from my trang chủ mạng 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 tên miền name, it works fine.
[root@localhost kevin]# curl http://173.194.46.0
any clue please?
Sathish
3,8501 gold badge18 silver badges28 bronze badges
asked Jul 26, năm trước at 5:26
Nayana AdassuriyaNayana Adassuriya
24.7k34 gold badges113 silver badges152 bronze badges
5
Issues were:
- IPV6 enabled
- Wrong DNS server
Here is how I fixed it:
IPV6 Disabling
- Open Terminal
- Type
su
and enter đồ sộ log in as the super user - Enter the root password
- Type
cd /etc/modprobe.d/
đồ sộ change directory đồ sộ/etc/modprobe.d/
- Type
vi disableipv6.conf
đồ sộ create a new tệp tin there - Press
Esc + i
đồ sộ insert data đồ sộ file - Type
install ipv6 /bin/true
on the tệp tin đồ sộ avoid loading IPV6 related modules - Type
Esc + :
and thenwq
for save and exit - Type
reboot
đồ sộ 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 đồ sộ log in as the super user - Enter the root password
- Type
cat /etc/resolv.conf
đồ sộ kiểm tra what DNS server your Fedora using. Mostly this will be your Modem IP address. - Now we have đồ sộ Find a powerful DNS server. Luckily there is a open DNS server maintain by Google.
- Go đồ sộ this page and find out what are the "Google Public DNS IP addresses"
- Today those are
8.8.8.8
and8.8.4.4
. But in future those may change. - Type
vi /etc/resolv.conf
đồ sộ edit theresolv.conf
file - Press
Esc + i
for insert data đồ sộ file - Comment all the things in the tệp tin 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 thenwq
for save and exit- Now you are done and everything works fine (Not necessary đồ sộ restart).
- But every time when you restart the computer your /etc/resolv.conf will be replaced by mặc định. So I'll let you find a way đồ sộ avoid that.
Here is my blog post about this: http://codeketchup.blogspot.sg/2014/07/how-to-fix-curl-6-could-not-resolve.html
answered Jul 28, năm trước at 1:29
Nayana AdassuriyaNayana Adassuriya
24.7k34 gold badges113 silver badges152 bronze badges
5
There is no need đồ sộ disable IPv6 as the answer suggests. The reason curl fails is simply because the DNS resolution is missing.
There is one liner solution đồ sộ 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 nội dung of the file:
echo 'nameserver 1.1.1.1' | sudo tee /etc/resolv.conf >/dev/null
answered Oct 11, 2021 at 17:33
HoumanHouman
66.1k95 gold badges290 silver badges479 bronze badges
1
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 đồ sộ spot from /tmp/wtf
output tệp tin what's going on.
answered Jul 26, năm trước at 11:12
SathishSathish
3,8501 gold badge18 silver badges28 bronze badges
5
I have today similar problem. But weirder.
- host - works
host pl.archive.ubuntu.com
- dig - works on mặc định 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 đồ sộ 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
<
302 Moved
302 Moved
The document has moved
here.
* Connection #0 đồ sộ 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 đồ sộ 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 đồ sộ solve this issue!
systemctl restart nscd.service
answered Jun 29, 2017 at 11:29
3
Try nslookup google.com đồ sộ determine if there's a DNS issue. 192.168.1.254 is your local network address and it looks lượt thích 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 đồ sộ it on a Internet trang web browser?
answered Jul 26, năm trước at 13:25
2
Could be a firewall issue.
Try:
ufw allow out 53
reboot
answered Oct 8, 2023 at 21:42
In Our case, the command was passed through mail/skype and the person who needs đồ sộ 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
nikhil2000nikhil2000
1884 silver badges16 bronze badges
I had an issue with IPV6 that suddenly showed up in wordpress admin where curl failed đồ sộ connect đồ sộ 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 tệp tin 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
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, 2023 at 20:49
AJBAJB
7,58415 gold badges60 silver badges91 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, 2023 at 20:35