Score:0

Retrieving the name of a NetworkManager connection by its IPv4 subnet

ru flag

I have some CentOS7 servers with two IP addresses, in two different subnets (say 192.168.1.0/24 and 192.168.2.0/24). Some of the servers have two physical network connections, and different addresses are assigned to different devices using two distinct (NetworkManager's) connections:

nmcli connection add type ethernet con-name SUBNET1 ifname eth0 ip4 192.168.1.1/24 ...
nmcli connection add type ethernet con-name SUBNET2 ifname eth1 ip4 192.168.2.1/24 ...

I also have some scripts to dynamically set some properties of the connections, e.g.:

nmcli connection modify SUBNET2 +ipv4.routes "192.168.3.100 src=192.168.2.1"

The other machines in the cluster only have one physical network interface, and the addresses in the subnet 192.168.2.0/24 are assigned as an alias to eth0.

My hope was to use the existing scripts on all the machines in the cluster. Unfortunately, despite you can define two different connections using the same device, you cannot activate them together (i.e. they are not 'merged'). This is unfortunate because the conceptual separation of the two objects, with their respective properties, was a handful abstraction.

On these machines, I must define a new connection (e.g. 'SYSTEM') with bot addresses, i.e.

nmcli connection add type ethernet con-name SYSTEM ip4 192.168.1.x/24,129.168.2.x/24 ...

but since the scripts rely on the connection name ("SUBNET1" or "SUBNET2"), they wouldn't work here.

So the question is: How can I programmatically retrieve the name of connections with an address in a given subnetwork, so that I can turn the hardcoded connection name into a parameter?

P.S. to edit connection properties I'd prefer to use nmcli only, I'd rather not add routes using the ip command or by directly modifying the files in /etc/sysconfig/network-scripts/.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.