What is the correct way to restart nmcli interface remotely?

6,728

Solution 1

If you use nmcli's device reapply command, it will apply the changes. Replacing devicename with the actual device name of course.

nmcli device reapply devicename

Solution 2

This worked fine for me.

nmcli device disconnect enp4s6; wait ; nmcli device connect enp4s6

Obviously replace enp4s6 with your device name

Share:
6,728

Related videos on Youtube

Serfoo
Author by

Serfoo

Updated on September 18, 2022

Comments

  • Serfoo
    Serfoo over 1 year

    On Ubuntu 18.04, NetworkManager is used. After modifying the configuration of an interface remotely, using the NetworkManager CLI.

    Example:

    nmcli connection modify (interface_profile_name) ipv4.addresses (XXX.XXX.XXX.XXX/XX)
    

    How can I make it taken into account without shutting down my remote access?

    I tried:

    nmcli device disconnect (interface_name) && sleep 5 && nmcli connection up (interface_name)
    

    Because it is recommended to disconnect, and then reconnect the modified interface, but it cuts my access to the computer, the old and the new IP address are unreachable. I have to move on the targeted computer to make locally the modifications.

    I want to be able to make the modifications taken into account remotely, with nmcli by an SSH connection, and without restarting the computer (nothing extraordinary ^^).

    The restart of the NetworkManager service doesn't change anything.

    Thank you.

    • Michael
      Michael about 4 years
      Are you running the command in a screen/tmux session over ssh? As soon as you run that command and it disconnects I don't think it will run the rest. Try it in a tmux session tmux new
    • Serfoo
      Serfoo about 4 years
      Yes, the command seems to have been executed only for the first part, the disconnection. I know there are a lot of tools, but I want to be able to restart the network-manager interface without any extra tool. Screen and tmux are not on Ubuntu or Debian by default.
    • tim
      tim over 3 years
      Maybe preface the commands with nohup
  • Sean McCarthy
    Sean McCarthy over 3 years
    This worked for me as well. Cheers