This is a relatively simple trick, but one that I thought was rather clever.
I needed to SSH into a target server (172.16.4.1) that only allowed connections from a specific IP address (172.16.4.10). I knew that the system holding that specific IP address was down, yet I still needed to SSH into the target.
To further complicate matters, I did not have physical access to the target network at the time. But, I did have remote access (and root) to another Linux box on the network.
Hmmm…
So, all I needed to do was change the IP address of my one good box to the one expected by the target system, but if I changed the IP address on the main interface, then I would disconnect myself.
Enter virtual interfaces and routing.
I created a new virtual interface with ifconfig (assuming 172.16.4.10 is the IP we want to come from):
/sbin/ifconfig eth0:1 172.16.4.10
This does not, however, mean that my SSH connection will come from this address, so I needed to change the routing table (assuming 172.16.4.1 is what we want to connect to):
/sbin/route add -host 172.16.4.1 eth0:1
Now, I will effectively be coming from my new interface when I connect to the target server.