diff --git a/initrd/bin/network-init-recovery b/initrd/bin/network-init-recovery index 9ec88637..a0fdba2d 100755 --- a/initrd/bin/network-init-recovery +++ b/initrd/bin/network-init-recovery @@ -1,5 +1,7 @@ #!/bin/ash +. /etc/functions + # bring up the ethernet; maybe should do DHCP? ifconfig lo 127.0.0.1 @@ -11,6 +13,16 @@ for module in `echo $network_modules`; do done if [ -e /sys/class/net/eth0 ]; then + #Randomize eth0 MAC address of maximized boards + if echo "$CONFIG_BOARD" | grep -q maximized; then + ifconfig eth0 down + echo "Generating random MAC address (might take a while)..." + mac=$(generate_random_mac_address) + echo "Assigning randomly generated MAC: $mac to eth0..." + ifconfig eth0 hw ether $mac + ifconfig eth0 up + fi + # Set up static IP if [ ! -z "$CONFIG_BOOT_STATIC_IP" ]; then ifconfig eth0 $CONFIG_BOOT_STATIC_IP diff --git a/initrd/etc/functions b/initrd/etc/functions index 45f893b9..b134da9c 100755 --- a/initrd/etc/functions +++ b/initrd/etc/functions @@ -374,3 +374,9 @@ print_battery_charge() echo "$battery_charge" fi } + +generate_random_mac_address() +{ + #Borrowed from https://stackoverflow.com/questions/42660218/bash-generate-random-mac-address-unicast + hexdump -n 6 -ve '1/1 "%.2x "' /dev/urandom | awk -v a="2,6,a,e" -v r="$RANDOM" 'BEGIN{srand(r);}NR==1{split(a,b,",");r=int(rand()*4+1);printf "%s%s:%s:%s:%s:%s:%s\n",substr($1,0,1),b[r],$2,$3,$4,$5,$6}' +}