Creating a keyfile Connection Profile Manually

You can manually create a NetworkManager connection profile in a keyfile format.

Note:

Manually creating or updating the configuration files can result in an unexpected network configuration. Another option would be to use nmcli in offline mode. See Creating a keyfile Connection Profile Using nmcli in Offline Mode.
  1. If you're creating a profile for a hardware interface, such as Ethernet, display the hardware's MAC address.
    ip address show ens3
    2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 02:00:17:03:b9:ae brd ff:ff:ff:ff:ff:ff
        ...
  2. Use any text editor to create a connection profile that contains the network settings that you want to define for the connection.

    For example, if the connection uses DHCP, the profile would contain settings similar to the following example:

    [connection]
    id=myconnection
    type=ethernet
    autoconnect=true
    
    [ipv4]
    method=auto
    
    [ipv6]
    method=auto
    
    [ethernet]
    mac-address=02:00:17:03:b9:ae
  3. Save the profile to /etc/NetworkManager/system-connections/filname.nmconnection.
    In this current procedure, the profile would be /etc/NetworkManager/system-connections/myconnection.nmconnection.

    Note:

    The defined ID variable, such as myconnection, doesn't need to be identical with the profile's file name, for example myethernet.nmconnection. When you change the profile by using the nmcli command, you can identify the profile by the defined ID (myconnection) or by the file name, but excluding the file extension name (myethernet).
  4. Restrict the permissions of the profile.
    sudo chown root:root /etc/NetworkManager/system-connections/myconnection.nmconnection
    sudo chown 600 /etc/NetworkManager/system-connections/myconnection.nmconnection
  5. Reload the connection profiles.
    sudo nmcli connection reload
  6. Verify that NetworkManager can read the profile.
    sudo nmcli -f NAME,UUID,FILENAME connection
    NAME           UUID       FILENAME
    myconnection   uuid        /etc/NetworkManager/system-connections/myconnection.nmconnection
  7. If you specified false for the profile's autoconnect parameter, then activate the connection.
    sudo nmcli connection up myconnection