Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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 192.168.8.20,another two system is 192.168.8.11 and 192.168.8.12, I want to block the ssh connection for 8.12, but I want to login from 192.168.8.11. and etc..

How can I do this?

share|improve this question

migrated from stackoverflow.com 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 192.168.8.12 (or specifically only allow it from 192.168.8.11).

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 192.168.8.12 -j DROP

This adds a rule to INPUT for TCP traffic aimed at your ssh port (22), that is coming from 192.168.8.12, 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

 
discard

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