This post shows how to change the mac-address of your NetworkManager configuration so you can transfer your wifi connections from one computer to the next one. This is an update of my old post Transfer network-manager connetions to new computer.
NetworkManager stores all the connections in /etc/NetworkManager/system-connections
as paintext files. Wifi connections are bound to the hardware MAC address and this is the reason, why you cannot just re-use the old files, when you copy the old system-connections
files from one laptop to the next one. You need to update the mac-address
line to match the MAC address of you new laptop, otherwise your old connections won’t show up.
So, all we need to do, is to modify the following section in all files:
[wifi]
mac-address= ...
Automate it!
I’ve written a simple change_nm_mac
script, which takes the new MAC address as argument and then changes all system-connections
files to use this new MAC address instead (e.g. to change it to 00:aa:bb:cc:dd:ee
):
change_nm_mac 00:aa:bb:cc:dd:ee
The script is just a clever sed
with some magic sugar around it:
#!/bin/bash -e
cd /etc/NetworkManager/system-connections
if [[ $# -gt 0 ]]; then
newmac=$1
else
printf "New MAC address: "
read newmac
fi
for f in *; do
sed -i "s/mac-address=..:..:..:..:..:../mac-addess=$newmac/" "$f"
done
echo -e "Done. You need to restart the NetworkManager for the effects to take place:"
echo -e "# systemctl restart NetworkManager\n"
Happy new year!