How to simulate unplugged network cable or down server?
Just bring the interface down. For example, with eth0:
ip link set eth0 down
To bring the interface back up:
ip link set eth0 up
When using the top voted answer on a machine you are connecting via SSH, you will bring down the network and have no means of bringing it back up. The following is a way to bring it down and bring it back up while on a SSH connection.
Example using interface ens32
:
If you run:
ip link set ens32 down
And you are connecting through SSH, you will be unable to bring it up again since you have disabled your network and therefore cannot SSH to your server.
I use the following script to simulate 20 seconds of downtime:
#!/bin/sh
ip link set ens32 down
sleep 20
ip link set ens32 up
Save it as downtime.sh, make sure the file has execute rights, and then run:
sudo ./downtime.sh