2

Brief:

Is there an accepted way to request two IP addresses and reserve them for use by one machine?

I don't believe that I am allowed to get two IPs from a DHCP server with one interface and one MAC address (correct me if I am wrong).

If I choose a static IP, I can't stop the IP being allocated to someone else (correct me if I am wrong).

Details:

I would like multiple IP addresses. Is there some polite way I can request them without risking their being allocated to other people? I could forge a DHCP DORA handshake, but that doesn't seem like the right thing to do. Aside from the issue generating a MAC address, it doesn't seem like there should be a need to provide a MAC address; I only need the DHCP sever to NOT lease out an IP, it doesn't need to manage the IP and manage any associated MAC addresses. I'm happy to manage renewals, NACK and any other nuances.

I could randomly pick static IPs and potentially interfere with some other network user. Static virtual interfaces like this or this or this will work for the purposes of attaining multiple IPs, but DHCP won't be in control of issuing them. I cannot guarantee that they will be free.

I don't believe that virtual DHCP interfaces will work, as DHCP allocations require unique MAC addresses.

You may assume that I am on a work network. I am allowed to connect an arbitrary number of different devices to the network (and hence get any number of IPs allocated with the full consent of the company). However, I only require two, but I only have one network interface (a Raspberry Pi). I understand that I have phrased this as a general networking problem; I only seek to find a solution relevant to the latest Rasberry Pi build (buster).

1 Answers1

3

create a file in /etc/network/interfaces.d - lets call it eth0 - doesn't matter what the name is.

In this file add the following

auto eth0
iface eth0 inet manual
  up ip link add link eth0 name eth01 address 02:00:00:00:00:01 type macvlan
  up ip link add link eth0 name eth02 address 02:00:00:00:00:02 type macvlan

Now restart networking

sudo systemctl restart networking

or just reboot

et voila

The value of the mac addresses can be virtually anything, as long as the first 'digit' is either a 2, 6, A or E.

You can name the interfaces anything you like too.

guntbert
  • 115
  • 5
Jaromanda X
  • 2,079
  • 1
  • 11
  • 14
  • 1
    I type "systemctl restart networking" followed by ifconfig and can now see eth01 and eth02 listed in the interface list. After a short wait they now have IPs associated. – Insert name here Feb 05 '21 at 09:32
  • Oh, yeah, I forgot to mention you need to restart networking (or reboot) – Jaromanda X Feb 05 '21 at 09:46
  • Just tested and it also works for wlan0 (same steps but replace "eth" with "wlan"). Can you recommend a good textbook (or such) that I can gain an understanding about how this works? – Insert name here Feb 05 '21 at 09:52
  • @Insertnamehere - textbook? not really - I just happened to answer a similar question recently, and this is basically the same issue - except the other question wanted static IP's so the `ip add` command was a bit different - my textbook is using google :p – Jaromanda X Feb 05 '21 at 10:03
  • to be honest, I'm surprised "the usual crew" haven't blasted me for daring to suggest you *mess around* in the Forbidden Zone of `/etc/network`!! :p – Jaromanda X Feb 05 '21 at 10:06
  • Is that because the preferred way is to have /etc/dhcpcd.conf handle all that stuff? – Insert name here Feb 05 '21 at 10:09
  • Also, are there legal / ethical considerations with assigning MAC addresses that you do not own? – Insert name here Feb 05 '21 at 10:10
  • I haven't figured out HOW to get this functionality to actually work using dhcpcd - creating "new" interfaces has nothing to do with DHCP, so, really, why would dhcpcd work ... – Jaromanda X Feb 05 '21 at 10:11
  • 2
    MAC addresses with 2,6,A,E in the second position are reserved for such use - see **Local MAC ranges** at https://en.wikipedia.org/wiki/MAC_address#Universal_vs._local_(U/L_bit) – Jaromanda X Feb 05 '21 at 10:11
  • technically, if you want to have more control over networking, you'd switch from using `networking` to `systemd-networkd` - but if you know how to do that, then you wouldn't need to ask your question @Insertnamehere – Jaromanda X Feb 05 '21 at 10:24
  • 1
    [Textbooks?... we don't need no stinkin' textbooks](https://www.youtube.com/watch?v=VqomZQMZQCQ) – Seamus Feb 05 '21 at 15:21
  • `I'm surprised "the usual crew" haven't blasted me for daring to suggest you mess around in the Forbidden Zone of /etc/network`... it was put to a vote, and we decided to cut you some slack. :-0 You know we only do it to help you - right? LOL – Seamus Feb 05 '21 at 21:14
  • @Seamus, I'd be seriously interested if there were a way to do this (and VLANs for that matter) without touching `/etc/network` or switching to `systemd-networkd` – Jaromanda X Feb 06 '21 at 00:51
  • Your best bet would be to get @Ingo involved as he is the `systemd-networkd` guru-extraordinaire :) He may have already posted something. Personally, I try to do everything in `/etc/dhcpcd.conf` as it's currently the *default* - but then networking is not really my thing. – Seamus Feb 06 '21 at 01:06
  • @Seamus - I did mention in a comment that `systemd-networkd` would be the better/proper way to configure such *exotic* networking - as far as I can tell `ifupdown` + `dhcpcd5` is fine for *let's just get a network happening and be done with it* type setups - i.e. the majority of raspberry pi uses – Jaromanda X Feb 06 '21 at 02:03
  • as far as a systemd-networkd config goes ... I guess https://raspberrypi.stackexchange.com/questions/108592/use-systemd-networkd-for-general-networking would be the answer – Jaromanda X Feb 06 '21 at 02:06
  • I've not tried it, but it certainly seems to be thorough. He's [the man](https://en.wikipedia.org/wiki/The_Man) for networking! – Seamus Feb 06 '21 at 04:10
  • Correction: Substituting eth0 for wlan0 will result in new IPs being assigned, but these will not be accessible from the wider network. [See here.](https://raspberrypi.stackexchange.com/questions/120978/need-two-ips-using-wlan0-interface-but-do-not-have-any-control-over-static-all/120996) – Insert name here Feb 07 '21 at 22:49