# Same IP, multiple interfaces using dhcpcd, systemd

## mieses

Is it possible to configure dhcpcd to accept the same IP address on multiple interfaces?  For example, consider a laptop where only one interface is enabled at a time with the wired interface having priority over the wireless interface.  An OpenWRT router is running dnsmasq and is configured to assign the same IP address to all MAC addresses belonging to this laptop.

OS X, Ubuntu and Windows are able assign the same IP address to multiple interfaces and seem to do this by default.  What is the intended behavior in Gentoo for this case when running dhcpcd, NetworkManager, and systemd?

When the Wi-Fi interface comes up on Gentoo, dnsmasq tries to assign the same IP and dhcpcd rejects the lease noting that the wired interface on the same laptop has already claimed it.  journalctl reports the following:

```
Oct 08 14:55:48 testgentoo dhcpcd[14263]: version 6.4.7 starting

Oct 08 14:55:48 testgentoo NetworkManager[14137]: <info> (wlp3s0): DHCPv4 state changed nbi -> preinit

...

Oct 08 14:55:48 testgentoo dhcpcd[14263]: wlp3s0: soliciting a DHCP lease

Oct 08 14:55:48 testgentoo dhcpcd[14263]: wlp3s0: offered 192.168.0.235 from 192.168.0.10

Oct 08 14:55:48 testgentoo dhcpcd[14263]: wlp3s0: hardware address c8:2a:14:29:b9:2d claims 192.168.0.235

Oct 08 14:55:51 testgentoo dhcpcd[14263]: wlp3s0: soliciting a DHCP lease

Oct 08 14:55:53 testgentoo dhcpcd[14263]: wlp3s0: offered 192.168.0.106 from 192.168.0.10

Oct 08 14:55:58 testgentoo dhcpcd[14263]: wlp3s0: leased 192.168.0.106 for 43200 seconds

Oct 08 14:55:58 testgentoo dhcpcd[14263]: wlp3s0: adding route to 192.168.0.0/24
```

If dhcpcd would allow the same IP (192.168.0.235) to be assigned to both interfaces simultaneously, then dnsmasq would be able to assign the same name to both the wired and wireless interfaces of the same machine.

For comparison, here are the router logs when the Wi-Fi interface is disabled and enabled on this Gentoo machine and OS X.

router log events upon disabling WiFi interface in OS X client.

```
Oct  8 22:12:06 router daemon.info hostapd: wlan1: STA 8c:2d:aa:31:ac:99 IEEE 802.11: disassociated

Oct  8 22:12:07 router daemon.info hostapd: wlan1: STA 8c:2d:aa:31:ac:99 IEEE 802.11: deauthenticated due to inactivity (timer DEAUTH/REMOVE)
```

router log events upon enabling WiFi interface in OS X client.

```
Oct  8 22:20:37 router daemon.info hostapd: wlan1: STA 8c:2d:aa:31:ac:99 IEEE 802.11: authenticated

Oct  8 22:20:37 router daemon.info hostapd: wlan1: STA 8c:2d:aa:31:ac:99 IEEE 802.11: associated (aid 1)

Oct  8 22:20:37 router daemon.info hostapd: wlan1: STA 8c:2d:aa:31:ac:99 WPA: pairwise key handshake completed (RSN)

Oct  8 22:20:38 router daemon.info dnsmasq-dhcp[26283]: DHCPREQUEST(br-lan) 192.168.0.14 8c:2d:aa:31:ac:99

Oct  8 22:20:38 router daemon.info dnsmasq-dhcp[26283]: abandoning lease to a8:20:66:51:ff:45 of 192.168.0.14

Oct  8 22:20:38 router daemon.info dnsmasq-dhcp[26283]: DHCPACK(br-lan) 192.168.0.14 8c:2d:aa:31:ac:99 testmac
```

router log events upon enabling WiFi interface in Gentoo client.

