I have simulated network latency with netem and It's great. Now I want to simulate unplugged network cable or when server goes down. I need this to make testing of my application easier and I couldn't find anything on the web that would help me. My servers are virtual CentOS instances and they are on Virtualbox. I want to do this from a php web page.
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
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: