11

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.

Serfoo
  • 111
  • 1
  • 1
  • 4
  • 1
    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 – Michael Feb 17 '20 at 13:41
  • 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. – Serfoo Feb 18 '20 at 04:28
  • Maybe preface the commands with nohup – tim Nov 14 '20 at 12:26

2 Answers2

24

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
zx485
  • 2,894
4

This worked fine for me.

nmcli device disconnect enp4s6; wait ; nmcli device connect enp4s6

Obviously replace enp4s6 with your device name

The wait is just there to confirm the first command completes, the semicolon would allow the command to fail. You could rewrite it like this to avoid using wait.

nmcli device disconnect enp4s6 && nmcli device connect enp4s6

The symbols && will run the second command after the first command completes successfully.

Dan H
  • 41
  • This worked for me as well. Cheers – Sean McCarthy Jan 29 '21 at 15:43
  • 1
    The wait command does absolutely nothing useful here. – Marcus Sep 23 '22 at 09:05
  • A sleep between the two commands is useful. Without it, you may run into an error at the connect command:

    Error: Failed to add/activate new connection: Connection 'x' is not available on device x because device has no carrier

    – Raman Apr 19 '23 at 21:00