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

Suppose you are on linux internet gateway/router. What would you do to block a client with specific IP using bash script. I prefer something like ./block_client.sh to block and ./unblock_client.sh

share|improve this question
up vote 3 down vote accepted
$ cat block_client.sh
iptables -I INPUT -s -j DROP
$ cat unblock_client.sh
iptables -D INPUT -s -j DROP
share|improve this answer
The IP block will not survive a reboot unless they are saved on update and restored on boot. look up iptables-save and iptables-restore. On Redhat like systems, you can get away with a simple "/etc/init.d/iptables save". – Shawn Chin Aug 23 '10 at 14:13

You might want to deploy something like apf which you'll be able to execute apf -d and apf -u to block and unblock respectively. In addition APF keeps it's blocks list local and will insert them into the iptables on each reboot.

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.