0

I would like to either figure out how to automatically change my MAC on a set timer through scripting, or just how to change the MAC at all through shell. This router is a Netgear WNDR3700v4, so it's using an Atheros chip.

I have no knowledge of Linux but I have done it through Windows via command prompt but that's pretty much it.

I did some Google searches to see if anyone has tried to change the MAC address through SSH and didn't quite see anything that made me feel confident enough to venture about without the worry of bricking my router.

Giacomo1968
  • 58,727

1 Answers1

0

Your question divides into two parts: How to change a MAC address, and how to time a certain process.

Change MAC address

Given you cannot install nice utilities like macchanger, you will have to do this manually.

  1. Find out your network interface name. In many cases this is eth0. Be sure to find the name of the interface you really want to change (WAN or LAN, VLAN...). In this example, I'll use eth0

  2. Check your current MAC address ip link show eth0. It may show something like link/ether 00:11:22:33:44:55

  3. Take down your interface: ip link set dev eth0 down. This is a large disadvantage of this solution because it tears down the whole network during the process. Be sure you really want this to happen.

  4. Set a new MAC address: ip link set dev eth0 address AA:BB:CC:DD:EE:FF

  5. Take your interface up again: ip link set dev eth0 up

Make a script of it

In a script, this might look like this:

#!/bin/bash
IF=eth0

# Create a Random MAC, inspired by http://superuser.com/a/218372/475723
# MAC might not be valid since it's completely random. Use the linked answer to add a prefix like 00:60:2F
hexchars="0123456789ABCDEF"
MAC=$(for i in {1..12} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/\1:/g;s/:$//')

ip link set dev $IF down
ip link set dev $IF address $MAC
ip link set dev $IF up

Save this script to a fitting location (let's assume /root/mac.sh) and make it executable by chmod +x /root/mac.sh.

You can test your script by executing /root/mac.sh.

Time running processes by cron

With cron you can make processes run on a regular basis, for example once a day.

  1. Edit your cron file by crontab -e

  2. Insert a line giving the necessary information: When and what. For example 0 1 * * * /root/mac.sh. This would execute the command every day, month, year at 01:00. Please check the cron help pages for information on how to set it to different intervals.

Please be sure to edit the crontab file as root.

mxmehl
  • 138