Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 08-14-2012, 05:11 PM   #1
Registered: Apr 2010
Location: India /Hyderabad
Distribution: RedHat, CentOS
Posts: 273

Rep: Reputation: 1
block ssh in iptables accept for group of ips


i want to block my servers ssh access to all except few ips say, 5 ips. usually i do like

# iptables -I INPUT -p tcp --dport 22 -j REJECT

and allow my ips

# iptables -I INPUT -p tcp -s --port 22 -j ACCEPT
# iptables -I INPUT -p tcp -s --port 22 -j ACCEPT
# iptables -I INPUT -p tcp -s --port 22 -j ACCEPT

any simple rule not wrinting rule for each ip , i know using ! except in iptables as below

# iptables -I INPUT ! -s --dport 22 -p tcp -j REJECT

issue with above rule is it will allow only one ip and blocks rest ...
please give me simple rule to full fil my need.

thank you.
Old 08-14-2012, 10:02 PM   #2
Registered: May 2008
Location: Toronto
Distribution: Centos && Debian
Posts: 347

Rep: Reputation: 34
IPSet is the way to go. You can create set of networks/ IP address and allow/block them as per your needs. Click the link for IPset IPSet



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Block bitmap for group 416 not in group (block 0) + group descriptors corrupted? quanta Linux - Server 1 12-08-2010 11:40 AM
how do i get full ssh block accept my ip adresses R03L Linux - Networking 8 04-23-2009 04:15 AM
How to block several IPs in one command using iptables? Ashkan_s Linux - Software 1 08-20-2008 05:30 PM
iptables: how to block IPs by country or registry mlnutt Linux - Security 4 09-14-2007 01:22 PM
i want to block a range of ips using iptables... Vasili Linux - Security 18 09-19-2006 07:31 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration