How to automaticaly changing MAC address on linux mint ?

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
spamator12
Level 4
Level 4
Posts: 214
Joined: Mon Feb 04, 2019 11:57 am

How to automaticaly changing MAC address on linux mint ?

Post by spamator12 »

Hi, I need to automate the MAC changing system, so even after reboot computer will use set up MAC and NOT the default one. I'm doing this cause after hardware failure (fire) I have equipment limitations and need to use specific MAC to not change whole configuration.

At the beginning I were using macchanger program to no avail - I could not automate the process (https://community.linuxmint.com/tutorial/view/376). After every restart my card had default address. The only permanent option was to install macchanger with random MAC address option set up at the beginning - MAC was the same after restart but I need manual specific MAC address so it was not an option for me. Then I found some info at kali linux wiki (good documentation - https://wiki.archlinux.org/title/MAC_address_spoofing) but in linux mint, some thing are simply different. I tried SO, SU scripts but there were not working properly.

So... any of you know hot to set up your specific MAC address that will last after restarts, and are set up BEFORE any connections are made (so the MAC is set up on card FIRST and then the card is up, NOT otherwise - cause then card is up using old MAC and you need to turn it off, give proper MAC and then set it up).

Thanks for any input. Tutorials/links are appreciated.
Last edited by LockBot on Mon Sep 18, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Pjotr
Level 24
Level 24
Posts: 20123
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: How to automaticaly changing MAC address on linux mint ?

Post by Pjotr »

Well, apparently it's quite simple to do if you launch Network settings, click on the gear wheel after your network name (SSID), tab Identity. There you can fiddle with "Cloned address".

No idea how well this works nor whether it's persistent across reboots, but it's worth a try, I'd say.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
spamator12
Level 4
Level 4
Posts: 214
Joined: Mon Feb 04, 2019 11:57 am

Re: How to automaticaly changing MAC address on linux mint ?

Post by spamator12 »

@Pjotr I have tried it - it was the first thing I tried, but it's not working - the card is started with default address. Also ifconfig, ip addr, my router etc. show default MAC. I would like the change of MAC to be on lowest level possible (so there is no "I as a separate program set to this, and the other program set it to that, and third program set it again cause default network manager change it to default, and then again... - just set MAC and THEN start network UP - automatically at system start up).
User avatar
Midnight True
Level 7
Level 7
Posts: 1537
Joined: Wed Jul 20, 2022 3:23 am
Location: Southern and Southwestern area of Mato
Contact:

Re: How to automaticaly changing MAC address on linux mint ?

Post by Midnight True »

If i may add, have you tried setting Clone Mac Address ---> Random? also on IPv4 Settings ---> Method ---> Automatic (DHCP) Addresses only if you use IPv6 change it as well like on IPv4
spamator12
Level 4
Level 4
Posts: 214
Joined: Mon Feb 04, 2019 11:57 am

Re: How to automaticaly changing MAC address on linux mint ?

Post by spamator12 »

@Midnight True hi, no random is not an option for me cause server is configured in a way it need specific MAC. Also I do not use IP6 it is turned off im interested in IP4 only.

I can't believe that you can set up proper custom MAC on linux mint. My acquaintance with arh linux can do it immediately but is way more advanced user and linux mint is more friendly so I prefer to keep it (and thanks to this forum I could configure it as I want to).
User avatar
Midnight True
Level 7
Level 7
Posts: 1537
Joined: Wed Jul 20, 2022 3:23 am
Location: Southern and Southwestern area of Mato
Contact:

Re: How to automaticaly changing MAC address on linux mint ?

Post by Midnight True »

spamator12 wrote: Sun Mar 19, 2023 8:58 am @Midnight True hi, no random is not an option for me cause server is configured in a way it need specific MAC.
In Xfce Image
Attachments
Screenshot_2023-03-19_23-14-15.png
User avatar
axrusar
Level 7
Level 7
Posts: 1512
Joined: Sat Jan 30, 2021 5:30 pm

Re: How to automaticaly changing MAC address on linux mint ?

Post by axrusar »

Try creating a file with the same name of the adapter you want to apply the permanent MAC address in the /etc/network/interfaces.d/ directory and add the following to it:

Code: Select all

auto eth0
iface eth0 inet dhcp
hwaddress ether XX:XX:XX:XX:XX:XX
(replace eth0 with the name of your adapter)
Reboot and check the MAC address with ifconfig
Linux Mint Una Cinnamon 20.3 Kernel: 5.15.x | Quad Core I7 4.2Ghz | 24GB Ram | 1TB NVMe | Intel Graphics
Image
spamator12
Level 4
Level 4
Posts: 214
Joined: Mon Feb 04, 2019 11:57 am

Re: How to automaticaly changing MAC address on linux mint ?

Post by spamator12 »

@axrusar this does not work for me. At startup there is:
A start job is running for network interface...
and it trying to resolve that for 5 min or so.

Then
Network name resolving
is set on/off and again on/off. And when I log in there is no network, and you can choose and start any connection.

@Midnight True - it works! Thanks! How to do that via command line (terminal), or by script or in /etc/network/interfaces.d/ ?
User avatar
Midnight True
Level 7
Level 7
Posts: 1537
Joined: Wed Jul 20, 2022 3:23 am
Location: Southern and Southwestern area of Mato
Contact:

Re: How to automaticaly changing MAC address on linux mint ?

Post by Midnight True »

spamator12 wrote: Sun Mar 19, 2023 3:37 pm @Midnight True - it works! Thanks! How to do that via command line (terminal), or by script or in /etc/network/interfaces.d/ ?
Your welcome 🍻🍻🍻 unfortunately, i have no knowledge regarding this method sorry
User avatar
axrusar
Level 7
Level 7
Posts: 1512
Joined: Sat Jan 30, 2021 5:30 pm

Re: How to automaticaly changing MAC address on linux mint ?

Post by axrusar »

I did it on Mint XFCE 20.3 like this and it works:
ether1.jpg
Have you previously changed any other settings on your network interface that may conflict with this?
Try resetting it, it should work
Linux Mint Una Cinnamon 20.3 Kernel: 5.15.x | Quad Core I7 4.2Ghz | 24GB Ram | 1TB NVMe | Intel Graphics
Image
spamator12
Level 4
Level 4
Posts: 214
Joined: Mon Feb 04, 2019 11:57 am

Re: How to automaticaly changing MAC address on linux mint ?

Post by spamator12 »

@Midnight True, sorry but after few restarts, it stop working.

@axrusar thanks for the screen, I has set it up exactly like you to no avail.

I try to set everything to default, check if programs are uninstalled correctly (my guess is that some macchanger scripts are still interfere with network setups), and try to set up everything again.

EDIT: ok, so remove simply not works with some of network mutating programs you need to use purge. Also you need to clear cache of your arp table

Code: Select all

ip -s -s neigh flush all
and check it

Code: Select all

arp -n
if its ok AND then restart you system.

So after restart the @Midnight True solution is working. Now I'm gonna check again if @axrusar idea is working.

EDIT2: no it's not...

I also disable IP6 in Network Settings, but
ifconfig
,
ip addr
are still showing if as on. The wired connection has properly
inet6 ::1
so it is turned off, but wireless has always some IP6 address...

EDIT3: I have manage to disable IPv6!

simply typing

Code: Select all

net.ipv6.conf.all.disable_ipv6 = 1
does not work! Cause my PC doesn't load /etc/sysctl.conf at boot time and disabling IPv6 from grub is needed (https://askubuntu.com/a/337736) - simply add

Code: Select all

ipv6.disable=1
to GRUB_CMDLINE_LINUX_DEFAULT.

I still do not know why @axrusar solution does not work for me...
User avatar
axrusar
Level 7
Level 7
Posts: 1512
Joined: Sat Jan 30, 2021 5:30 pm

Re: How to automaticaly changing MAC address on linux mint ?

Post by axrusar »

spamator12 wrote: Mon Mar 20, 2023 8:41 am I still do not know why @axrusar solution does not work for me...
Please post a screenshot like i did with the ifconfig output, and the file with the code in the /etc/network/interfaces.d/ directory.
Also your system info report (inxi -Fznxxx).

Note that the solution i provided works on ethernet adapters, i did not test on wifi ones. Which one are you trying to setup?
Linux Mint Una Cinnamon 20.3 Kernel: 5.15.x | Quad Core I7 4.2Ghz | 24GB Ram | 1TB NVMe | Intel Graphics
Image
spamator12
Level 4
Level 4
Posts: 214
Joined: Mon Feb 04, 2019 11:57 am

Re: How to automaticaly changing MAC address on linux mint ?

Post by spamator12 »

@axrusar that explains a lot. I'm using this to set up wifi adapter (WLAN). My LAN (cable) is not connected.

Anyway, the 5min wait till system set up is weird.
mintuser192847
Level 1
Level 1
Posts: 3
Joined: Mon May 29, 2023 7:45 pm

Re: How to automaticaly changing MAC address on linux mint ?

Post by mintuser192847 »

Can anyone confirm if the "network manager" method of setting random mac addresses actually works?

I'm wanting to avoid connecting online with the static hardware mac of the ethernet card.

So in network manager, in Mint 21.1, I set the "cloned mac address" of my ethernet card to Random.

If I use ip link to show the address, the default is shown. A system restart made no difference.

I have not attempted to actually get online yet.

How can I tell if the "random" setting works?

Previously I have used MacChanger, but I would need to perform an offline install of that package in order to use it, and installing packages offline seems like a headache on linux. I looked into the subject but haven't attempted it.
Locked

Return to “Beginner Questions”