Ubuntu – Don’t see apache running in netstat

Apache2server

I'm just playing with apache and i got it to work, that is i can connect to server by browsing to http://127.0.0.1 and http://192.168.1.5 i'm NOT running IPv6

Yet this is the result of netstat

$ sudo service apache2 status
 * apache2 is running
$ netstat -an | grep :80
tcp6       0      0 :::80                   :::*                    LISTEN

$ wget 127.0.0.1
--2014-06-26 01:32:15--  http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11510 (11K) [text/html]
Saving to: ‘index.html’

100%[=====================================================================================================>] 11,510      --.-K/s   in 0s      

2014-06-26 01:32:15 (161 MB/s) - ‘index.html’ saved [11510/11510]

I was expecting to see it listening on a regular TCP which it clearly does!?

Edit:

$ netstat -a | grep LISTEN
tcp        0      0 localhost:ipp           *:*                     LISTEN     
tcp        0      0 localhost:mysql         *:*                     LISTEN     
tcp6       0      0 ip6-localhost:ipp       [::]:*                  LISTEN     
tcp6       0      0 [::]:https              [::]:*                  LISTEN     
tcp6       0      0 [::]:http               [::]:*                  LISTEN     

Edit2:
Why the down vote? What am i missing can someone elaborate?

Best Answer

TL;DR

Apache does appear in your netstatoutput, and it is running. That's why your wget call works. However, it's bound to your IPv6 address instead of your IPv4 one. Address mapping handles the translation when necessary.

Going for the docs

There's obviously some IPv6-IPv4 fallback mechanism here. As a matter of fact, I don't use IPv6 on my local network, yet :

$ netstat -tunla | grep LISTEN | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN

It is important to note that no matter how you address your machine, it's still the same service and port in the end. The rest is mainly up to your browser and DNS resolution services. However, for more information on how Apache handles this, you may want to have a look at their documentation :

One complicating factor for Apache administrators is whether or not an IPv6 socket can handle both IPv4 connections and IPv6 connections. Handling IPv4 connections with an IPv6 socket uses IPv4-mapped IPv6 addresses, which are allowed by default on most platforms, but are disallowed by default on FreeBSD, NetBSD, and OpenBSD, in order to match the system-wide policy on those platforms. On systems where it is disallowed by default, a special configure parameter can change this behavior for Apache.

Basically, this is about handling both IPv4 and IPv6 sockets in way that will avoid most problems related to cross-platform compatibility and socket handling. As you can read, on Linux platforms like Ubuntu, this problem is solved using IPv4-mapped IPv6 addresses. The documentation also states :

If you want Apache to handle IPv4 connections only, regardless of what your platform and APR will support, specify an IPv4 address on all Listen directives.

Which would give something like this in the ports.conf file :

Listen 0.0.0.0:80 # Or...
Listen 127.0.0.1:80 # Or...
Listen 192.0.2.1:80

Resulting in one of the following netstat outputs...

$ netstat -tunla | grep LISTEN | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN 
$ netstat -tunla | grep LISTEN | grep 80
tcp        0      127.0.0.1:80              127.0.0.1:80            LISTEN
$ netstat -tunla | grep LISTEN | grep 80
tcp        0      192.0.2.1:80              192.0.2.1:80            LISTEN 

A beautiful, yet IPv6-not-ready, listener. The above setting is usually set in /etc/apache2/ports.conf (or directly in apache2.conf for older versions). The default value is Listen 80, which performs an automatic binding, i.e. conforming to the IPv6 specifications given in the documentation.

Related Question