1

I have installed webserver (apache) but I can't seem to make netcat connect to it.

$ curl localhost:80 | head
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10701  100 10701    0     0  2230k      0 --:--:-- --:--:-- --:--:-- 2612k

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Apache2 Debian Default Page: It works</title>
    <style type="text/css" media="screen">
  * {
    margin: 0px 0px 0px 0px;
    padding: 0px 0px 0px 0px;

$ nc localhost 80
localhost [127.0.0.1] 80 (http) : Connection refused

I've also tried the same experiment with nginx before. With the same results.

I'm on debian and there's no firewall active, what am I doing wrong?

6
  • can you pipe a command to the session? echo "GET index.html" | nc localhost 80? – Sven Jul 26 '18 at 11:05
  • $ echo "GET index.html" | nc localhost 80 Result: localhost [127.0.0.1] 80 (http) : Connection refused – Marcelo Lacerda Jul 26 '18 at 11:16
  • How have you configured Apache to Listen? – Michael Hampton Jul 26 '18 at 13:05
  • Listen 80 <IfModule ssl_module> Listen 443 </IfModule> <IfModule mod_gnutls.c> Listen 443 </IfModule> – Marcelo Lacerda Jul 26 '18 at 15:04
  • 1
    Run curl -v for more information on the actual request and what localhost is resolving to (perhaps ipv6 ::1 instead of 127.0.0.1?) – Jason Floyd Jul 27 '18 at 20:44
0

The problem was that the netcat that was installed was netcat-traditional which does not support IPV6 and for some reason both apache2 and nginx were listening only on the IPV6 loopback.

curl 127.0.0.1
curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused

The solution was to install and use netcat from openbsd and netcat could connect with either nc ::1 80 or nc localhost 80.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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