How to: Clone the mac address for the WAN interface on a Ubiquiti Unifi Security Gateway

How to: Clone the mac address for the WAN interface on a Ubiquiti Unifi Security Gateway

Background

Nowadays you somewhat expect that cloning a mac address on a gateway/router would be a basic feature… but as Apple has taught us we don’t know what we want even if we need it. But getting back into topic, recently we started testing Ubiquiti products and part of that included the Unifi Security Gateway. One of the features we are not able to configure via the web administration console / controller is that of cloning a MAC address. For obvious reasons, we require to do that in order for our ISP to assign the correct IP address.

Solution

The solution is a bit more difficult than what I would have hoped for. As you probably already know, you are able to access the USG (Unifi Security Gateway) via SSH in order to configure several things. This has proven useful as the default IP it comes with is not compatible with our network. This time thought, it was useful in order to access the configuration console and change the MAC address of the WAN interface (eth0 in my case.) To do this, you need to follow these steps:

Connect to your USG via SSH

Run the following commands (where you replace the Xs for the right numbers):

Now, if you connect your Ethernet cable to the USG you’ll notice the change took place and you’re using the new mac address. But here comes the tricky part, when you reboot/restart the USG the settings will be lost! In order to persist the settings, you need to export the running configuration (after performing the changes/commands mentioned above) and include it in your config.gateway.json file. At this point I was like you, clueless as to what to do next. If you want to learn how to do this, please visit: UniFi – How to further customize USG configuration with config.gateway.json.

Now that you have prepared everything, it should look like this:

{

“interfaces”: {

“ethernet”: {

“eth0”: {

“mac”: “AB:CD:EF:01:23:45”

}

}

}

}

remember to put your actual MAC address there as well as confirm that your WAN interface is eth0. Also, don’t forget to validate the json file, you can use something like http://jsonlint.com/ which is a JSON Validator. Just to make sure the syntax is correct.

Now, if you are using Ubuntu you need to create this json file on your controller. After logging in the default folder where you need to place the file is located at: /var/lib/unifi/sites/default. Keep in mind default here is the name of the site, so if your site has a different name you will need to access that folder not this one. Once you’re there, you will create a file (nano config.gateway.json) and paste there our configuration we obtained just before in json format. If you are doing this for different settings, you’ll need to add the interfaces section to your existing config file. One you’re done, reboot your USG and see if the setting worked. If it booted correctly and the MAC address changed as indicated, then you’re all set and good to go!