[Help] new MAC on bootup

Don´t be shy, Linux is fun! =)
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

[Help] new MAC on bootup

Post by ayu »

So I wanted to set my Raspberry PI with Raspbian (Debian based) to change the MAC at bootup.
The problem is that it works about 50% of the time only, which makes me think that it's either a race condition or that something else is wrong.

This is my script:

/etc/init.d/startup

Code: Select all

#!/bin/sh

### BEGIN INIT INFO
# Provides:          macchanger
# Required-Start:    $network $syslog
# Required-Stop:     $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Changes the MAC address at boot time.
# Description:       Changes the ethernet and wireless cards MAC addresses
#                    that begins with a real manufacturers MAC (the first 3
#                    segments) and randomize the next 3 segments.
### END INIT INFO


# Disable the network devices
#ifconfig eth0 down
ifconfig wlan0 down

echo "Changing MAC address" >&2
# Spoof the mac addresses
#/usr/bin/macchanger -r eth0
/usr/bin/macchanger -r wlan0

# Re-enable the devices
#ifconfig eth0 up
ifconfig wlan0 up

start() {
  echo 'Service started' >&2
}

stop() {
    echo 'Service not running' >&2
}

uninstall() {
  echo "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  uninstall)
    uninstall
    ;;
  retart)
    stop
    start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|uninstall}"
esac


exit 0
I then run:
update-rc.d startup defaults 100 5
to have it run with low priorities and only in run level 5 (that's how interpret the man page of update-rc.d).
Like I mentioned above, the script runs. But the MAC only changes about half of the time.

Any advice on how to get this working?
I've been stuck with this now for a few days.

Another thing I tried was to set it via rc.local and have it run when the user logged in, but that seems to have similar results.
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: [Help] new MAC on bootup

Post by bad_brain »

anything to find in syslog? my suspicion is that some startups interfere with each other... :-k
best disable the startup (rcconf is a very nifty little tool for that btw) of the script, reboot and then start it manually. if it works every time that way you know it must be the init order during boot.

and yes, the order during boot is not always the same, I had such an issue with a vpn client auto start which sometimes worked and sometime did not because the NIC started after the client for some odd reason then).

but yeah, syslog first.
Image

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: [Help] new MAC on bootup

Post by ayu »

Yeah most likely some kind of race condition indeed.
I've gone through the syslog with little to no result.

At the moment the script seems to work (upgraded to a faster Raspberry PI (V2)).
So I'll just stick with this for now.

Another change was that I took the contents of my two scripts that is setting up my device, and put all of it in the rc.local file in the right order.
That seems to have had a very positive effect on things.
"The best place to hide a tree, is in a forest"

Post Reply