How to make a TCP socket time out

sockettimeout

For network catastrophe simulations of our server environment, we are looking for a way to intentionally timeout a TCP socket. Are there any simple ways for existing sockets? Also, little C test-case program would be a plus.

We have already tried putting down network interfaces during TCP buffer reading, and reading from disconnected mounted resources (samba).

Out test server is Ubuntu 12.04.4.

Best Answer

To cause an exiting connection to timeout you can use iptables. Just enable a DROP rule on the port you want to disable. So to simulate a timeout for your Samaba server, while an active connection is up, execute the following on the server:

sudo iptables -A INPUT -p tcp --dport 445 -j DROP

The DROP target will not reply with a RST packet or ICMP error to the packet's sender. The client will stop receiving packets from the server and eventually timeout.

Depending on if/how you have iptables configured, you may want to insert the rule higher into the INPUT ruleset.

Related Question