Digital Mages

Digital Mages - virtmac(1)

VIRTMAC

Section: User Contributed Perl Documentation (1)
Updated: 2019-04-21
Index  

NAME

virtmac - Virtual MAC address generator  

VERSION

$Id: bin/virtmac, 0.2 2019/04/21 20:47:51 acorliss Exp $  

USAGE

  virtmac {IP Address} [{IP Address} ...]

 

DESCRIPTION

The program generates virtual MAC addresses for use with virtual machines, bonded interfaces, etc. The intent is to generate a MAC that will be reliably unique within any given broadcast domain.

The MAC address is generated using the following technique:

  1) Convert the IP address into hex for use as the lower four bytes
  2) Use the current time for the first two bytes:

     |4 bits|6 bits  |6 bits  |
       HH       MM      SS

  3) Set the local administration bit (2nd least-significant bit 
     of the first byte) to '1'
  4) Set the unicast bit to '0' (least-significant bit of the 
     first byte)

The uniqueness and non-repeatability of this MAC is based on the following rationale: the IP address of any given machine must be unique within any given broadcast domain, so using it as the basis of a MAC address seems to be a logical extension. Setting the local administration bit also guarantees that there will be no conflicts between the virtual MAC and any officially registered hardware manufacturer OIDs.

I've also tried to anticipate the likelihood that a machine might be readdressed after deployment, and a new machine with a virtual MAC being deployed on the old IP address. I've introduced two ``random'' elements into the full MAC address. The first is by using the MAC generation time stamp (12hr hours, minutes, and seconds). Unless you're generating a virtual MAC for the same IP at the exact same second of the given hour the addresses will remain unique on the network. The second random element is replacing the first octet of the network address with a random number.

While none of this is a guarantee that the MAC address will be globally unique, it should be sufficient for 99% of your use-case scenarios. In essence you have three bytes of ``randomness'' (well, 23 bits, anyway) attached to a locally unique IP address.  

REQUIRED ARGUMENTS

One or more IP addresses.  

OPTIONS

None.  

DIAGNOSTICS

None.  

EXIT STATUS

Returns a 1 if there are any errors (like missing or invalid IP addresses). Otherwise, it returns a 0.  

CONFIGURATION

None.  

BUGS AND LIMITATIONS

All caveats mentioned in the description.  

AUTHOR

Arthur Corliss (corliss@digitalmages.com)  

LICENSE AND COPYRIGHT

This software is licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information.

(c) 2009, Arthur Corliss (corliss@digitalmages.com)


 

Index

NAME
VERSION
USAGE
DESCRIPTION
REQUIRED ARGUMENTS
OPTIONS
DIAGNOSTICS
EXIT STATUS
CONFIGURATION
BUGS AND LIMITATIONS
AUTHOR
LICENSE AND COPYRIGHT