-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom-mac.sh
executable file
·34 lines (27 loc) · 1.02 KB
/
random-mac.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
#
# Description:
# This script generates and sets a pseudo-random mac address on interface eth0.
# This script is created because the Raspberry Pi doesn't accept mac addresses
# from the macchanger package.
# It is not completely random because it won't set broadcast, multicast
# or 'locally administered' mac addresses. This is done by setting the
# second hexadecimal character in the mac address to zero.
#
# This script is used in combination with the /etc/network/interfaces file.
#
# TODO:
# - Get macchanger package to work
#
# Bash options
set -o errexit # exit script when a command fails
set -o nounset # exit script when a variable is not set
# Variables
export RANDFILE=/etc/onion-node/.rnd
readonly MAC_NEW=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//; s/[a-f0-9]/0/2')
# Set new mac address
ifconfig eth0 down hw ether "${MAC_NEW}"
# Sleep 10 seconds to fix occasional ifdown/ifup "RTNETLINK answers: Network is
# unreachable" error.
# In tests 1 second was enough, but use a margin of safety
sleep 10