How to change the MAC address in Linux and use time-limited wifi unlimitedly

How to change the MAC address in Linux and use time-limited wifi unlimitedly

In Japan, there are many locations (e.g. airport, convenience store, train stations, ...) where there is free wifi available. Usually, the wifi connection here is limited to a specific time range (e.g. 1 hour). After the connection expires, you have to connect to the wifi again and obtain a new access session.

It happens to me when I traveled to other countries, stayed in an environment which limits wifi connection. There, wifi is free only in the first session. To continue the access, an extra payment is requested.

Technically, the only way a wifi router can track a device and check if the device has finished the free session or not is by MAC address. Thus, if the MAC address is changed, technically, the wifi router has no idea on the tracking device. Cookie can be used, however, cookie is too easily to be manipulated by end-user.

I write this post for technical purposes. And I do not recommend using this way to avoid a have-to-pay bill. Non-free wifi is usually cheap and it is not worth to pay too much effort to avoid such a small amount of payment.


On each device that supports a wifi connection, there is a wifi card. This wifi card requires a driver (so called network driver) to be used. For example, to provide device information (MAC address) to wifi router, encode/decode data to physical layer signal data.

Network driver is a "soft"ware, programmed, thus it can be changed, configured via software. Usually, default network driver is provided by operating system.

Changing MAC address requires sudo (root) privilege. As a result, if you want to do the change in smartphone devices, technically, it requires your smartphone to be rooted.


My current ubuntu version via lsb_release -a is as follows

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.3 LTS
Release:	18.04
Codename:	bionic

Step 1: check interface name and current MAC address

sudo ifconfig

Result looks like

wlp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        inet6 fe80::ed2b:844f:3c9f:315d  prefixlen 64  scopeid 0x20<link>
        ether b4:d5:bd:93:3c:99  txqueuelen 1000  (Ethernet)
        RX packets 417159  bytes 351029164 (351.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 236165  bytes 94066903 (94.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

The interface name here is wlp4s0, current MAC address is b4:d5:bd:93:3c:99.

From this MAC address, you can choose any new MAC address you want.
MAC address is 48 bits (6 bytes) long, which includes 24-bit OUI (Organizational Unique Identifier) and 24-bit vendor-assigned address.
You should change the latter 24-bit, and should not change the first 24-bit OUI. Otherwise, the wifi router could not recognize your device and use the wrong protocol at a low-level network layer (physical layer, network layer, ...)

For example, I choose my new MAC address as b4:d5:bd:93:3d:99.

Step 2: stop network driver

sudo /etc/init.d/networking stop


sudo systemctl stop networking

Step 3: de-activate current interface

sudo ifconfig wlp4s0 down

Step 4: change MAC address

sudo ifconfig wlp4s0 hw ether b4:d5:bd:93:3d:99

Step 5: activate the network interface

sudo ifconfig wlp4s0 up

Step 6: confirm the new configuration

sudo ifconfig wlp4s0

Check if the new MAC address has been assigned.

Step 7: enable network driver

sudo /etc/init.d/networking start


sudo systemctl start networking

Step 8: (optional) reset wifi

If you are connecting to a wifi connection. The current connection will not be able to work. To re-connect, run following commands

sudo nmcli radio wifi off
sudo nmcli radio wifi on

Note: this method only works in the current login session. The change will be reversed after a logout or a restart. To permanently change MAC address, refer to the following source.