34

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.

Nishu Tayal
  • 20,106
  • 8
  • 49
  • 101
Amelie
  • 535
  • 1
  • 5
  • 13
  • 1
    Are you actually sure that 127.0.0.1 is being listened to? – Amir Raminfar Dec 07 '16 at 21:05
  • The ping works already. Do you mean another thing ? – Amelie Dec 07 '16 at 21:06
  • @user1231728 ping and curl operate on different protocol layers and in does quite different things. curl connects to a TCP port, and expects to talk http over that tcp connection (by default). If you do not have anything listening on TCP port 8080 on your machine, curl will correctly report connection refused. – nos Dec 07 '16 at 21:10
  • Ping will always work. Ping doesn't hit a port though. You have to have an application listening on port 8080. – Amir Raminfar Dec 07 '16 at 21:10
  • Ok. How can I test it – Amelie Dec 07 '16 at 21:11
  • `telnet 127.0.0.1 8080` will try to connect to the port. – Barmar Dec 07 '16 at 21:17
  • I think you already tested it: if connection is refused, nobody is listening there. But what are you using curl for? I guess you are trying to connect to some web server. So, have you started the server? Is it configured ti listen at 8080 or the standard 80? I don't see the need to add 127.0.0.1 to hosts file but to assign it a name (usually localhost). This loopback address will always correspond to local computer anyway. – Juan Dec 07 '16 at 21:18
  • My goal is to connect to another adress (another machine in the network) to download a file from it, but, it didnt work too. That is why I switched to localhost, just to test it. – Amelie Dec 07 '16 at 21:21

5 Answers5

33

Make sure you have a service started and listening on the port.

netstat -ln | grep 8080

and

sudo netstat -tulpn
Peter
  • 449
  • 5
  • 9
8

Try curl -v http://localhost:8080/ instead of 127.0.0.1

Dima Lituiev
  • 12,544
  • 10
  • 41
  • 58
Sudharasan D
  • 119
  • 5
0

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

0

You have to start the server first, before using curl. On 8/10 occasions that error message arises from not starting the server initially.

Sten Techy
  • 79
  • 1
  • 7
-11

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.

user41909
  • 27
  • 1
  • 127.0.0.1 is the localhost interface. It still needs a server to listen on that port. – user3486184 Jun 20 '17 at 17:59
  • if we specify 0.0.0.0 as the desired IP address for IPv4 configurations, the development server will listen on every interface on port 8000. In addition, it is necessary to open default port 8000 in our firewalls (software and/or hardware and configure port-forwarding to the computer that is running development server. – user41909 Jun 20 '17 at 18:44