Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to map 2 different MAC addresses to the same IP address?

For my backup, I need to connect back from the server to the portable, and I would like to have the same IP both for the wireless and the wired interface.

The openwrt web interface doesn't accept multiple dhcp entries with the same IP address, but perhaps there is a workaround?

Clarification added on 23 may:

I should have made it clear that only one of the network interfaces of the portable is connected to the network at any given time (hence switches shouldn't get confused). Initially I had 2 distinct IP addresses assigned to the interfaces, with the same DNS name, but this didn't work very well (timeouts when I got the wrong IP). Yet I want to use the same name for both, as it is hard-coded in my backup script.

Sorry for the confusion.

share|improve this question

migrated from stackoverflow.com May 21 '11 at 22:08

This question came from our site for professional and enthusiast programmers.

    
I'm pretty sure shenanigans will ensue if you attempt this. –  Holocryptic May 21 '11 at 22:20
    
The OS on the client (and possibly the server) might also be germaine here –  Norky May 23 '11 at 17:45

6 Answers 6

up vote 11 down vote accepted

(random semi-opinionated comment: it's rare to see this highish count of unconstructive and plain inaccurate answers and comments to a question)

In contrast to others here, I claim that your request is actually quite elementary and has been supported in dnsmasq since version 2.46, IIRC. This was the sole reason I switched from dd-wrt. After about a year of running OpenWRT, I now know there are actually plenty more reasons to switch, but that's beside the point.

I'm running Backfire 10.04-rc4:

May 23 17:45:16 gateway dnsmasq[1925]: started, version 2.55 cachesize 150

My configuration:

$ cat /etc/config/dhcp

config 'dnsmasq'
    option 'domainneeded' '1'
    option 'boguspriv' '1'
    option 'localise_queries' '1'
    option 'rebind_protection' '1'
    option 'rebind_localhost' '1'
    option 'expandhosts' '1'
    option 'authoritative' '1'
    option 'readethers' '1'
    option 'leasefile' '/tmp/dhcp.leases'
    option 'resolvfile' '/tmp/resolv.conf.auto'
    option 'enable_tftp' '1'
    option 'domain' 'domain.net'
    option 'local' '/domain.net/'

config 'dhcp' 'lan'
    option 'interface' 'lan'
    option 'start' '100'
    option 'limit' '150'
    option 'leasetime' 'infinite'

config 'dhcp' 'wan'
    option 'interface' 'wan'
    option 'ignore' '1'
    option 'dynamicdhcp' '0'

config 'dhcp'
    option 'interface' 'dmz'
    option 'start' '100'
    option 'limit' '150'
    option 'leasetime' '12h'

config 'host'
    option 'name' 'travelmate'
    option 'mac' '00:11:22:33:44:55 aa:bb:cc:dd:ee:ff'
    option 'ip' '192.168.1.111'

config 'host'
    option 'name' 'mobilitymac'
    option 'mac' '99:88:77:66:55:44 ff:ee:dd:cc:bb:aa'
    option 'ip' '192.168.1.104'

Enjoy the seamless transition this setup provides, all existing session stay alive if you don't take too long with the switch.

share|improve this answer
3  
Would upvote this answer, because it answers my question in a very detailed way, but don't have the karma yet. –  sleepyMonad May 24 '11 at 15:20
    
And extra brownie points, as luci (the web interface) seems to actually support this format. –  sleepyMonad May 24 '11 at 15:52
1  
Last night I happened to have a situation where I didn't know wlan0 was still connected (staging brcm80211 might be tiny bit b0rked) when connecting eth0. dnsmasq didn't have a particular issue with this, it just assigned a new IP for eth0. Bad thing is that you then have to go into router, stop dnsmasq and edit/kill /tmp/dhcp.leases, re-start dnsmasq for things to return to desired operational mode. –  lkraav May 25 '11 at 3:21

I would be very surprised if your switch can support this. You might have more luck giving both network interfaces the same MAC address.

Saying that, I definitely agree with Holocryptic, here be dragons.

share|improve this answer
    
thanks for suggesting to use the same MAC; although I'm not sure about how to do that. Perhaps it's something I can configure from the BIOS... –  sleepyMonad May 23 '11 at 17:24
    
It's normally easiest to just set it in the OS, on windows it's under properties of the network interface (manually set MAC address). –  happyhairydude May 23 '11 at 20:21

Your aim: to have constant-hostname-of-laptop always point to the (active IP address/interface of the) laptop? I would have thought that the combined DNS-and-DHCP service of dnsmasq would do that, i.e. when a client does a DHCPDISCOVER/DHCPREQUEST it reports its hostname, and dnsmasq associates the hostname with whichever IP address is assigned. That has been my experience, however I must admit I've not tried connecting with one network i/f, then disconnecting (without doing an explicit release) and connecting again with another.

Assuming a hostname of "laptop", what happens when you query the OpenWRT device for "laptop", after having switched from one interface to another?

share|improve this answer

Why use DHCP?

You can manually configure a static IP address on both interfaces, and then use the one you prefer (while leaving the other one disconnected, of course).

share|improve this answer
    
Well, because this is the easiest method, the one config that fits all the networks I connect to (or so I hoped, at least). –  sleepyMonad May 24 '11 at 5:13

No, it's not possible. But most NICs allow you to administartively set the MAC, and you could set both NICs to the same MAC.

On most *nix boxen you can usually do this, then setup a failover LAGG interface to both (with preference for the wired) to allow your to hotplug the wired connection without disconnecting TCP sessions.

share|improve this answer

I did a bit of research.

First thing I learned is that it is possible to assign DHCP leases based on criteria other than a MAC address.

From the dhcp FAQ:

What is a Client ID?

What is termed the Client ID for the purposes of the DHCP protocol is whatever is used by the protocol to identify the client computer. By default, DHCP implementations typically employ the client's MAC address for this purpose, but the DHCP protocol allows other options. Some DHCP implementations have a setup option to specify the client ID you want. One alternative to the MAC address is simply a character string of your choice. In any case, in order for DHCP to function, you must be certain that no other client is using the client ID you choose, and you must be sure the DHCP server will accept it.

Then, although it is apparently not supported by the luci web interface on openWRT, dnsmasq itself supports client_id, and multiple MAC addresses (with the some cautioning).

From the dnsmasq man page:

-G, --dhcp-host=[hwaddr][,id:client_id|*][,set:tag][,ipaddr][,hostname][,lease_time][,ignore] Specify per host parameters for the DHCP server. This allows a machine with a particular hardware address to be always allocated the same hostname, IP address and lease time. A hostname specified like this overrides any supplied by the DHCP client on the machine. It is also allowable to ommit the hardware address and include the hostname, in which case the IP address and lease times will apply to any machine claiming that name. For example --dhcp-host=00:20:e0:3b:13:af,wap,infinite tells dnsmasq to give the machine with hardware address 00:20:e0:3b:13:af the name wap, and an infinite DHCP lease. --dhcp-host=lap,192.168.0.199 tells dnsmasq to always allocate the machine lap the IP address 192.168.0.199.

(...)

It is allowed to use client identifiers rather than hardware addresses to identify hosts by prefixing with 'id:'. Thus: --dhcp-host=id:01:02:03:04,..... refers to the host with client identifier 01:02:03:04. It is also allowed to specify the client ID as text, like this: --dhcp-host=id:clientidastext,.....

(...)

As a special case, it is possible to include more than one hardware address. eg: --dhcp-host=11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.2 This allows an IP address to be associated with multiple hardware addresses, and gives dnsmasq permission to abandon a DHCP lease to one of the hardware addresses when another one asks for a lease. Beware that this is a dangerous thing to do, it will only work reliably if only one of the hardware addresses is active at any time and there is no way for dnsmasq to enforce this. It is, for instance, useful to allocate a stable IP address to a laptop which has both wired and wireless interfaces.

I opted for the multi-mac solution (because I didn't try to find out how I could specify the client id on the client side, which is something that has to be done for each separate client, and the multi-mac alternative is one solution for all the portables in the house.)

I circumvented the luci interface, and added directly to /etc/dnsmasq.conf the following line:

dhcp-hostsfile=/etc/dnsmasq-dhcphosts.conf

and /etc/dnsmasq-dhcphosts.conf contains lines of the following format:

mac1,mac2,ip

(I keep this config in a seperate file to prevent to have it overwritten by the next update.)

Works fine.

share|improve this answer

Your Answer

 
discard

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.