Context
I am working on Centos 7 and I have a network interface eth0 configured with multiple fixed IP addresses (I am only concerned about the IPv4 addresses here, I do not care what happens to the IPV6 one) :
$ ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:bf:83:39 brd ff:ff:ff:ff:ff:ff
inet 192.168.220.92/24 scope global eth0:311
valid_lft forever preferred_lft forever
inet 192.168.220.82/24 scope global secondary eth0:312
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:febf:8339/64 scope link
valid_lft forever preferred_lft forever
These addresses are automatically affected by some software so I do not have a handle on either their IP value (192.168.220.92), their alias name (eth0:311), or the order in which they are affected (primary/secondary).
Objective
What I want is a way to temporarily disable 192.168.220.92 while keeping 192.168.220.82 up and running.
Then I need a way to turn 192.168.220.92 back online still without interfering with 192.168.220.82.
Attempts
What I tried so far (with no success, or I wouldn't be here) :
I tried several
ifconfigcommands with no success and read that those were deprecated anyway, so I focused onipcommands instead.Turn the virtual interface down with
ip link set eth0:311 down. This removes all addresses on this interface:
$ ip a
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:50:56:bf:83:39 brd ff:ff:ff:ff:ff:ff
- Remove the IP only with
ip addr del 192.168.220.94/24 dev eth0:311. This removes all IPv4 addresses on this interface:
$ ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:bf:83:39 brd ff:ff:ff:ff:ff:ff
inet6 fe80::250:56ff:febf:8339/64 scope link
valid_lft forever preferred_lft forever
- Removing 192.168.220.84 only with method 3) works (it keeps 192.168.220.92), but this is not what I need, so I started looking for a way to swap primary and secondary IP addresses but couldn't find any. The most relevant post I found was this one which concluded it was not possible...