Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to block a ssh connection from particular IP address. for example: my system IP address is,another two system is and, I want to block the ssh connection for 8.12, but I want to login from and etc..

How can I do this?

share|improve this question

migrated from Aug 20 '10 at 1:26

This question came from our site for professional and enthusiast programmers.

2 Answers 2

The simplest and best solution would be "Using whatever firewall you happen to be using". Just block access to port 22 from (or specifically only allow it from

If you don't currently have a firewall setup, then you may want to look into iptables, which comes as part of the linux kernel. There's a tutorial here. There's also quite a few GUI interfaces for it.

The specific command you want to do what you've described above is:

# iptables -A INPUT -p tcp --dport ssh -s -j DROP

This adds a rule to INPUT for TCP traffic aimed at your ssh port (22), that is coming from, and drops it.

share|improve this answer

If you have tcpwrappers installed, then you can put an entry in to hosts.deny. Read the man page for hosts.deny for details.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.