3

Ref:
How is uniqueness of MAC addresses enforced?

Background:

  • I have a single computer, using a single motherboard, that has a single Ethernet port.
  • I have three different operating systems installed on that system, each doing a different task.
    • One is a flight simulator that makes use of streaming scenery that loads in nearly real-time as you fly.
    • Another is a generalized "gaming" system that plays games like Aion or Genshin Impact.
    • The third one is a generic Linux, (Mint), installation that I use for coding or administrative tasks.
  • My router identifies a particular computer by its MAC address, not the operating system running when it connects to the internet.
  • My router allows me, (requires me), to choose a "priority" for each connection which ranges from "near real-time" (VoIP, etc.), all the way down to "(yawn) I'll get to it eventually".
    • My flight simulator requires internet access to be quite prompt and is very allergic to being preempted by other tasks.
    • The other games want reasonably prompt internet access, but they're not as picky as my flight simulator.
    • The Linux installation doesn't really need any priority to speak of, aside from not taking forever.

I want to create separate priority levels based on the system running, but in order to do this the three systems have to have "unique" MAC addresses, at least within themselves.

I can create "unique" MAC addresses the way I create unique disk UUID's if there's a collision: I modify the last couple of digits.

Question:
If I do this, (change the last two digits by either swapping them or adding 1 to them, etc.), how do I guarantee uniqueness - or does it even matter if there's another system out there in Television Land somewhere that happens to have the same MAC address?

1 Answers1

9

I can create "unique" MAC addresses the way I create unique disk UUID's if there's a collision: I modify the last couple of digits.

Just generate a new UUID with uuidgen. It's free.

If I do this, (change the last two digits by either swapping them or adding 1 to them, etc.),

Generate a new one. There's a specific bit of the MAC address that indicates "locally generated" (as opposed to "manufacturer OUI"), while the other 46 bits can be random. This is what your phone does for its Wi-Fi MAC address when connecting to unknown networks.

So take 6 random bytes, write them in hex, change the 2nd digit to one of 2/6/a/e, and you have a valid "locally generated" MAC address with a very high chance of it being globally unique.

#!/usr/bin/env perl
my @bytes = map {int rand 256} 1..6;
$bytes[0] &= ~1; # clear "unicast/group" bit to indicate unicast
$bytes[0] |= 2;  # set "global/local" bit to indicate local (private)
print join(":", map {sprintf "%02X", $_} @bytes), "\n";

Though even just the last step (changing the 2nd digit to 2/6/a/e) will already be enough to separate the address from any manufacturer-issued addresses (which have 0/4/8/c instead).

Alternatively: You can buy a very cheap USB Ethernet or Wi-Fi adapter, or a used PCI(e) Ethernet card, then note down its MAC address and throw the adapter into the old cable box, never using it again. Now you have a unique MAC address for your own use. (Any other non-functional Ethernet/Wi-Fi device would also work.)

how do I guarantee uniqueness - or does it even matter if there's another system out there in Television Land somewhere that happens to have the same MAC address?

For their primary purpose, MAC addresses (Ethernet network addresses) only need to be unique within the network they're used in, so in this case within the boundary of your Ethernet LAN (the Wi-Fi counts as an extension of the Ethernet LAN). There's no uniqueness requirement between disjoint networks.

The new "unique" MAC address you got by editing a manufacturer-issued one will absolutely not be unique worldwide – 98% chance it belongs to the Ethernet port of another motherboard from the same batch, possibly owned by someone in the same general area – but it doesn't matter as long as they never talk to each other directly (i.e. on the same Ethernet LAN).1

Generating a fully random MAC address is still a better idea, though.

Though beware that MAC addresses can also be used for secondary purposes, e.g. commercial software licensing. (For example, AutoCAD's "network" licensing requires us to provide the license server's MAC address.) Sometimes online game bans are based on the MAC address.


1 (Some systems deliberately use non-unique MAC addresses, e.g. VRRP allows enterprise routers to share an IP address – which becomes tied to a fixed, algorithmically-generated MAC address.)

grawity
  • 501,077