I'm executing curl and no matter what URL I point it to, it always tries to connect to and port 8080:

$ curl -v http://asdfsafzsdfsdf/
*   Trying
* connect to port 8080 failed: Connection refused
* Failed to connect to localhost port 8080: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 8080: Connection refused

In the above example I'm using a non-existing domain 'asdfsafzsdfsdf' but the same happens with existing domains like google.com.

But, if I point it to an SSL URL like https://google.com, it resolves and performs the request OK. Also, if I point it to https://asfasdfasdfdasfd, it tries to resolv it and fails (no weird resolution):

$ curl -v https://asdfsadfsafsdf
* Rebuilt URL to: https://asdfsadfsafsdf/
* Could not resolve host: asdfsadfsafsdf
* Closing connection 0
curl: (6) Could not resolve host: asdfsadfsafsdf

This suggests me that perhaps "some" form of interference cannot happen when making SSL connections (maybe they cannot be cached by whatever it is that is causing this, or something).

If I run "host asdfsadfsadf" or "dig asdfasfsafa" it fails as you would expect it to. But "wget" behaves the same way as "curl" (I know they resolve DNS differently, so maybe this is a clue).

I've been investigating this for hours now. I don't have any entries in /etc/hosts, I'm not running any DNS cache, I've checked /etc/nsswitch.conf and I just have "files, dns" resolution, I don't have any special iptables configurations, etc.

More importantly, putting aside the DNS part of the problem... why port 8080?

This is super weird, why could this be happening? Any ideas?

I'm running Ubuntu 16.04.



It looks like you have a proxy server defined in your environment, e.g. in the http_proxy environment variable.

Check your shell environment and remove the variable from whichever shell startup script defines it, or start the proxy server.

Alternately, you can ask curl to ignore the proxy environment variable by passing -x "".

curl -x "" https://www.google.com/
  • You are a lifesaver! It was that :O I guess I did some testing and left this setting: declare -x http_proxy="localhost:8080". Thanks! – jotadepicas Feb 1 at 18:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.