Linux change mac permanent

Change Mac Address permanently inside /etc/network/interfaces

QUESTION: How might I be able to specifically change the Mac Address of the enp3s0 and wlp2s0 interfaces through the /etc/network/interfaces file? What code would I have to include inside? I have been trying for some time now without success sadly enough. ELABORATING: So I found this great article online explaining how to change a Mac Address permanently through the /etc/network/interfaces file on my Ubuntu. In the article, it says:

On Debian, Ubuntu, and similar systems, place the following in the appropriate section of /etc/network/interfaces (within an iface stanza, e.g., right after the gateway line) so that the MAC address is set when the network device is started: hwaddress ether 02:01:02:03:04:08

# interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback 

I would like to change the mac address of all of my interfaces (enp3s0, wlp2s0) (lo is loopback so no need there), but I am unfamiliar with the commands in the /etc/network/interfaces file. I have been looking at tutorials online though I can’t seem to get stuff right, and my computer even started acting very strangely a few times afterwards.

Assuming wlp2s0 is your wifi, I think you may want to see the «Cloned MAC Address» feature inside NetworkManager to change the advertised MAC address of your wifi device — same for your Ethernet

@ThomasWard thanks for the reply thomas, I actually did just that previously but found out it wasn’t premanent (which is what I needed). Hence the reason why I’m looking for the previous solution. I am trying out Jos’s solution now. I did however see you commented that I would be unable to connect to the internet through the GUI. Could you elaborate on how I would have to connect to the internet with the changes in place?

Painfully if wireless connection, less painfully if wired. I will elaborate in my own answer after I am at a computer — typing into the SE mobile app is evil.

@ThomasWard haha alright thank you! Sadly my case is wireless. I’m still trying to get Jos’s previous code to work as well.

I’ve posted my answer. It’s a very long answer, and I apologize for that, but it’s mostly complete explaining the headaches I mentioned, and links to where better information is, as I’m on a mini-time-crunch and won’t have time yet today to copy in all the steps.

3 Answers 3

First, the guide you linked to. It’s a nice guide. Sadly, it also makes some headaches for different types of connections. And normally, /etc/network/interfaces is left alone except for the loopback interface in favor of Network Manager managing your connections.

There’s a few reasons for this, mostly in that configuring wireless via /etc/network/interfaces will be painful if you switch wifi networks as you have to edit the configuration and reload it manually (and sometimes it won’t load until you reboot). It’s also extremely painful in that you have to hard-code connection data into wpa2-supplicant — wireless network name, password (in plain text), sometimes even the wifi band and the channel number. All of which is painful as you have to change it to switch to a different network.

Читайте также:  Linux mint xfce ноутбук

I did mention that using /etc/network/interfaces will prevent Network Manager from working for handling your connections. The way Network Manager works is that it takes ‘ownership’ of the devices that are network devices not defined in /etc/network/interfaces and updates the configurations for each on the fly or with predefined connection profiles from older connections made in the past. If you decide to go the /etc/network/interfaces route you will have to make adjustments to how you connect to the Internet, and I give some descriptions for wifi connections this way below. And a more useful link.

Ethernet is not so bad. Ethernet can work pretty well actually with this, because you can simply set up Ethernet as such for a DHCP’d connection (dynamically assigned IP address, not a static config; note I use ‘eth0’ here instead of your actual device here to be more understandable):

auto eth0 iface eth0 inet dhcp hwaddress ether 01:23:45:67:89:0A 

The only headache is if you have static IP addresses and not DHCP handled ones. But it’s still pretty simple.

On wireless, however, it’s not as pretty. It’s a mess of steps, usually involving iwlist , /etc/network/interfaces configuration, advanced configuration of wpa2_supplicant , and otherwise. You’d ultimately end up with something looking like this when you’re done, for a standard residential-grade shared-password network, but that only works for your one wireless network:

auto wlan0 iface wlan0 inet dhcp hwaddress ether 00:11:22:33:44:55 wpa-ssid WIFI_NAME wpa-psk HASHED_PASSWORD 

It gets even more complex when you need to switch networks, or use an Enterprise grade connection with an authentication backend (called WPA2-EAP or WPA2 802.1x Enterprise, or other names), of which I am not going to detail here.

You’ll also note I didn’t copy the steps in for how to get the hashed password. That’s my bad, I’m on a time crunch to get to work, but this is all in the wiki linked in the next paragraph (from Debian, but it works).

The Debian Wiki on Wifi and How to Use It on the Command Line is where most of this information came from for the wireless section here, and having personally had to set this up on two Raspberry Pi devices manually because they’re headless, I can attest that this is the most painful approach to setting up wireless.

There’s a second element here: network device MAC addresses are hardcoded into the device. You can’t ever ‘permanently’ change the MAC address that a device has. What /etc/network/interfaces , MAC Changer, and Network Manager (via the ‘cloned MAC address’ function) do is they temporarily change the Ethernet address advertised, but they don’t change the core hardware address. You can make it work with Network Manager, but you have to configure it manually for each wifi network you use. MAC Changer, similar situation, it needs to be run at boot time. /etc/network/interfaces does this at boot time, but you lose Network Manager management of devices.

Источник

Solved: Change MAC Address in Linux [Temp & Persistent]

