What is the correct way to restart nmcli interface remotely
What is the correct way to restart nmcli interface remotely
https://askubuntu.com/questions/1211088/what-is-the-correct-way-to-restart-nmcli-interface-remotely
Asked 5 years, 9 months ago Modified 2 years, 10 months ago Viewed 50k times 13
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.
networkingnetwork-managernmcli
Share Improve this question Follow edited Dec 11, 2020 at 18:53 BeastOfCaerbannog’s user avatar BeastOfCaerbannog 17k1111 gold badges6161 silver badges100100 bronze badges asked Feb 17, 2020 at 12:19 Serfoo’s user avatar Serfoo 13111 gold badge11 silver badge44 bronze badges
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
Commented Feb 17, 2020 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
Commented Feb 18, 2020 at 4:28
Maybe preface the commands with nohup –
tim
Commented Nov 14, 2020 at 12:26
Add a comment 2 Answers Sorted by: 25
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
Share Improve this answer Follow edited Jul 13, 2021 at 18:09 zx485’s user avatar zx485 2,9051818 gold badges3131 silver badges3939 bronze badges answered Jul 13, 2021 at 17:48 Adam Gibson’s user avatar Adam Gibson 35133 silver badges22 bronze badges Add a comment 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. Share Improve this answer Follow edited Dec 31, 2022 at 22:27 answered Dec 9, 2020 at 0:15 Dan H’s user avatar Dan H 4133 bronze badges
This worked for me as well. Cheers –
Sean McCarthy
Commented Jan 29, 2021 at 15:43
1
The wait command does absolutely nothing useful here. –
Marcus
Commented Sep 23, 2022 at 9: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
Commented Apr 19, 2023 at 21:00