1

I need to set up an ethernet connection to a LIDAR, the steps to do so are:

Without the sensor connected to PC

sudo ip addr add 10.5.5.1/24 dev enp12s0

where enp12s0 is the name of my computers ethernet network interface, found by ifconfig.

Then connect the sensor and

sudo ip link set enp12s0 up
sudo dnsmasq -C /dev/null -kd -F 10.5.5.50,10.5.5.100 -i enp12s0 --bind-dynamic

I was curious if I could automate this? I have tried changing the netplan yaml config file, as well as adding wired connection types through gnomes network interface gui. But I can't seem to get it working.

My hope is to be able to make a profile where I can click on the wired connections in gnome and select this instead of having to redo the above steps all the time. How would I go about doing this?

Note: this is for ubuntu 20.04 LTS.

2
  • Do you use enp12s0 for other connections as well or is it sufficient to run a configuration script when the interface is brought up?
    – frippe
    Commented Oct 19, 2021 at 14:05
  • It's the laptops main Ethernet port, I do use it for other things so I'd like to maintain the possibility. I think this is why I was drawn to the connection profiles that gnome displays in the wired connection settings. Commented Oct 20, 2021 at 8:22

1 Answer 1

0

There may be more elegant ways to do it, but you could write a script for NetworkManager-dispatcher to trigger on connection change.

The dispatcher will give the interface and event as input and also sets up some convenient environment variables for you to use.

A minimal "working" example would be something like this:

/etc/NetworkManager/dispatcher.d/<script_name>

#!/bin/sh

interface="$1"
action="$2"

interfacename=enp12s0
uuid="<uuid of the desired connection>"

if [ "$action" = "up" ] && [ "$interface" = "$interfacename" ] && [ "$CONNECTION_UUID" = "$uuid" ]; then
    # Do your thing
fi

Obviously, you can undo any changes in a similar fashion when disabling the connection/profile.

Make sure the permissions are correct (not world-writable etc.) and that it's owned by root.

I haven't tested which events are fired when changing the wired profile, but at least changing wireless network will fire a connectivity-change followed by a down with CONNECTION_UUID set to the old network, followed by an up with CONNECTION_UUID set to the new network.

8
  • how do i then enable this bash script for use by the network manager? Or is this the case by default Edit: Also, by "do your thing" you mean the previously mentioned lines for setting up the connection? Because some of the commands I mentioned need to be executed before the connection, so setup the port. How can this be handled here. Commented Oct 20, 2021 at 11:44
  • All you do before bringing the interface up in your question is adding an IP address to it, and that you can do to an interface that's already up. That said, there's also the pre-up event. The dispatcher will automatically pick up scripts in specific locations (e.g., /etc/NetworkManager/dispatcher.d/). Check out the NetworkManager manpage for details
    – frippe
    Commented Oct 20, 2021 at 12:06
  • How can i check for the UUID or an ethernet connection? Commented Oct 22, 2021 at 7:22
  • NetworkManager stores the connections under /etc/NetworkManager/system-connections/. In those files you'll find the uuid of the connections.
    – frippe
    Commented Oct 22, 2021 at 7:36
  • Great, and regarding permissions. 755 is fine? Commented Oct 22, 2021 at 7:47

You must log in to answer this question.

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