Monday, January 23, 2017

Linux Network Manager Manual Commands

I have a love/hate relationship with the Linux NetworkManager daemon.  It usually works and keeps your laptop PC network connections going smoothly when you move around, but it gets in the way when one does network tests and system integration using a laptop PC.

Each time you plug a cable in, or turn an embedded system off/on, NetworkManager restarts the connection and you can then lose your static IP address setting, which gets tiring really quickly in a lab setup.

Usually, I completely disable NetworkManager and assign a static IP address to my machine on a laboratory bench with a script in /usr/local/bin called static:

#! /bin/bash
echo Configure network for PDLU access

# Disable the Network Manager
systemctl disable NetworkManager.service
systemctl stop NetworkManager.service

# Set static IP address
ifconfig em1 192.168.111.1 netmask 255.255.255.0 up

# Set multi casting route
route add -net 224.0.0.0 netmask 240.0.0.0 dev em1

# Open up the firewall
iptables -F

# Show setup
ifconfig
route


and when I get back to a desk, I set things back to normal with a script called dynamic:

#! /bin/bash
echo Configure network normally

# Disable the Network Manager
systemctl enable NetworkManager.service
systemctl restart NetworkManager.service
sleep 1

# Set multi casting route
route add -net 224.0.0.0 netmask 240.0.0.0 dev em1

# Show setup
sleep 1
ifconfig
route


Sometimes NetworkManager gets confused and the Aplet ends up spinning forever, trying to bring up a non-existent interface.

The way to fix these kind of issues is to invoke the command line program nmcli:

# nmcli connection show active
NAME                UUID                                  DEVICES      DEFAULT  VPN  MASTER-PATH
Wired connection 1  34111952-8271-4f64-a616-a6cd5899bae2  vboxnet0     no       no   --         
Wired connection 2  9dd23ba2-3378-4657-96bb-3b687cfe0180  enp0s29u1u2  yes      no   --       


Disable the errant interface:
# nmcli connection down id "Wired connection 1"

and finally delete it altogether:
# nmcli connection delete id "Wired connection 1"

This way I have a quiet GUI again without the irritating spinning widget in the corner.

La voila!

Herman

No comments:

Post a Comment

On topic comments are welcome. Junk will be deleted.