Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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 ./ to block and ./

share|improve this question

2 Answers 2

up vote 3 down vote accepted
$ cat
iptables -I INPUT -s -j DROP
$ cat
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.