MAC Address: What it is and how to change it desde Linux

La MAC address (media access control) is a 48-bit identifier that uniquely corresponds to a network card or device. It is also known as physical address, And is unique for each device, since they are written directly on the hardware at the time of manufacture. An example would be: 38:70:77:1D:51:00.

In other words, in reality with this post we are not going to learn to change the MAC permanently, but to create a clone with different objectives. For example, in one of my work centers, to obtain an IP address with Internet access, a MAC registered in the DHCP server is required. That is, an IP is delivered against a MAC.

The problem is that I usually carry my laptop everywhere and it is much more comfortable to work from it than on a random computer. Therefore, what I do is clone the MAC of the computer assigned to me in the Laptop and in this way I can access the Internet.

3 methods to change the MAC address.

Through the ip link

The simplest method (in Archlinux) is using ip-link. To do this, the first thing we have to do is "knock down" or "stop" the network card, but we need to know what our interface is, so we execute:

$ ip link show

This will give us a list similar to this:

1: what: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default link / loopback 00: 00: 00: 00: 00: 00 brd 00: 00: 00: 00: 00: 00 2: enp1s0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link / ether 20: 89: 84: f7: 4c: fa brd ff: ff: ff: ff: ff: ff 3: wlp2s0: mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000 link / ether 68: 17: 29: be: ff: 69 brd ff: ff: ff: ff: ff: ff 4: virbr0: mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default link / ether ca: 97: e2: 96: 15: b3 brd ff: ff: ff: ff: ff: ff

In this case, the one that interests us is number 2, so we proceed to execute (the name may change depending on the PC or the distro):

$ sudo ip link set dev enp1s0 down

Once the card is down we execute the command:

$ sudo ip link set dev enp1s0 address XX:XX:XX:XX:XX:XX

Where XX: XX: XX: XX: XX: XX is the MAC number that we want to clone. Now we lift the card:

$ sudo ip link set dev enp1s0 up

Via macchanger

We can change the MAC through an application called macchanger:

# pacman -S macchanger

The usage syntax is "macchanger -r ».

# macchanger -r enp1s0

To create a random MAC address, except for the provider's bytes (in case they check the MAC), you must use the command:

# macchanger -e enp1s0

Finally, to change the MAC address to a specific value:

# macchanger --mac=XX:XX:XX:XX:XX:XX

Using NetworkManager

Well, after so much console hassle, we have a much simpler method to change or clone the MAC address, and that is simply using NetworkManager. Notice where it says: Cloned MAC addresses.

MAC address

The best thing about this method is even when we restart the computer, the MAC address that we clone will remain. Also, this tool allows us to create a random MAC address. And this has been all dear friends.

Source: ArchLinux Wiki


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   orange said

    o
    ifconfig eth0 down
    ifconfig eth0 hw ether 02: 01: 02: 03: 04: 08
    ifconfig eth0 up

    1.    alex said

      You put the easiest way with arch and the easiest way is the one that put orange, which is the one I knew too

  2.   eliotime3000 said

    Interesting, to be able to access WiFi networks with MAC address filtering (it is ephemeral, but it turns out to be useful).

    1.    Raphael Castro said

      A Cuba is very common, greetings.

  3.   static said

    Excellent, at the university I always cloned the MAC of one or another user to improve connectivity in downloads, of course it was nothing serious but it helped me with the download of OS and its future learning, thanks for the post

  4.   Bones said

    Interesting to be able to filter the internet by MAC address, I foresee that I will need to learn to do that. Excellent post

  5.   Jorge said

    Interesting, although it is still important to clarify that the process is "Spoofing" or "MAC Masking", since the de facto and de jure concept of changing the MAC is practically impossible given that it is a physical address. But that it remains masked until after the reboot, it is valuable, useful at the time of the network security audit.

    By the way, what font did you use in the screenshots? : v

    1.    elav said

      Yes, that's why I said in the post that we were going to clone, not physically change the MAC 😀 the font is Aller.

  6.   sirMvM said

    Excellent article

  7.   Surfer said

    macchanger also has a GTK interface the package I think is macchanger-gtk

  8.   Pastor said

    Does this work in case of MAC blocking on domain servers or on wireless? I say this because in the company I work for, MACs from cellular devices and laptops are blocked by wireless. If the devices blocked by MAC change it, will they be free again?

  9.   darkar said

    The information is very useful, thank you for sharing it.

  10.   shini kire said

    As you say, in kde you can, in gnome too tamb even though it doesn't have the Random option: 'c

  11.   jamin samuel said

    In gnome Network Manager it also facilitates it graphically

  12.   Radex's said

    excellent article for those who start in linux

  13.   dario said

    It also has another less known use to change mac. When my isp has static ip I change the mac of the router and restart and they give me a new ip

  14.   mat1986 said

    I remember when I used aircrack-ng they said that as an important requirement when auditing networks it was necessary to change the MAC, imagine if for some reason they discover you: locating the physical MAC they discover your computer ...

  15.   pek said

    Can forum administrators see your mac? Does changing it serve for something more than filtering routers?

  16.   Absalom said

    Greetings, I have a problem. I have already done the three-way procedure with my Wi-Fi card, but while it is disconnected from the network, the Mac is changed. When I connect to the network, it returns to the original Mac and the new one does not stay. Therefore it does not connect. The strange thing is that I have done it from Windows and it works and connects but desde linux no… Maybe some solution for this dilemma….????

  17.   Jose de Alonso said

    Very good!

    Here I have found another link in Spanish that explains several methods to find your MAC address in Linux:

    http://www.sysadmit.com/2018/01/linux-saber-direccion-mac.html