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/
.