Apache server not listening on IPv4 but listening on IPv6

28,266
assiduus@localhost:~/httpd-2.4.34$ ./configure --help | grep IPv6
--enable-v4-mapped      Allow IPv6 sockets to handle IPv4 connections
assiduus@localhost:~/httpd-2.4.34$

This is enabled by default when you compile Apache httpd from source. If you used your distribution binary package then apparently this option is enabled.

Share:
28,266

Related videos on Youtube

amol
Author by

amol

Updated on September 18, 2022

Comments

  • amol
    amol over 1 year

    We are facing one weird problem on one of our RHEL apache server.

    Actually, it is not listening on port 80 from remote hosts. When we locally browse http://localhost it is opening default page. When we checked listening port through netstat, we found that only tcp6 interface was listening at :::80. And there was no entry for tcp, and that entry should be present there like

    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
    

    I have tried searching many forums for this issue, but none of the solution suggested worked. In httpd.conf, we change Listen 80 to Listen 0.0.0.0:80and Listen 127.0.0.0:80 but it did not open 80 port to access from remote hosts. IPtables is disabled from the beginning.

    How can we set the server to listen on IPv4?

    • Johan Myréen
      Johan Myréen over 6 years
      You could try to set net.ipv6.bindv6only=0 in /etc/sysctl.conf and then run sudo sysctl -p. This makes the socket listen on both IPv4 and IPv6.
    • Rui F Ribeiro
      Rui F Ribeiro over 6 years
      tcp6 0 0 :::80 Is indicative of the server listening both in IPv4 and IPv6. You can put it back at Listen 80. How is the vhost/default vhost configured?
    • Raman Sailopal
      Raman Sailopal over 6 years
      Check you apache logs for any issues relating to listening on the ip4 address,
    • amol
      amol over 6 years
      @JohanMyréen I tried using your suggestion, but the result is unchanged. Raman, there are no specific logs generated related to IPv4. Surprisingly, SSH server is running and it is listening on IPv4 and IPv6 port 22. When tried with Listen 0.0.0.0:80 in httpd.conf, the netstat showed tcp entry as tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN but still the port 80 was not accessible from remote hosts.
    • Johan Myréen
      Johan Myréen over 6 years
      Try if the connection succeeds from the local host using the non-localhost IP address. If it is ok, and nothing else that you have tried works, I suspect the problem lies elsewhere (firrewall, etc.) Listening on :::80 should not be a problem, since normally a socket listening on IPv6 also accepts IPv4 connections, unless disabled with bindv6only=1.
    • amol
      amol over 6 years
      Johan, I appreciate your suggestions. I am able to open localhost in the same system. But when I access the server from remote host in the same network, it does not give any response. I have completely removed httpd package with all conf files and reinstalled it but the issue is still there. IPTables is completely out of frame as we have disabled it from beginning.
    • Johan Myréen
      Johan Myréen over 6 years
      But can you connect in the same system, not using localhost (127.0.0.1 or ::1) but the IP address of the server? Let's say the server IP address is 10.2.3.4, try URL http://10.2.3.4/.