Random Hostname and Mac Address AR300M

I have seen this question asked here several times with an answer of it can be scripted.

Can anyone asist in helping the community get this created as its been asked for a number of years.

This is what this device is really perfect for but yet it doesn’t exist yet in an easy to use form.

I don’t have the complete skill set to make it happen. Anybody willing to help out?

Yes you can use Mac Clone in UI. However that requires you to know a valid mac and also do it before connecting so that every free wifi you use won’t have your real mac evertime. It about having some anonimity with this device and having it do it automatically. You just boot up and connect to whatever wifi you wan and everything is already done for you in background automatically.

Having a script may bring some issues. For example, how can the script knows when it should generate a new MAC address? Yes this should be AI.

So maybe you can just change the MAC address in the UI. You can generate valid MAC online.

There is a package in openwrt to generate random MAC.

check this: GitHub - janost/openwrt-wan-mac: WAN MAC address randomizer for OpenWRT/LEDE

It should generate a new MAC Address on every new boot of the device. It should also have the option to do so via the web interface(or command line for advanced users via the script). A script would allow the user to decide when and how they want to utilize it. So if they want to schedule a cron job or if they want to manual run it or if they just want to set it on boot. Like on a pc you just have a script that changes hostname and mac address if you wish to do so(just load a dictionary file that it can pull random names from).

Is this possible to just build in so that people can’t screw up the device or can we work to create the scripts in this thread together so that people can use that may want it in the future.

It appears that this really needs done as an example the conference I am at the knocked down hotspots. This now doesn’t allow me to connect with the device as the MAC address has been blocked from making connection so I can’t even use it as a repeart with the LAN side connected because it keeps getting dropped everytime it connects.

I just copied from the openwrt-wan-mac script
Originally it is used to change wan mac. I modified it to change wifi repeater mac. Does it work for you?

#!/bin/sh /etc/rc.common                             

START=17                                             

start() {                                            
  OLDMAC=$(uci get wireless.sta.macaddr)              
  logger "[WAN-MAC] Old WAN MAC address is ${OLDMAC}."                                                    
  NEWMAC=$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/')                                                                            
  logger "[WAN-MAC] Applying new random MAC address to WAN (${NEWMAC})..."                                
  uci set wireless.sta.macaddr=${NEWMAC}       
  uci commit network                                 
}
2 Likes

Let me try can we also add hostname. We can create a dictionary file to store on the device to create the random names.

Did not work.

./wwan-change-mac start
uci: Entry not found

I also tried running running uci from command line.
uci get network.wan.macaddr
uci: Entry not found

How do I also look at that current wireless mac address so when it does work I can be sure it changed. I don’t think this script is quite there yet.

I changed a little.

uci: Entry not found
is a message that telling you that the old MAC is not found. If you didn’t have a MAC before it will show this.

As long as a new mac is generate it is fine.

Works like a charm. Thanks man. Now how do we change hostname?

I don’t see hostname in the normal spot of /etc/hostname and it doesn’t return anything when i do hostname command.

BTW…Here are results:

root@GL-AR300M:/scripts# uci get wireless.sta.macaddr
46:0f:56:fe:9a:15
root@GL-AR300M:/scripts# ./wwan-change-mac restart
root@GL-AR300M:/scripts# uci get wireless.sta.macaddr
db:fc:b7:00:f9:1e

hostname is in /etc/config/system

Awesome can you assit with completing how to change it to something random?

Here is a randomizer for Linux Mint. Are there similar services on the router that would needs scripts restarted?

I think this is the correct code for random name.

new=$(tr -dc 'A-Z0-9' < /dev/urandom | head -c12)

So how do we insert into the system config file and is there any service that need restarted?

I may made it wrong. Seems you want to change your hostname what is exposed to the network. Please try the following script.

newhost=$(tr -dc 'A-Z0-9' < /dev/urandom | head -c12)
uci set network.wwan.hostname=$newhost
uci commit network

This needs to take effect when restart network or reboot.

/etc/init.d/network restart

I’ve been looking for pretty much the same thing as the OP and am happy that a thread for this exists. Please allow me to revive this discussion.

I can’t write script myself and was wondering if and how the mac-changer-script could be modified so that a prefered vendor prefix (first 6 digits) could be set in the script and only the last 6 digits would be randomized.

My plan is to have the mac addresses for WAN, LAN, WIFI, as well as the hostname randomized at boot. Would it make sense to have 4 seperate scripts or a single script to achieve all 4?

You should just use one scripts

For example, if you want to have 00:11:22 as the prefix you can generate mac like

echo 00:11:22:$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\
)\(..\)\(..\)\(..\).*$/\1:\2:\3'/)
1 Like
#!/bin/sh /etc/rc.common                             

START=17                                             

start() {                                            
  OLDMAC=$(uci get wireless.sta.macaddr)              
  logger "[WIFI-MAC] Old WIFI MAC address is ${OLDMAC}."                                                    
  NEWMAC=echo 00:11:22:$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3'/)                                                                        
  logger "[WIFI-MAC] Applying new random MAC address to WIFI (${NEWMAC})..."                                
  uci set wireless.sta.macaddr=${NEWMAC}       
  uci commit network                                 
}

I added the snippet to the existing script from earlier in this thread. Is this correct?

Can you help me to combine all 4 (Wireless,Ethernet,WAN & Host) into a single script?

#!/bin/sh /etc/rc.common                             

START=17                                             

start() {                                            
  OLDMAC=$(uci get wireless.sta.macaddr)              
  logger "[WIFI-MAC] Old WIFI MAC address is ${OLDMAC}."                                                    
  NEWMAC=$(echo 00:11:22:$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3'/))
  logger "[WIFI-MAC] Applying new random MAC address to WIFI (${NEWMAC})..."                                
  uci set wireless.sta.macaddr=${NEWMAC}       
  uci commit network                                 
}
2 Likes

It is better that you can do it by yourself. It takes a lot of time to try and test each changes. I am afraid that I do not have time for that.

2 Likes

I understand, I don’t want to steal your time.

Just wondering if you meant one script for all tasks or for each task its own script.