Server Fault is a question and answer site for system and network administrators. 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

can anyone spot what is wrong with this? As soon as I run the script i'm locked out of my server and need to restart it. It's blocking ssh at a minimum. I'm using port 6789 for ssh.

Thanks for any help.

share|improve this question

According to the CentOS documentation, they say

IMPORTANT: At this point we are going to clear the default rule set. If you are connecting remotely to a server via SSH for this tutorial then there is a very real possibility that you could lock yourself out of your machine. You must set the default input policy to accept before flushing the current rules, and then add a rule at the start to explicitly allow yourself access to prevent against locking yourself out.

So you need to set INPUT to Allow. Flush the rules. Add your SSH ALLOW rule, then set INPUT to DROP. So in your case, you can probably change line 12 to ALLOW and move it up before you flush your rules, than at the very end of the script before you finalize everything, put $IPTABLES -P INPUT DROP.

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.