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
Source: Changing Your MAC Address/Linux -WikiBooks
Now when I use the following code:
cat /etc/network/interfaces
I get the following output
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
And when I do ifconfig on my ubuntu, I get back 3 different interfaces:
enp3s0
lo
wlp2s0
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.
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.
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.
Assuming that you don't use NetworkManager to configure your connections, I would think this will work:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
iface enp3s0
hwaddress ether 02:01:02:03:04:08
iface wlp2s0
hwaddress ether 02:01:02:03:04:09