3

I can't get Apache to listen on a specific IP address. It's a local web server, not public.
I'm on CentOS 5.11 using Apache 2.2.
The default configuration httpd.conf works great but only listens to the server's static IP address 10.0.0.101:80.

I appended Listen 10.0.0.103:80 to the end of the httpd.conf but get the error:

Starting httpd: (99)Cannot assign requested address: make_sock: could not bind to address 10.0.0.103:80

I'm following a tutorial on making a high availability cluster which can be seen at https://www.howtoforge.com/high_availability_heartbeat_centos. If I could only get Apache to start on that address, I'd be golden.

I'm using this old version of CentOS because I'm trying to put old hardware to use instead of junking it.

I looked for 4 hours straight on Google, the CentOS site, and Apache's site and found no solution.

HBruijn
  • 77,029
  • 24
  • 135
  • 201

2 Answers2

6

Apache won't bind to your VIP because it is not configured on any network interface.

To allow this to happen, you need to set a sysctl:

sysctl net.ipv4.ip_nonlocal_bind=1

Apache can then do the bind, but of course no traffic will flow until the VIP is assigned to the machine.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • THANK YOU SO MUCH!!! I'm not sure what you just did but this worked. Can you tell me how you knew to do that? Or can you point me to a Web page that can explain more about this solution? – Rhyknowscerious Feb 09 '16 at 03:09
  • 2
    I've seen at least a little of many, many things. :) – Michael Hampton Feb 09 '16 at 03:14
  • Applications can set the `IP_FREEBIND` option on the socket before binding to achieve the same result. Using that socket option rather than the kernel setting would make it work with both IPv4 and IPv6. But I don't know if any version of Apache supports that socket option. – kasperd Feb 09 '16 at 08:36
  • @MichaelHampton One quick question: what's the best way to automatically enable sysctl net.ipv4.ip_nonlocal_bind=1 on startup? – Rhyknowscerious Feb 14 '16 at 17:25
2

In your httpd.conf check if you have an older 'Listen' directive active. By appending the new directive you can have two directives clashing.

Else check if another process is listening on port 80 by running this:

netstat -plant

Hopefully you see something like this and kill it:

Proto Recv-Q Send-Q Local Address           Foreign Address         State      PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     939/webserver        
FoamyBeer
  • 371
  • 1
  • 5