curl always connects to a specific ip:port pair - linux

I'm running into this scenario on one of our linux boxes.
$ curl 10.200.20.66:8087/ping
curl: (7) Failed to connect to 219.135.102.36 port 8118: Connection timed out
$ curl 114.114.114.114:80/x
curl: (7) Failed to connect to 219.135.102.36 port 8118: Connection timed out
As you can see, curl has always been trying to connect 219.135.102.36:8118.
I've tried using nc and telnet and both of them give correct results.
Finally I've turned to strace curl 10.200.20.66:8087/ping and here's output.
Can anybody help explain why this happened?

To be sure what is happening, turn on verbosity with -v switch:
$ http_proxy=1.2.3.4:8080 curl -v http://google.com
* About to connect() to proxy 1.2.3.4 port 8080 (#0)
* Trying 1.2.3.4...
* Connection timed out
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
In your case, I'd guess that Curl tries to use proxy. If that is the case, you should check the following:
http_proxy environment variable:
Check:
env | grep -i proxy
Curl configuration file ~/.curlrc (unlikely, it doesn't show in strace)
Proxy can be proxided on command line (-x or --proxy), so check if curl isn't aliased in your shell

Curl should be used with website, http,https,ftp.
example curl "http://www.google.com"
it provides the output in html format
Kindly check and try in correct format

Related

curl: (7) Failed to connect to port 80, and 443 - on one domain

This question shows research effort; it is useful and clear
I have checked the cURL not working properly
When I run the command curl -I https://www.example.com/sitemap.xml
curl: (7) Failed to connect
Failed to connect on all port
this error only on one domain, all other domain working fine, curl: (7) Failed to connect to port 80, and 443
Thanks...
First Check your /etc/hosts file entries, may be the URL which You're requesting, is pointing to your localhost.
If the URL is not listed in your /etc/hosts file, then try to execute following command to understand the flow of Curl Execution for the particular URL:
curl --ipv4 -v "https://example.com/";
After many search, I found that Hosts settings not correct
Then I check nano /etc/hosts
The Domain point to wrong IP in hosts file
I change the wrong IP and its working Fine
This is new error Related to curl: (7) Failed to connect
curl: (7) Failed to connect
The above error message means that your web-server (at least the one specified with curl) is not running at all — no web-server is running on the specified port and the specified (or implied) port. (So, XML doesn't have anything to do with that.)
you can download the key with browser
then open terminal in downloads
then type sudo apt-key add <key_name>.asc
Mine is Red Hat Enterprise(RHEL) Virtual Machine and I was getting something like the following.
Error "curl: (7) Failed to connect to localhost port 80: Connection refused"
I stopped the firewall by running the following commands and it started working.
sudo systemctl stop firewalld
sudo systemctl disable firewalld
If the curl is to the outside world, like:
curl www.google.com
I have to restart my cntlm service:
systemctl restart cntlm
If it's within my network:
curl inside.server.local
Then a docker network is overlapping something with my CNTLM proxy, and I just remove all docker networks to fix it - you can also just remove the last network you just created, but I'm lazy.
docker network rm $(docker network ls -q)
And then I can work again.

Curl : connection refused

I got the following error while running curl:
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection
refused.
It seems that it is easy to debug, but, I didnt find how to solve it.
The adress 127.0.0.1 is mentioned in the file etc/hosts.
I am using curl version 7.47 on Ubuntu system.
Anyone has an idea about it ?
Thank you.
Make sure you have a service started and listening on the port.
netstat -ln | grep 8080
and
sudo netstat -tulpn
Try curl -v http://localhost:8080/ instead of 127.0.0.1
Listen to the port in one session and then open another session to test it with l$ curl -v http://localhost:8080/
It should work. That's how I worked although in l
Termux
You have to start the server first, before using curl. On 8/10 occasions that error message arises from not starting the server initially.
127.0.0.1 restricts access on every interface on port 8000 except development computer. change it to 0.0.0.0:8000 this will allow connection from curl.

cURL --resolve issues

I am trying to make a cURL request that resolves to a specific IP. From everything I've read, this looks syntactically correct to me but I am still seeing the 'could not resolve host error'. Can someone point me in the right direction? I'm seeing a variety of errors:
curl —-resolve e-dinar.io:443:42.81.15.75 "https://e-dinar.io"
IDN support not present, can't parse Unicode domains
* getaddrinfo(3) failed for —-resolve:80
curl —-resolve e-dinar.io:443:42.81.15.75 "https://e-dinar.io:443"
curl: (6) Couldn't resolve host '—-resolve'
curl: (6) Couldn't resolve host 'e-dinar.io:443'
curl "https://e-dinar.io:443" —-resolve e-dinar.io:443:42.81.15.75
curl: (6) Couldn't resolve host '—-resolve'
curl: (6) Couldn't resolve host 'e-dinar.io:443'
Any thoughts where I am going wrong? Thanks.
You are using wrong - in the curl command (—), change —- to --.
You have a hint in curl response here:
curl: (6) Couldn't resolve host '—-resolve'
curl tries to get data from —-resolve host, it doesn't parse it as a command because of wrong -.

How to allow curl via a local proxy?

According the the Charles Proxy configuration page, you can manually set up a proxy if you use your localhost with port 8080.
The syntax is curl --proxy localhost:8080 http://google.com/
However, this is not working for me. Here is my syntax and results - i'm also using the -v option for debugging:
curl -v --proxy localhost:8080 http://google.com/
* About to connect() to proxy localhost port 8080 (#0)
* Trying 127.0.0.1... Connection refused
* Trying ::1... Connection refused
* Trying fe80::1... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
I can connect to localhost:8080 in the web browser, and the results are logged in the proxy. However this is not working, the connecting is refused and nothing is logged.
So far I have also tried:
- executing this as root
- using 127.0.0.1 instead of localhost
- using wget instead of curl
- disabling the system firewall
What am I doing wrong? What else can I try?
I had some success using port 8888:
curl http://www.google.com --proxy 127.0.0.1:8888
Connection refused would suggest that nothing is listening on port 8080. Charles has to be running (and listening on port 8080) for curl to be able to use it as a proxy. That or you've got a firewall actively blocking that port, preventing anything from connecting.

how to get response from a remote server by using curl command through proxy?

Please give a simple syntax for making a curl command that will connect to the remote server through proxy......
curl -x my-proxy:8080 www.bbc.co.uk
Try here for more details: http://curl.haxx.se/docs/manual.html

Resources