7

I have a laptop with debian. Networking is configured with NetworkManager. Now occasionally I want to connect a device to its wired ethernet port and then bridge wireless to it. That all works in so far: I need to terminate NetworkManager first manually to ignore the ethernet port or else it is going to try to configure it which interferes with the static address required. My question now is: how can I, using a dbus command, say to NetworkManager that it should ignore eth0 for a while? And later to manage it again?

0

4 Answers 4

2

From the Debian wiki:

As of Debian Squeeze, NetworkManager does not manage any interface defined in /etc/network/interfaces by default.

So you should maybe put the static Ethernet configuration in the interfaces file and prevent NetworkManager from managing it altogether. I think you can also do some interface mapping to automatically switch between using the bridged configuration and the "normal" one as needed.

4
  • as far as i remember, you have to restart network manager after that to take effect. Which is more complicated than simply stopping it.
    – BatchyX
    Commented Apr 28, 2013 at 20:25
  • @BatchyX Not really sure what you mean. I'm suggesting that the OP should prevent NetworkManager from managing their eth0 (or equivalent) interface. All it would cost is one restart of NetworkManager.
    – Joseph R.
    Commented Apr 28, 2013 at 20:37
  • 1
    The OP reads temporarily ignore an interface. It's even in the title!
    – BatchyX
    Commented Apr 29, 2013 at 6:59
  • @BatchyX I have seen that. Please read the OP again carefully. Making NetworkManager temporarily ignore an interface, isn't an end in itself. It's the solution the OP found to his problem. I'm suggesting (what I think is) a better approach to his original problem that would allow him to switch between configurations automatically without resorting to a "dbus command".
    – Joseph R.
    Commented Apr 29, 2013 at 9:20
2

TL;DR

nmcli device set eth0 managed false
.
.
.
nmcli device set eth0 managed true

Note: you do not need to be root.

Network unmanager

Although old, this is still a very good question and the answer has changed over the years. Thankfully, it is now much simpler. The nmcli command controls Network Manager from the command line and can be used to tell it that certain interfaces should be left unmanaged:

nmcli device set eth0 managed false

When you want Network Mangler to get back to managing the interface, you run the opposite command:

nmcli device set eth0 managed true

You can see the state of the various network interfaces on your machine (which Network Manager calls "devices") by typing nmcli devices:

$ nmcli device
DEVICE           TYPE      STATE         CONNECTION       
wlan0            wifi      connected     Mother Brain (66GHz) 
p2p-dev-wlan0    wifi-p2p  disconnected  --               
eth1             ethernet  unavailable   --               
enx00505b01d4d3  ethernet  unavailable   --               
eth0             ethernet  unmanaged     --               
lo               loopback  unmanaged     --            

nmcli usage

nmcli has excellent usage information, discoverable at the command line by using -h at any point. For example:

$ nmcli device set -h

Usage: nmcli device set { ARGUMENTS | help }

ARGUMENTS := DEVICE { PROPERTY [ PROPERTY ... ] }
DEVICE    := [ifname] <ifname> 
PROPERTY  := { autoconnect { yes | no } |
             { managed { yes | no }

Modify device properties.

If you have tab completion enabled — apt install bash-completion — nmcli's context sensitive completion is extremely useful. For example, if you don't remember the name of the device you wish to set, you can type nmcli device set and hit the TAB key twice to see all the possibilities. It's also a time and typo saver: on my machine I can type

nmcli device set enx

and when I hit tab it completes to:

 nmcli device set enx00505b01d4d3 
1

I'm afraid that that is not possible. The D-Bus API allows you to disable all kinds of wireless devices, but not the wired ones. The only way to disable wired connections is to disable all devices, including your wireless device.

Maybe it helps to untick the "Connect automatically" box for your wired device. That way NetworkManager won't automatically connect to it.

1
  • Maybe that was true in 2013, but since sometime since then there is a nmcli command to toggle the managed flag for individual interfaces without restarting NM. Commented Oct 13, 2021 at 21:38
0

This is what I found from nmcli man-pages. I don't know which distributions this applies, but I'm using Ubuntu 12.04 LTS

This will mark device to disconnect state so it's outside network-manager control

nmcli dev disconnect iface eth0 

This is fine as long as I don't disconnect the cable.

You can check device status with:

nmcli dev status

And currently active connections with:

nmcli con status

I created this helper script nm-manual-interface

#!/bin/bash

DEV=${1:-help}
shift

OPER=${1:-manual}
shift


if [ "$DEV" == "help" ]; then
echo -n "$0 "
  cat <<'EOH';
<DEV> [manual|auto]

Change <DEV> to disconnected state for nm.
In short take manual control of <DEV>.

All changes are temporary.

Usage:

Change to manual:
EOH
echo $0 eth0 manual
echo
echo Change back to nm control:
echo $0 eth0 auto
echo
  exit 1
fi
# store last uuid of device here
LASTUUIDFILE="/tmp/.nm-last-uuid-${DEV}"


if [ "$OPER" == "manual" ]; then
  if [ -n "$DEV"  ] ; then
    UUIDNET=$(nmcli con status |grep "$DEV" | perl -anle 'print @F[1]')
    if [ -n "$UUIDNET" ]; then 
      echo "$UUIDNET"  > $LASTUUIDFILE
      nmcli dev disconnect iface "$DEV"
    fi
  fi
fi

if [ "$OPER" == "auto" ]; then
  if [ -f "$LASTUUIDFILE" ]; then
     nmcli con up uuid $(cat "$LASTUUIDFILE") --nowait
     rm "$LASTUUIDFILE"
  else
    echo No last-state uuid file for iface "$DEV"
  fi
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .