cubieplayer / Cubian

Debian for Cubieboard
http://cubian.org
271 stars 49 forks source link

Cb1 vs Cb2 MAC address #441

Closed Bug-Spray closed 9 years ago

Bug-Spray commented 9 years ago

I'm having trouble finding authoritative data on setting a fixed MAC address between the two versions of Cubieboard/Cubian (and I see there's a problem with the script.bin supplied with each image).

Can anyone help to clear this up for me - which method works with which Cubieboard version (for the Cubian X1 distro)?

My company uses several of these units for development, and it is quite problematic to have several devices on the network with the same MAC address.

Thanks and regards.

vovcacik commented 9 years ago

Hi, this is easy to fix in Cubian X1:

sudo apt-get install cubian-update
sudo cubian-update
sudo shutdown -r now

After the reboot it will generate new MAC address and store it permanently, you can't however choose your own custom MAC.

Bug-Spray commented 9 years ago

Hello vovcacik,

Very helpful - thank you for responding to me. I did run cubian-update initially, but rolled it back because it patched over my custom kernel. I think I can run it --skip-kernel --skip-modules to ensure I keep the custom built kernel, right? (I built it custom just because we need 1-wire support at this stage...)

Best regards,

Bug-Spray commented 9 years ago

Is there anyway to force regeneration of a new address? After taking a disk image of a 'completed setup', I am still in the situation with multiple devices reporting the same MAC.

estevesd commented 9 years ago

if the mac address is not specified in /boot/script.bin :

sudo rm /root/.cubian-emac
sudo reboot

if the mac address is specified in /boot/script.bin (not tested the "sed" part, be careful) :

sudo su
cp /root/script.bin /root/script.old
/usr/bin/bin2fex /boot/script.bin /boot/script.fex
randemac="c0b0$(openssl rand -hex 4 | sed 's/\(..\)/\1/g; s/.$//')"
sed -i "MAC.*=.*/MAC = \"$randemac\"/" /root/script.fex
/usr/bin/fex2bin /boot/script.fex /boot/script.bin
reboot
Bug-Spray commented 9 years ago

Thank you - OK, this works.

One thing which I discovered doing this: Once the MAC changes, udev will "rediscover" the device as a new interface, which means that any the interface definitions are no longer valid.

In our case, it meant that whenever I recompiled script.bin with the changes, the eth0 interface wouldn't come up after reboot. (And I was unable to SSH into the unit anymore, leading me to think it wasn't booting properly!)

That was a 'gotcha', but can be solved by deleting /etc/udev/rules.d/70-persistent-net.rules before restarting; or at least, the portion of this file that relates to the old MAC.