Blocking IP Addresses with IPtables

Discussion in 'Site & Server Administration' started by digitome, Jan 24, 2008.

  1. #1
    I hope someone knows this answer to this, every day it seems i have to block new ips from trying to access my server via SSH using this:

    iptables -I INPUT -s 111.111.111.111 -j DROP

    What i would like to do is just block access to SSH for every IP except for mine, does anyone know how to do this?

    Thanks for your help
     
    digitome, Jan 24, 2008 IP
  2. boltok

    boltok Active Member

    Messages:
    257
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    78
    #2
    There are lots of things you can do to accomplish this. I use multiple methods, but iptables would definitely be the most effective one for you. You can exclude your own IP with '!', like this:

    iptables -I INPUT -s ! <your ip address/network> -p tcp --dport 22 -j DROP
    Code (markup):
    Some other suggestions to increase security:
    • Run SSH on a port other than 22
    • Disable direct root login
    • Use AllowUsers to limit the accounts that are allowed to login
    • Restrict password access and use SSH keys instead
    Hope that helps.
     
    boltok, Jan 24, 2008 IP
  3. digitome

    digitome Peon

    Messages:
    411
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you very much for your help
     
    digitome, Jan 25, 2008 IP