What is the MAC address?
The MAC address (Medium Access Control address) is a unique network address for each Network Interface Controller to identify the hardware on the network segment. The address is generally expressed as six hexadecimal digits, sometimes separated by a '-', ':', or without a separator.
The MAC address is assigned by the hardware manufacturer during production, however many network controllers allow the operating system (via the drivers) to override the MAC address, this is handled at the operating system level and does not change the address stored in the adapter.
The first three octets (first three hexadecimal values, six characters) identify the network hardware manufacturer while the last three octets should be unique within each hardware manufacturer's product line. For example Plugable's MAC addresses all begin with "8CAE4C", with lower values typically representing older companies, "000000" belongs to Xerox for example, some companies have multiple ranges of MAC addresses.
Why it can be useful to override the manufacturer's address?
Setting a custom MAC address can provide anonymity when connecting to public networks. It can also be used by an IT Network Administrator to provide specific access rights to computers based on the connection.
It can also be useful for Network Administrators for testing, troubleshooting, and maintenance to simulate different devices without having access to that specific device.
Checking the MAC Address in Linux
The MAC Address can be checked from the terminal:
1. Open a bash shell
2. Read the address from the /sys directory:
cat /sys/class/net//address
or from the ip command to print out all of the hardware MAC Addresses
ip -o link | awk '$2 != "lo:" {print $2, $17}'Changing the MAC Address in Linux
Temporary change until system reboot
1. Open a bash shell
2. Run the following command to set the MAC Address for a specific network device.
sudo ip link set dev <devicename> down sudo ip link set dev <devicename> address <mac address> sudo ip link set dev <devicename> up
3. Confirm the new MAC address
Permanently change the MAC Address
This can depend on your distribution's specific network services and settings. This example will create a new systemd unit file to change the MAC Address on startup.
1. Open a bash shell
2. Create a new systemd unit file "/etc/systemd/system/changemac@.service with the following contents the mac address should be colon separated:
[Unit] Description=Change MAC Address %i Wants=network-pre.target Before=network-pre.target [Service] Type=oneshot ExecStart=/usr/bin/ip link set dev %i down ExecStart=/usr/bin/ip link set dev %i address <mac address> ExecStart=/usr/bin/ip link set dev %i up RemainAfterExit=yes User=root [Install] wantedBy=multi-user.target
3. Enable the service with the following command
sudo systemctl enable --now changemac@<interface_name>
4. Reboot the computer, the MAC address should be set to the new address