LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 11-02-2015, 12:32 PM   #1
kingston
Member
 
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 215
Blog Entries: 1

Rep: Reputation: 21
Iptable rule to block outgoing ip addresses except some


Hi All

I don't want my server to communicate with other servers using SSH except some servers.

Please have a look at the following rule and let me know if this is correct.

Quote:
iptables -I OUTPUT ! -d 192.168.1.2,192.168.2.3,198.168.3.3 -p tcp --dport 22 -j REJECT
I hope ssh connection except the ip addresses mentioned in the rule will be blocked.
 
Old 11-02-2015, 02:54 PM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Have a look at this one;

Code:
iptables -I OUTPUT --dst-range ! 192.168.1.2,192.168.2.3,198.168.3.3 -p tcp --dport 22 -j REJECT
 
Old 11-03-2015, 02:40 AM   #3
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by lazydog View Post
Have a look at this one;

Code:
iptables -I OUTPUT --dst-range ! 192.168.1.2,192.168.2.3,198.168.3.3 -p tcp --dport 22 -j REJECT
Does this mean that all outgoing ssh connection are rejected, except those towards those ip addresses?
 
Old 11-03-2015, 03:21 AM   #4
kingston
Member
 
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 215

Original Poster
Blog Entries: 1

Rep: Reputation: 21
Hi Lazydog

"--dst-range" is not working. I think i have to go with the "ipset" option
 
Old 11-03-2015, 05:57 AM   #5
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Note that while port 22 is the default, there is no guarantee that port 22 will be used. OK, you can easily argue that it could be way better than nothing for preventing ssh to 'random' servers, if there is a case that the remote SSH box could be under the command of one of your users, then they could change that port to almost anything (and then any 'port 22 based' blocking would fail).

(Changing the ssh port is also used as a 'security measure'; I don't think it is too controversial to say that, on its own, it is a poor security measure, but it does mean that there is a population of boxes where a non-default port is used for entirely legitimate, if often poor, reasons.)
 
Old 11-04-2015, 12:34 PM   #6
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by kingston View Post
Hi Lazydog

"--dst-range" is not working. I think i have to go with the "ipset" option
Try moving the "!" before the --dst-range to ensure it is not working.
 
Old 11-07-2015, 06:19 AM   #7
kingston
Member
 
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 215

Original Poster
Blog Entries: 1

Rep: Reputation: 21
Hi All

I have achieved blocking multiple ip addresses using IPSET

Quote:

Reference Link :
http://www.linuxjournal.com/content/...urations-ipset

RPM Installed:
ipset-6.11-4.el6.x86_64

ipset -N myset iphash
ipset -A myset 1.1.1.1
ipset -A myset 2.2.2.2
iptables -A INPUT -m set --set myset src -j DROP
iptables -A OUTPUT -m set --set myset dst -j DROP
 
Old 11-09-2015, 12:34 PM   #8
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Question

Quote:
Originally Posted by lazydog View Post
Have a look at this one;

Code:
iptables -I OUTPUT --dst-range ! 192.168.1.2,192.168.2.3,198.168.3.3 -p tcp --dport 22 -j REJECT
I've never seen the "!" used before for an IPTables ruleset. Looking at the man page, this will invert on the dst-range, which normally would match destination IPs in the specified range.

So with the "!", it would mean that we would ignore the range of 192.1681.2, 192.168.2.3, 198.168.3.3 ?

thanks
 
Old 11-10-2015, 09:44 AM   #9
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by JockVSJock View Post
I've never seen the "!" used before for an IPTables ruleset. Looking at the man page, this will invert on the dst-range, which normally would match destination IPs in the specified range.

So with the "!", it would mean that we would ignore the range of 192.1681.2, 192.168.2.3, 198.168.3.3 ?

thanks
The "!" equals NOT, so yes we would ignore 192.168.1.2, 192.168.2.3 and 192.168.3.3
 
  


Reply



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
writing an iptable rule bassplayer Linux - Newbie 4 08-13-2014 06:08 AM
[SOLVED] iptable rule amartlk Linux - Newbie 2 12-18-2011 10:36 PM
iptable how many rule iptable can manage toure32 Linux - Networking 1 05-13-2010 04:34 AM
iptable rule vinaytp Linux - Newbie 1 10-26-2009 01:39 AM
[SOLVED] ipTables rule to block a port for all internal IP Addresses except one pranaysharmadelhi Linux - Security 8 07-08-2009 07:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:00 PM.

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