I found this handy script online, and would like to modify it to only block SSH access but I don't know anything about iptables and Im afraid Ill kill my system as i have no physical access to it.
http://ipinfodb.com/ip_country_block_iptables.php
What should i change to only drop port 22 please?
I know hackers can use proxies etc and this won't be my only security. This reason for this is only to reduce the number of fail2ban emails i get about automated attacks from China :)
Thanks Maciej
You need the equivalent to this in your distro:
You are interested in the
geoip
module. Then add some rules to youriptables
.Check the 4th point in the HOWTO.
A simple walkthrough the example rules:
The above command adds a rule in the
INPUT
chain that uses thegeoip
module to match connections originating from a specific country, identified by its ISO 3661 code. In this case, A1 and A2 represent:This command uses the negation (
!
) to invert the match, resulting in all traffic not originating from the specified country (CA, in this case) being dropped:The last example shows you how create a custom chain in order to analyze traffic to your
sshd
server:As an alternative, you could filter any ssh traffic by using the
hosts.deny
file and then allow traffic from selected countries specifically by querying a shell script in thehosts.allow
file. See this tutorial: https://www.axllent.org/docs/view/ssh-geoip/