Changing a Linux or Cumulus Switch IP Address Remotely Without Losing SSH Connectivity

Changing a Linux or Cumulus Switch IP Address Remotely Without Losing SSH Connectivity

When re-addressing a remote Linux host or Cumulus Linux switch in-band over SSH, deleting the primary IPv4 address immediately drops your session. By adding the new IP as a secondary address and enabling kernel promote_secondaries, the secondary IP seamlessly becomes primary when the old address is removed:

First you have to add a secondary IP address to the interface,  and confirm like so:

bash
ip addr add 192.168.1.10/24 dev eth0
ip addr show eth0
cli
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
link/ether 44:38:39:00:11:aa brd ff:ff:ff:ff:ff:ff 
inet 192.168.1.5/24 scope global eth0 
inet 192.168.1.10/24 scope global secondary eth0

 

Now we have to setup the interface to where it will promote the secondary IP address when we remove the first like so:

cli
echo 1 > /proc/sys/net/ipv4/conf/eth0/promote_secondaries

or

cli
sysctl net.ipv4.conf.eth0.promote_secondaries=1

** PRO-TIP: Change eth0 to all to have it work on all interfaces.

Lastly we need to remove the original IP address and confirm like so:

bash
ip addr del 192.168.1.5/24 dev eth0
ip addr show dev eth0
cli
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 44:38:39:00:11:aa brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 scope global eth0

 

The interface is now running on the new primary IPv4 address without dropping active TCP/SSH sessions.

>_ Engineering Discussion 2 Comments

+ Add Field Note ↓
  1. Chaining ifreload -a inside a detached nohup bash -c "..." & subshell is the gold standard for remote management IP migrations on Cumulus Linux when out-of-band console isn't reachable.

  2. Even better with NCLU/NVUE on newer Cumulus releases, but on 2.5/3.x editing /etc/network/interfaces and triggering ifreload -a in the background is still the safest way not to saw off the branch you're sitting on.

Leave a Technical Comment

Share CLI tips, hardware notes, or questions below. Inline backticks (`command`) are supported.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Engineering Notes