1

I run Apache inside VirtualBox on a laptop. I also used IP based VirtualHost-s. I want to be able to have LAN access whenever I move about, to certain pre-known networks. The IP, however, is not "moving", since I've setup DHCPs on the network routers to asign static IPs to MACs, so the IP is basically static on each location.

I want to have all those IPs in my Apache config.

However, the Listen directive fails when one of the interfaces is not available.

Is there any way I could make the Listen directive work in an OR fashion instead of AND fashion?

Thank you.

Ate Somebits
  • 157
  • 9
  • I don't think this is possible. You can, however, have Apache bind to all interfaces on a certain port. – parkamark Aug 17 '18 at 16:40
  • 1
    Are you only interested in solutions for BSD? I have very little experience with BSD, but I know a solution for Linux. – kasperd Aug 18 '18 at 15:24
  • @kasperd I could use anything, cheers. – Ate Somebits Aug 19 '18 at 15:31
  • @kasperd My bad. Could you move the question to the Super User? – Ate Somebits Sep 02 '18 at 12:05
  • 1
    @AgnesK.Cathex I voted to migrate this question to [unix.se] where I think it would be better suited. But the majority voted to close it without migrating it. There are two things you can do yourself. You can edit your question to improve it, for example stating what exact OS version you are trying to do this on and whether using a different OS is an option. Alternatively you can use the link above to flag your question for moderator attention as moderators have the powers to migrate questions. There isn't much more I can do. – kasperd Sep 02 '18 at 12:19
  • @kasperd Thank you very much for the explanation. But your answer already helped me a lot. I don't have time at the moment to reword the question, so it's fine. Thanks for your attention. – Ate Somebits Sep 02 '18 at 12:23

1 Answers1

3

If you want Apache to listen on all IP addresses assigned to the machine you can simply specify a bind directive without any IP address, for example:

Listen 80

If you need to bind to only a subset of assigned addresses a possible solution to this is to ensure that both IP addresses are always assigned to the machine even while they are not assigned to the physical interface.

From question and comments I understand that you are currently using BSD, but are open to other platforms if that will solve the problem. Following is how I did something very similar on Ubuntu. I expect that some variation of this would also work on BSD, but I don't have enough BSD knowledge to give a detailed solution for BSD.

Linux has a dummy network driver with a dummy interface called dummy0 which you can assign IP addresses to. Those IP addresses will be considered local just the same as IP addresses assigned to physical interfaces, so Apache can bind to them.

In /etc/network/interfaces I added a post-up line like this:

post-up /usr/local/sbin/eth0-post-up

And in /usr/local/sbin/eth0-post-up I then loaded the dummy driver and configured all the IP addresses I needed:

#!/bin/bash
modprobe dummy
ip address add dev dummy0 10.58.249.248/32
ip address add dev dummy0 10.138.65.134/32
kasperd
  • 30,455
  • 17
  • 76
  • 124
  • cool, I'll dive into FreeBSD handbook, and get back to you.... sorry, can't vote yet. – Ate Somebits Aug 19 '18 at 21:59
  • The only thing I've managed to dig out is the *ifconfig alias* mechanism. It sure solves the problem for failsafe Apache restart, but I haven't a single clue as to the side effects, one of which might be that Apache spits out a lot of 206 responses. – Ate Somebits Sep 02 '18 at 12:09
  • 1
    @AgnesK.Cathex A few 206 responses is not unusual if you are serving large static files. It's not necessarily a problem with your server. Look for a pattern in which client IPs get the 206 responses. – kasperd Sep 02 '18 at 12:24
  • Ok, that seems like a good troubleshooting step. More explicitly, any page that is more than a few lines of HTML, takes ages to load, and loads only partly. Not so with Host-Only loopback, which works fine. For example, *localhost/manual* (I added VBox NAT into the mix) takes indeterminate amount of time to load, and doesn't properly load. Ditto for an SVG page. A very minimalistic index.html loads OK. – Ate Somebits Sep 02 '18 at 12:33
  • Ditto for bridged interface. Thought at first, problem with wireless NIC, but then NAT behaves the same. So far, my only guess is I oughta tune the tcp offloading sysctl params. – Ate Somebits Sep 02 '18 at 12:40
  • 1
    @AgnesK.Cathex Those additional symptoms suggest you may have a problem with the network stack. Maybe the server is periodically losing and regaining the IP address? – kasperd Sep 02 '18 at 12:46
  • The 206 response was perhaps not the symptom, but I came to realize two things: 1) bridged wireless emulation _does not exist in reality_, and 2) _virtio_ - guest system integrated net emulation - doesn't work well with NAT, at least not "out of the box". – Ate Somebits Dec 15 '18 at 10:36