In some networks, computers have to be registered to get connected. Upon registration, the computer will receive a name and an IP address. Every time it connects to the network, the DHCP server assigns it the same name and IP address. The DHCP server identifies computers based on the MAC address, which is unique to every NIC. However, if you know the MAC address of a registered computer, you can use it to connect to the network, faking the MAC address:
ifconfig eth0 down
macchanger --mac=00:B0:D0:20:A5:D9 eth0
ifconfig eth0 up
If you need to execute this change every time the machine is booting you can put it into a script. Under Ubuntu Trusty Tahr (14.04), the ifconfig lines didn't work for me anymore. It works, however, it by adding the following three lines to the end of file /etc/rc.local (but before the "exit 0" line):
dhclient -r eth0
macchanger -m 00:21:5a:76:44:b0 eth0
dhclient eth0
Unfortunately, on MacOSX, this seems almost impossible. Or rather, the way to do so seems to change with every OS update. The easy way is to use a router since most of these support MAC address cloning.
And with Ubuntu 16.04 and later, the easiest way seems to be to use systemd:
sudo touch /etc/systemd/system/macchange@.service
sudo emacs /etc/systemd/system/macchange@.service
Paste the following content into the file:
[Unit]
Description=changes mac for %I
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
Type=oneshot
ExecStart=/usr/bin/macchanger --mac=00:B0:D0:20:A5:D9 %I
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Then, enable the service. Remember to replace the enp2s0 with the name of your network interface!
sudo systemctl enable macchange@enp2s0.service
UPDATE: The various ways to make this permanent with systems have changed with almost every Ubuntu version, and recently, I haven't managed to do it at all anymore. One way that worked with Ubuntu 22.04 and higher was described here: https://askubuntu.com/questions/1394904/how-can-i-set-the-hardware-mac-a...
However, after some experimenting, I think that macchanger is not the right tool for the default Ubuntu desktop setup, which uses NetworkManager. NetworkManager needs to be disabled so as not to interfere. And most people want to have the convenience of changing settings with a simple click instead of issuing commands in a terminal. So, how do you do this with NetworkManager? First, you need to get to know the name of your wired configuration (in this case, "Wired"):
nmcli con show
Then you simply change the mac address:
nmcli con modify Wired ethernet.cloned-mac-address XX:XX:XX:XX:XX:XX
(BTW: The configuration files are in /etc/NetworkManager/system-connections)