Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 5 down vote accepted

I assume you mean that your network cable is unplugged. You didn't specify.

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
share|improve this answer
thank you ,I'm reading about it here – SafeY Apr 6 '13 at 8:36
that's working successfully but ip link set eth0 up is not working :( and I need them both – SafeY Apr 6 '13 at 8:46
@NancySmith "Is not working" is not meaningful. What error messages occur? Did you assign an IP and netmask? – Chris Down Apr 6 '13 at 8:59
I mean that I used ip link set eth0 down via php and ping shows that my server is unreachable . then I wanted to get it back "up" , I executed ip link set eth0 up via php and server still down . – SafeY Apr 6 '13 at 9:05
@NancySmith Create another network interface that does not have access to whatever it is connecting to (using routes, etc). SSH to the host using that interface. Bring down the interface that you are not connecting to SSH through. – Chris Down Apr 6 '13 at 10:22

On your virtualbox console window, you should have a Machine menu pull down. Under that one there are several actions. One of which is Power off. You need to select that one for an immediate power down. This is the closest thing to yanking the power cord of a physical server.

share|improve this answer
I want to do this from a web page . surly I know how to power off machines . – SafeY Apr 6 '13 at 8:22
and I don't want to fake it . not really shut down and boot it again . – SafeY Apr 6 '13 at 8:23
Judging by the mention of netem, I assume the question is really about unplugging the network cable from a server, and not the power cable (although it is not clear). – Chris Down Apr 6 '13 at 8:28
I will edit my question to make it more clear , thanks – SafeY Apr 6 '13 at 8:33

The following is an 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:

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.