Skip to content

Instantly share code, notes, and snippets.

@GeorgeDewar
Last active August 29, 2015 13:56
Show Gist options
  • Save GeorgeDewar/9064445 to your computer and use it in GitHub Desktop.
Save GeorgeDewar/9064445 to your computer and use it in GitHub Desktop.
Simulates network disconnection over SSH by dropping all traffic to/from any host other than the host calling the script
#!/bin/bash
#Determine IP of calling user
ssh_ip=`echo $SSH_CLIENT | awk '{ print $1}'`
if [ "$1" == "kill" ]; then
echo "Simulating network disconnection by dropping traffic from all hosts except $ssh_ip..."
#Default Policy to DROP all incoming traffic
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT DROP
#Allow traffic from/to calling IP
sudo iptables -A INPUT -s $ssh_ip -j ACCEPT
sudo iptables -A OUTPUT -d $ssh_ip -j ACCEPT
elif [ "$1" == "resume" ]; then
echo "Resuming network connectivity..."
sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
else
echo "$0 simulates network disconnection over SSH by dropping all traffic to/from any host other than the host calling the script over SSH"
echo
echo "Usage: $0 <kill/resume>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment