Jump to content

armbian-install: can we set a custom or random macaddress ?


Dantes

Recommended Posts

 

I had a need to change the macaddress of this device, after looking through the bootloader I spotted 2 offsets:

  • 0x380400 macaddress NIC1
  • 0x380406 macaddress NIC2

 

I would love an option in the installer, but I did it manually now:

 

# dd if=/dev/mmcblk2 bs=16M count=1 of=bootloader
1+0 records in
1+0 records out
16777216 bytes (17 MB, 16 MiB) copied, 0,0736928 s, 228 MB/s

# read_mac bootloader 0x380400
9c:d5:dc:b2:ce:1c

# write_mac bootloader 0x380400 $(random_mac)
write_mac bootloader 0x380400 $(random_mac)

# read_mac bootloader 0x380400
b0:3f:1a:83:9a:da

 

After scripting a couple of functions of course: ;)

 

### Functions read_mac , write_mac and random_mac are hereby licensed under GPLv3

# read_mac file offset
# read_mac bootloader 0x380400
# read_mac /dev/mmcblk2 0x380400
read_mac(){ 
  dd if=$1 bs=1 count=6 skip=$(($2)) 2>/dev/null |\
    xxd -l 16 -p | sed 's/../:&/g;s/^://'
}

# write_mac file offset macaddress
# write_mac bootloader 0x380400 aa:bb:cc:dd:ee:ff
# write_mac /dev/mmcblk2 0x380400 aa:bb:cc:dd:ee:ff
write_mac(){
  for hex in $(echo $3|tr ':' ' ');do printf "\x$hex";done |\
    dd of=$file bs=1 count=6 seek=$(($offset)) conv=notrunc 2>/dev/null
}

# print a random macaddress
random_mac(){
  printf "%012x" \
    $(( 0x$(hexdump -n6 -ve '/1 "%02X"' /dev/urandom) & 0xFCFFFFFFFFFF )) |\
      sed 's/../:&/g;s/^://'
}

 

Edited by Dantes
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines