Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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
share|improve this answer

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.

share|improve this answer
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
Nice idea regarding the DHCP lease. – Steve Sep 30 '11 at 13:55
@Steve You still don't get the catch of OSI ( 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.