44

My router can do port-forwarding based on MAC addresses. That is, a specific MAC will get a specific IP, for which I can configure a set of ports to be forwarded. In order to easily change that set of ports, I'd like to have different connections in the Network manager.

How do I change the MAC address for a network connection?

Jorge Castro
  • 71,754

6 Answers6

44

First, go to the networking indicator and select "Edit connection" to configure a new connection:

enter image description here

Click 'add' and choose a name for the spoofed MAC network connection.

enter image description here

After selecting your interface "eth0" in the top dropdown, you can simply choose any MAC address you like:

enter image description here

And after connecting to it, you'll be using your new MAC address.

enter image description here

Running ip link ls will show you the new interface, including it's spoofed MAC:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff

And now you can easily switch MAC-addresses by connecting to one of the new connections.

  • 3
    Is it possible to automate and randomize the Mac address for every new connection or login? I would post this as a new question, but I assume it would get marked as a duplicate of your question. – king_julien Aug 06 '13 at 08:25
  • 4
    Yes, there is a thing called macchanger - but I've never tried it. – Stefano Palazzo Aug 06 '13 at 11:51
  • In gnome shell, I don't get the option to set up another interface on eth0. Could you describe what's going on behind the scenes, and how to achieve it via a terminal? thx – drevicko May 07 '14 at 03:09
  • in Ubuntu 14.04, with a wifi network, this doesn't seem to work, NetworkManager simply refuses to connect to the wifi network that I choose to modify the MAC on (via Cloned MAC address textbox) :( – knocte Apr 12 '16 at 13:25
  • 2
    This doesn't work in Ubuntu 16.04 unfortunately. – onknows Mar 04 '17 at 12:33
  • Problem is you have to connect to the network at least once with your real MAC to be able to spoof it this way (real MAC is in router's logs now). – Xaqron Feb 08 '20 at 16:04
12

You can also change mac address on ubuntu or linux mint via the terminal

Go to your ubuntu or linux mint terminal, edit /etc/network/interfaces file

$ sudo nano /etc/network/interfaces

You should see something like this with dhcp enabled for your network interface. Usually its eth0 for ubuntu or linux mint wired network and wlan0 for ubuntu or linux mint wireless network.

auto eth0
iface eth0 inet dhcp

At the end of /etc/network/interfaces file, add this line to give your system’s network interface new MAC address.

hwaddress ether A4-19-E2-94-DD-BB

Save /etc/network/interfaces file with the new config, then restart your system network.

$ sudo /etc/init.d/networking restart

or

$ sudo service networking restart
Ollie
  • 2,932
  • this doesn't work in Ubuntu 14.04, sudo /etc/init.d/networking restart gives stop: Job failed while stopping, and even if you restart the network with NetworkManager, ip link ls doesn't reveal the new MAC being in use (testing with wifi wlan0 instead of eth0 though) – knocte Apr 12 '16 at 13:21
  • Try sudo service network-manager restart – ArcaneDominion Apr 28 '17 at 09:10
10

You could try macchanger available in the repositories. Install with sudo apt-get install macchanger or through Ubuntu Software center.

$ macchanger
GNU MAC Changer
Usage: macchanger [options] device

Try `macchanger --help' for more options.
tvbox@tvbox-G31M-ES2L:~$ macchanger --help
GNU MAC Changer
Usage: macchanger [options] device

  -h,  --help                   Print this help
  -V,  --version                Print version and exit
  -s,  --show                   Print the MAC address and exit
  -e,  --ending                 Don't change the vendor bytes
  -a,  --another                Set random vendor MAC of the same kind
  -A                            Set random vendor MAC of any kind
  -p,  --permanent              Reset to original, permanent hardware MAC
  -r,  --random                 Set fully random MAC
  -l,  --list[=keyword]         Print known vendors
  -b,  --bia                    Pretend to be a burned-in-address
  -m,  --mac=XX:XX:XX:XX:XX:XX
       --mac XX:XX:XX:XX:XX:XX  Set the MAC XX:XX:XX:XX:XX:XX

Granted this a CLI utility.

Elder Geek
  • 36,023
  • 25
  • 98
  • 183
5

Install macchanger and have it run every time the network connects by using a udev rule. Create the following file:

## File name /etc/udev/rules.d/70-macchanger.rules
## Set Mac Address for Network Adapters
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlan*" RUN+="/usr/bin/macchanger -m XX:XX:XX:XX:XX:XX %k"
ACTION=="add", SUBSYSTEM=="net", KERNEL=="eth*" RUN+="/usr/bin/macchanger -m XX:XX:XX:XX:XX:XX %k"

Replace XX:XX:XX:XX:XX:XX with the Mac Address you want. (Note: some addresses are invalid)

Sepero
  • 4,557
3

Without requiring ifconfig or macchanger:

sudo ip link set dev [interface_name] down
sudo ip link set dev [interface_name] address XX:XX:XX:XX:XX:XX
sudo ip link set dev [interface_name] up
Eliah Kagan
  • 117,780
ekeyser
  • 239
2

In Ubuntu 14.04 many of the solutions proposed were not working for me, and the macchanger one didn't provide many details, so I'm writing here what worked for me (if your wifi network interface is called wlan0), simply:

sudo apt-get install macchanger
sudo service network-manager stop
sudo macchanger -A wlan0
sudo service network-manager start

UPDATE: In Ubuntu 16.04 my solution above doesn't work anymore, however, the accepted answer works (the accepted answer wasn't working for me in Ubuntu 14.04 back then).

knocte
  • 996
  • 1
    The solution from knocte worked for me. My only remaining issue is to specify a particular MAC address. This is the terminal command from the package macchanger for selecting a MAC address:
    macchanger --mac=XX:XX:XX:XX:XX:XX eth0
    
    You may also use the easy package `macchanger-gtk`.
    – Andrew Wyatt Sep 21 '16 at 06:09
  • @AndrewWyatt if this worked for you, please upvote – knocte Sep 21 '16 at 18:39