1

I have 2 ethernet ports on my machine, both receiving their IP addresses via DHCP.

I would like to run essentially two web servers on the machine. Technically, I would like to run Apache on one address/port combination, and Node.js listening on port 80 on the other ethernet port.

All Apache documentation I've found mentions using the Listen directive for specifying which address/port Apache should listen on. The only problem is that my IP addresses are dynamic, and I don't want to bother changing the config every time my IP changes.

Is there anyway to tell Apache to bind to a specific MAC address?

I'm pretty sure the answer is no, considering the socket bind function appears to require an IP address, unless it's smart enough to take a MAC or port name, and lookup the associated IP.

Steve
  • 225
  • 3
  • 9

2 Answers2

1

Servers are just not meant to run on dynamic IPs. I don't believe you can get apache to listen on a MAC address, but I can suggest two possible work arounds:

  1. have the two web services run on different ports rather than different IPs - EASY
  2. hack the apache startup script so that it detects the IP addresses on the two cards, and then edits the config file before actually starting the server - MESSY HACK
Bart B
  • 3,457
  • 6
  • 31
  • 42
1

TCP/IP is something on OSI-Layer 3 and 4. Whereas MAC addresses are on OSI-Layer 2.

And binding sockets can only work on the TCP/IP level and has no access to the Layer 2. So what you are trying to do is not possible the way you want it to be.

You can solve that by specifying static DHCP leases for your MAC so that the MAC will always get a fixed IP out of the DHCP pool.

mailq
  • 17,023
  • 2
  • 37
  • 69
  • 1
    I don't agree that it's no possible. It may not be possible using current Apache configuration options, but it should definitely be possible. That's why I was asking. In a C program, I can get a list of the machines interfaces, and mac addresses, and then lookup the appropriate IP to bind the socket. – Steve Sep 28 '11 at 12:51
  • @Steve In this case you switch between layers. You assume that you have Ethernet all the time. But you can even have a Link Layer without using MAC-Addresses and on top of that run TCP/IP. In this case you don't have MAC addresses at all. Apache will run on this because of the abstraction used. – mailq Sep 28 '11 at 15:54
  • It would be perfectly reasonable for the folks at Apache to provide additional support for Ethernet. Sure someone may use ATM, or whatever, but I'm sure a large user base is using Ethernet. – Steve Sep 30 '11 at 13:55
  • 2
    Nice idea regarding the DHCP lease. – Steve Sep 30 '11 at 13:55
  • 1
    @Steve You still don't get the catch of OSI (http://en.wikipedia.org/wiki/OSI_model). There is a reason for separation. And there is no reason to break the separation. So nobody writing software for the upper layers cares about the layers below. This is by design! – mailq Sep 30 '11 at 14:02
  • You don't get my point. I understand the layering model. I used to write IP routing software, bridging, and kernel drivers. I get it, trust me. Explain to me why the Apache dev's cannot provide the ability to provide a mac address in a configuration file, use that mac address to scan through the machine interfaces, and lookup the associated IP, and then bind using a socket. Sounds straight forward and perfectly legit to me. If I don't use Ethernet, then I don't use the extra convenience of being able to specify a mac, and use IP. – Steve Sep 30 '11 at 15:45
  • After the binding of the server socket, everything is still the same from the developers perspective. – Steve Sep 30 '11 at 15:52
  • @Steve Whatever. Bring it on the Apache feature request list. Then you will see if they laugh at you. I'll bet you that they are not going to implement this. – mailq Sep 30 '11 at 16:00
  • @maliq Ok, so you're admitting that it's possible. So, now back to my original question...does the server support that configuration? I'm not asking whether they will add support. – Steve Sep 30 '11 at 17:12