```
Oct  8 22:14:33 router daemon.info hostapd: wlan1: STA e4:ce:8f:56:1c:2a IEEE 802.11: authenticated

Oct  8 22:14:33 router daemon.info hostapd: wlan1: STA e4:ce:8f:56:1c:2a IEEE 802.11: associated (aid 1)

Oct  8 22:14:33 router daemon.info hostapd: wlan1: STA e4:ce:8f:56:1c:2a WPA: pairwise key handshake completed (RSN)

Oct  8 22:14:34 router daemon.info dnsmasq-dhcp[26283]: DHCPREQUEST(br-lan) 192.168.0.106 e4:ce:8f:56:1c:2a

Oct  8 22:14:34 router daemon.info dnsmasq-dhcp[26283]: DHCPNAK(br-lan) 192.168.0.106 e4:ce:8f:56:1c:2a static lease available

Oct  8 22:14:34 router daemon.info dnsmasq-dhcp[26283]: DHCPDISCOVER(br-lan) e4:ce:8f:56:1c:2a

Oct  8 22:14:34 router daemon.info dnsmasq-dhcp[26283]: DHCPOFFER(br-lan) 192.168.0.235 e4:ce:8f:56:1c:2a

Oct  8 22:14:34 router daemon.info dnsmasq-dhcp[26283]: DHCPREQUEST(br-lan) 192.168.0.235 e4:ce:8f:56:1c:2a

Oct  8 22:14:34 router daemon.info dnsmasq-dhcp[26283]: DHCPACK(br-lan) 192.168.0.235 e4:ce:8f:56:1c:2a testgentoo

Oct  8 22:14:34 router daemon.info dnsmasq-dhcp[26283]: DHCPDECLINE(br-lan) 192.168.0.235 e4:ce:8f:56:1c:2a Duplicate address detected

Oct  8 22:14:34 router daemon.warn dnsmasq-dhcp[26283]: disabling DHCP static address 192.168.0.235 for 10m

Oct  8 22:14:37 router daemon.warn dnsmasq-dhcp[26283]: not using configured address 192.168.0.235 because it was previously declined

Oct  8 22:14:40 router daemon.info dnsmasq-dhcp[26283]: DHCPDISCOVER(br-lan) e4:ce:8f:56:1c:2a

Oct  8 22:14:40 router daemon.info dnsmasq-dhcp[26283]: DHCPOFFER(br-lan) 192.168.0.106 e4:ce:8f:56:1c:2a

Oct  8 22:14:40 router daemon.info dnsmasq-dhcp[26283]: DHCPREQUEST(br-lan) 192.168.0.106 e4:ce:8f:56:1c:2a

Oct  8 22:14:40 router daemon.info dnsmasq-dhcp[26283]: DHCPACK(br-lan) 192.168.0.106 e4:ce:8f:56:1c:2a testgentoo
```

router log events upon disabling WiFi interface in Gentoo client.

```
(no events reported)
```

3 minutes later, router log events upon enabling WiFi interface in Gentoo client.

```
Oct  8 22:17:47 router daemon.info hostapd: wlan1: STA e4:ce:8f:56:1c:2a IEEE 802.11: authenticated

Oct  8 22:17:47 router daemon.info hostapd: wlan1: STA e4:ce:8f:56:1c:2a IEEE 802.11: associated (aid 1)

Oct  8 22:17:47 router daemon.info hostapd: wlan1: STA e4:ce:8f:56:1c:2a WPA: pairwise key handshake completed (RSN)

Oct  8 22:17:48 router daemon.info dnsmasq-dhcp[26283]: DHCPREQUEST(br-lan) 192.168.0.106 e4:ce:8f:56:1c:2a

Oct  8 22:17:48 router daemon.info dnsmasq-dhcp[26283]: DHCPACK(br-lan) 192.168.0.106 e4:ce:8f:56:1c:2a testgentoo
```

----------

## UberLord

Heh, you're like the 2nd person to ask for this in about 5 years!

It is on my personal radar to address, but please do file a ticket:

http://roy.marples.name/projects/dhcpcd

Login as anonymous and enter password as the ascii banner and create the ticket please!

It's actually not a small job ....

----------

## mieses

Thank you.  It's good to know that it's working as intended.  I will post an issue on your tracker.

Out of pure curiosity, how would the solution work?  How is the wireless interface de-prioritized when the wired interface is plugged in and receives the same IP as the wireless interface? Do both interfaces stay up and one is configured to route through the other?

----------

## UberLord

Oh that's easy. Here is the code

```
      ifp->metric = 200 + ifp->index;

      if (if_getssid(ifp) != -1) {

         ifp->wireless = 1;

         ifp->metric += 100;

      }
```

Index is a low number assigned by the kernel to each interface

This is also user editable in dhcpcd.conf

```
interface eth0

metric 111
```

Lowest metric is preferred.

----------

## UberLord

Internally, dhcpcd would remove the conflicting IP address from high metric interfaces and then assign it to low metric ones.

This does force ably break connections, but it already does this with routes, so IP addressing working the same way isn't much of a stretch.

----------

## UberLord

You didn't post a ticket  :Sad: 

But I've already made the change here:

http://roy.marples.name/projects/dhcpcd/ci/77611ce41704345c8037a465ef0af8d7a129d7cd?sbs=0

----------

## UberLord

Re-reading your post, it won't work for you because you're using network manager.

You'll need to disable ARP checking in dhcpcd.conf or tweak your kernel config as described here:

https://www.ibm.com/developerworks/community/blogs/tclaret/entry/linux_considers_an_ip_address_as_belonging_to_a_host_rather_than_an_interface?lang=en

----------

## UberLord

Holy thread necro batman!

Anyway, just a heads up that dhcpcd-6.5.1 upwards do this.

If you have say wired and wireless and both are active then the wired interface will have the IP address.

When unplugged, the IP address will move to the wireless interface.

----------

## steveL

 *UberLord wrote:*   

> If you have say wired and wireless and both are active then the wired interface will have the IP address.
> 
> When unplugged, the IP address will move to the wireless interface.

 

Lovely. :-)

----------