When it comes to networking, you’ve probably heard of the term MAC addressed a lot. MAC Address is a physical identity assigned to each interface. Now you may wonder when the MAC Address is already assigned to an interface then why would we want to change it? Well there can be a number of scenarios, speaking from my personal experience

  1. We had a very old rack server where we failed to installed RHEL 8 and the MAC address of the interfaces from this server kept changing after every reboot. So we decided to update the PCI ID of each interface using udev rule bundled inside initrd to overcome this issue.
  2. For PXE boot we perform network based installation. Now this should not be a problem when we are using DHCP but if you want to use static IP then you must define the MAC Address of the interface and the IP to be assigned. Now imagine you have 100s of servers, so connecting to each one and getting the MAC can be nasty so we can just change the MAC address of these servers as per our need and then just use them to perform PXE boot.
Читайте также:  Ch340 arduino driver linux

In this tutorial, I will cover what we mean by MAC address, what it’s used for, and how to change it. We will use Kali Linux to demonstrate the steps from this article.

Overview on MAC Address

  • MAC address stands for Media Access Control, and it’s a permanent, physical, and unique address assigned to network interfaces by the device manufacturer.
  • So whether you have a wireless, wired, or Ethernet, each of these network cards comes with a specific address unique to this card. There are no two devices in the world that would have the same MAC address.
  • This address will always be the same to this specific device; even if you unplug it from your computer and connect it to another computer, this network device will always have the same address.
  • Not only that but the MAC address is often used by filters to prevent or allow devices to connect to networks and do specific tasks on the web.
  • Changing your MAC address to another device’s MAC address will allow you to impersonate this device and will enable you to do things that you might not be able to do.
  • So you’d be able to bypass filters or connect to networks that only specific devices with specific MAC addresses can relate to, and you will also be able to hide your identity. Now changing the MAC address is very simple, so let me show you how to do that.

Method-1: Change MAC Address of Network Adapter (Non-Persistent)

Step 1: List Network Interfaces

First, I will use the ifconfig command to list all the network interfaces available on my Kali machine. What I mean by network interface is any device that allows us to connect to a network.

An example is a Wi-Fi card or an Ethernet card, and so on. So you can see first of all we have eth0 , which is a virtual interface created by virtual box when we set Kali to use NAT network.

Solved: Change MAC Address in Linux [Temp & Persistent]

You can see the interface name is eth0, and you can see it has an IP address because, as I said, it’s connected to a network.

If we go here, we can see it saying Wired Connected. The interface represents the wired network that Kali is connected to, which is a virtual NAT network.

You can also see the netmask, the broadcast, and an essential piece of information: the ether, which is the MAC address of this virtual interface.

Now, you can see similar information for my other two interfaces, the lo and the wlan0. The only thing is you can see for both of these interfaces. We do not have an IP address. And the main reason for that is that none of these interfaces is connected to a network.

Читайте также:  Linux print server port

Now lo is the default interface created by Linux, and wlan0 is my genuine wireless adapter. I can use it to connect to Wi-Fi networks. But if I go on the web in here, you’ll see Wi-Fi is not connected because I didn’t connect to any network, and that’s why it does not have an IP address.

Now, this doesn’t matter because we want to change the MAC address, which is again shown under the ether part, similar to what you see here for eth0 .

Step 2: Disable Interfaces

Now, to change any of the values you see here, you first have to disable the interface. In this example, we want to change the MAC address to represent it by the ether, and the value is right here.

To disable an interface, we’re going to do ifconfig followed by the interface name, wlan0 in my example, followed by down to disable it.

Solved: Change MAC Address in Linux [Temp & Persistent]

Now, if I hit Enter, you’ll see the command runs with no errors, so it means that it got correctly executed. And the next thing that we need to do is change the option that we want to change. And in this example, we want to change the ether, which is the MAC address.

Step 3: Change MAC Address

First, we’re going to type ifconfig , type the interface that we want to change, one of its options, then type the option we want to change. And what we want to change is the hardware address, so we’re going to do hw ether. Then we’re going to give it the lesson that we want to change the MAC address.

For this example, I’m going to use 00:89:76:88:82:33 . Very, very simple command, we’re doing ifconfig wlan0 to select the interface that we want to change its option, we want to set the hardware address, and we want to put this address to this specific address.

So you can use any address that you want, following the same format shown here. Just make sure your address starts with 00 . So I’m going to hit Enter, and again, we don’t see any error messages, so it means the command got appropriately executed.

Solved: Change MAC Address in Linux [Temp & Persistent]

And finally, we need to enable the interface because we disabled it by doing ifconfig wlan0 down , so we need to do ifconfig wlan0 up to allow it. Now the interface is enabled, and if we do ifconfig again, and look at the ether part here, you can see that it is changed to the MAC address that we specified.

Step 4: Verify the new MAC Address

Now, this is done, and your MAC address has changed. Now, you can go ahead and start using the interface, and it’ll appear to have this MAC address instead of its original MAC address. And like I said, this can be useful in so many scenarios.

Solved: Change MAC Address in Linux [Temp & Persistent]

Now, keep in mind, the MAC address will revert to the original one once you restart the computer because we’re only changing the MAC address in memory. We’re not changing the physical MAC address.

Method-2: Change MAC Address of Network Adapter (Persistent)

In this section we will change MAC Address of a network adapter permanently which will be persistent across reboots.

Источник

Оцените статью
Adblock
detector