1

I am trying to change my MAC address every time I reboot the system. So I wrote a script and it is attached bellow.

#!/bin/bash -x  
echo "Date $(date)"  
systemctl stop NetworkManager.service  
ip addr  
macchanger -r wlx9cefd5fe0d41  
systemctl start NetworkManager.service

When I run the script in the terminal it's successfully changeing the MAC address but when I use crontab to do it I get the following error:

[ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy.

I am running the crontab as a root and by logs which I attached shows that the interface is down. Can some one help me? If there is a better way I am open for it.

This is my crontab line:

@reboot bash -x /home/user/changeMac.sh >> /home/user/testlog.txt 2>&1

The log file:

++ date
+ echo 'Date Wed Aug 22 21:27:32 PDT 2018'
Date Wed Aug 22 21:27:32 PDT 2018
+ systemctl stop NetworkManager.service
+ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  inet 127.0.0.1/8 scope host lo
  valid_lft forever preferred_lft forever
  inet6 ::1/128 scope host 
  valid_lft forever preferred_lft forever
2: enp0s25: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
  link/ether  brd ff:ff:ff:ff:ff:ff
3: wlx9cefd5fe0d41: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
  link/ether  brd ff:ff:ff:ff:ff:ff
+ macchanger -r wlx9cefd5fe0d41
[ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy
Current MAC:    (unknown)
Permanent MAC:  (unknown)
+ systemctl start NetworkManager.service
1

The log doesn’t say that the interface is down, it complains it’s up! In order to bring it down properly, add

ip link set wlx9cefd5fe0d41 down

to your script before the macchanger line. To bring it up again afterwards, use the equivalent:

ip link set wlx9cefd5fe0d41 up

As you probably figured, for manipulating network devices ip should be used. NetworkManager is just a daemon managing the networking configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.