37

How to export and migrate NetworkManager settings to new system?

Use cases are:

  • reinstalling a machine
  • moving network configuration from laptop to desktop system (or vice-versa)

All settings should be migrated, that includes:

  • default and custom network connections
  • wifi connections with passwords
  • VLAN configurations
  • VPN configurations (with keys if possible)

I checked on Arch wiki and it there is nothing on migration, so I'm asking you guys and gals here.

Christopher
  • 15,611
  • 7
  • 51
  • 64
valentt
  • 699
  • 2
  • 8
  • 12

7 Answers7

27

Each connection configured in NetworkManager is stored in a file in

/etc/NetworkManager/system-connections

Usually, you can copy needed files from a machine to another (by root, of course).

Warning: some configuration file could reference external resources. E.g. in one of my openvpn files I have a line like cert=/home/andcoz/somedir/somefile.crt. You need to copy any referred file.

andcoz
  • 16,830
  • 3
  • 38
  • 45
  • 12
    This answer is incomplete. NetworkManager assigns a UUID to each system connection that appears to be based on the MAC address of the interface. If you change hardware, NetworkManager won't use old system connections because the UUID no longer matches what it expects. – divestoclimb Jul 12 '17 at 13:30
  • I checked directory /etc/NetworkManager/system-connections on my laptop and I only see vpn connections there. But I don't see any wired or wifi settings there. I'll try moving over one vpn connection and report back if this works or not. So if it works this answers 1/4 of the question. Thanks. – valentt Oct 27 '17 at 08:00
  • 3
    @divestoclimb is there some guide that explains how to rename UUID from old system to new one's ? – valentt Oct 27 '17 at 08:01
  • 1
    @divestoclimb is right, these connections won't be picked up if you migrate to new hardware, only for a reinstall on the same hardware this will work. I'd love to know a solution here, just like valentt! – djvdorp Apr 25 '18 at 16:57
  • 2
    The UUID is only a random generated identifier. You have to be sure that each connection has a unique identifier (on each machine). – andcoz Apr 30 '18 at 13:08
  • Perhaps, you'd have some problem on different hardware if your configuration file has some line like "mac-address". I usually do not have that line but, if you have that kind of line, you'll have to change the hardware address to the right value on that machine. Use `ip link` to check the hardware address of your devices. – andcoz Apr 30 '18 at 13:12
  • In my VPN conf file I don't see any external reference nor MAC address. But when I copy it to a new system (both are Ubuntu 20.04) and reboot, the file is not seen by `nmcli con`. – Mark Oct 10 '21 at 07:57
14

As mentioned by others, Wi-Fi connection files in system-connections directory have the interface MAC address included. This need to match your current setup hence the procedure is:

  1. copy all files from old machine to new machine from/to directory:

    /etc/NetworkManager/system-connections
    
  2. change MAC address entry in each file from old MAC to new MAC. As root:

    cd /etc/NetworkManager/system-connections
    sed -i -e 's/<old mac>/<new mac>/ *
    
  3. Just in case, restart network manager:

    systemctl restart NetworkManager
    

Old mac you may check from any of the files you copied, new mac if unsure you can check with ip link (or from the file that likely got created when you installed your system for the connection you used to copy the files).

Note: above assumes you had a single Wi-Fi interface in both your old an new setup, but the same logic should work with multiple interfaces.

  • 2
    What is the line of MAC for VPN conf files? I only see UUID. How can I re-generate new UUID on a new machine? – 32r34wgf3e Aug 01 '18 at 17:48
5

Wireless settings (at least on Fedora) are kept in this directory:

/etc/sysconfig/network-scripts 

There are two files per wifi connection. First file is named ifcfg-YOURSSID contains wifi network settings and keys-YOURSSID contains wireless network password.

Also there is a related question that explains this: Where are NetworkManager's WiFi settings stored?

valentt
  • 699
  • 2
  • 8
  • 12
5

The following worked for me on ubuntu:20.10

Copy the contents of /etc/NetworkManager/system-connections over.

Make sure that the permissions=user:newusername:; matches your running user (the one under which you want to use the vpn - echo $( whoami ) can help)

Next make sure you have the correct packages installed. If you are using openvpn then you need

network-manager-openvpn
network-manager-openvpn-gnome

You will also need the correct service-type packages installed. For example when using service-type=org.freedesktop.NetworkManager.l2tp Then you will need to install l2tp for network manager

And finally what I had problem with is permissions on the files in /etc/NetworkManager/system-connections For me, the files need these permissions:

-rw------- 1 root root

When I copied the files I had 775 permissions with my user as owner on them which prevented NetworkManager from using them for some reason.

zatloeri
  • 51
  • 1
  • 2
3

The other posts are right, but there are minor changes to some points.
The answers are kept in

/etc/Networkmanager/system-connections

You can remove the line mac-address or change it via

cd /etc/NetworkManager/system-connections
sed -i -e 's/<old mac>/<new mac>/' *

You can get the new mac adress via

ip a

Depending on the storage where You kept the files, the file rights may be wrong, just set them via:

chmod 0600 *
chown root:root *

Finally restart Network Manager

systemctl restart NetworkManager

Works the same under ubuntu 18.04.

sneaky
  • 251
  • 2
  • 11
2

It took me too long to figure this out, but you can export individual things (like VPN settings) using nmcli:

# List connections
nmcli connection

# Export one
nmcli connection export ConnectionName > yourfile

This works no matter where your config files are, though I think there's no way to export more than one at a time. Unfortunately this doesn't appear to retain at least password credentials - it may retain certificate ones.

Ryan Pavlik
  • 131
  • 5
  • Usage: nmcli connection export { ARGUMENTS | help } ARGUMENTS := [id | uuid | path] [] Export a connection. Only VPN connections are supported at the moment. The data are directed to standard output or to a file if a name is given. (This at least for Centos/rocky 8.4) – Paul Hedderly Aug 02 '21 at 21:33
  • It doesn't do much, only grabs what is in system-connections. For OpenVPN connections in particular, keys and certs are left out so it is basically useless. – Eusebius Sep 15 '21 at 11:12
0

Use the connection show interface name and redirect to a file. First run con show to get the name/UUID

nmcli con show 
nmcli con show eth0 > yourfile
rydx
  • 1