20

The connect automatically option is allowed for my wired Wired connection 1. Disconnecting the connection works when I do it from the panel's Network > Disconnect menu. But when I do that with command:

nmcli con down id "Wired connection 1"

no sooner than it disconnects, the connection is back on.

How does Network > Disconnect work? Could we do the same with nmcli without disabling the automatic connection?

Note:

  1. nmcli con down id "Wired connection 1" works as with automatic connection disabled (but again that's not an option),
  2. I don't want to use sudo (wouldn't be good to implement in a script!).
Zanna
  • 72,312
rusty
  • 16,917

1 Answers1

28

The following command works for me like a charm if I want to disable any internet connection from terminal:

nmcli networking off

To enable it again:

nmcli networking on

Note: As commented by CPBL, this works in Ubuntu 15.04 and later. For older versions try nmcli nm enable false and nmcli nm enable true.


Another way very close to your quest is to use:

nmcli dev disconnect iface eth0

To enable eth0 again you need to type:

nmcli -p con up id "<connection name>" iface eth0

Example for connection named "Wired connection 1":

nmcli -p con up id "Wired connection 1" iface eth0

Change eth0 to your wired interface name. This will prevent any further connections without user/manual intervention as man nmci says:

disconnect iface <iface> [--nowait] [--timeout <timeout>]
           Disconnect a device and prevent the device from automatically
           activating further connections without user/manual intervention.
       Available options are:
            --nowait     – exit immediately without waiting for
            command completion

            --timeout    – how long to wait for command completion
            (default is 10 s)

Please read man nmcli for more info.

Pablo Bianchi
  • 17,371
Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407