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 07-19-2010, 03:55 PM   #1
Jz87
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Rep: Reputation: 0
Allow internal ips block external ips


Im running Centos 5.4 with a sftp server, and I´d like to allow all 172.16.0.x ip and 192.168.0.x ip and block everything else.

Does someone have a good way to do this with IPTables or any other opensource FW?

Thanks !
 
Old 07-19-2010, 03:58 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
The networks you mentioned are RFC1918 private IP space. They are not routable across the 'net. In order for inbound traffic to reach you, some externally-facing device must be providing NAT/PAT.

So, don't provide NAT/PAT, and keep your border devices and hosts secure.

If you have more questions, please describe your network more thoroughly.
 
Old 07-19-2010, 04:03 PM   #3
Jz87
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Original Poster
Rep: Reputation: 0
thanks for quick reply.
Exaclly, it´s a lab enviorment and I just wan´t to block everything else except those internal IPs.
 
Old 07-19-2010, 04:04 PM   #4
Jz87
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Original Poster
Rep: Reputation: 0
And forgot to mension we do use NAT
 
Old 07-19-2010, 04:08 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
You can open it up to your internal subnets, but remember that in doing so you'll also be allowing the internal IP for your NAT device (for the sake of argument, let's call it 192.168.0.1). You might consider allowing stateful traffic, but dropping inbound requests from 192.168.0.1.
 
Old 07-19-2010, 04:20 PM   #6
Jz87
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Original Poster
Rep: Reputation: 0
that sounds like a good idea, how would you do that in a good way ?
 
Old 07-19-2010, 04:31 PM   #7
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Ideally, you have packet filtering at the switch level to handle this. (Or somewhere between you and the NAT device.)

Alternatively, your NAT device does the packet filtering.

Or, you have host-level firewalls in place for all your private network workstations. (That may get unwieldy.)
 
Old 07-19-2010, 05:14 PM   #8
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by Jz87 View Post
Im running Centos 5.4 with a sftp server, and I´d like to allow all 172.16.0.x ip and 192.168.0.x ip and block everything else.

Does someone have a good way to do this with IPTables or any other opensource FW?
That could be done like (example):
Code:
iptables -P INPUT DROP
iptables -A INPUT -m state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p TCP --dport 22 -s 172.16.0.0/24 -m state NEW -j ACCEPT
iptables -A INPUT -p TCP --dport 22 -s 192.168.0.0/24 -m state NEW -j ACCEPT
Change the destination port number to whichever you've got your daemon listening on. Also, keep in mind that if someone cracks a host on your LAN (and obtains root privileges) they can spoof any IP.

Quote:
Originally Posted by anomie View Post
You can open it up to your internal subnets, but remember that in doing so you'll also be allowing the internal IP for your NAT device (for the sake of argument, let's call it 192.168.0.1). You might consider allowing stateful traffic, but dropping inbound requests from 192.168.0.1.
Could you elaborate as to the reason you'd be blocking the router's IP? Just curious.

Last edited by win32sux; 07-19-2010 at 06:48 PM. Reason: Removed unnecessary iptables command.
 
Old 07-19-2010, 05:43 PM   #9
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
I was envisioning something similar to:

Code:
            ----------
           ( internet )
            ----------
                |
                |
            ------------
           | NAT device |
            ------------
                |
                |
             ----------
            | bridged  |
            | firewall |
             ----------
                |
                |
            ------------
           | switch for |
           | internal   |
           | hosts      |
            ------------
                |
             ........
The NAT device should never be making unsolicited connections attempts to any of the internal hosts. (All inbound traffic should be part of a stateful session.)
 
Old 07-19-2010, 06:24 PM   #10
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by anomie View Post
The NAT device should never be making unsolicited connections attempts to any of the internal hosts.
I agree. And in your diagram, this sort of thing can be effectively enforced, given the bridged firewall you placed there. If you remove the bridged firewall, however, things get a bit difficult, as a bad guy which manages to own the router will be able to use any IP or MAC he/she wishes. This may or may not be a concern in this case, but it's something I think the OP should keep in mind.
 
Old 07-19-2010, 09:42 PM   #11
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
TBH, I'm probably over-complicating things for the purposes of this thread. A NAT + firewall host is "good enough" for many situations.
 
  


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
Internal IPs and DNS danielakkerman Linux - Networking 1 02-03-2009 01:26 PM
How to ban IPs from Internal ? ThanhDuongCong Linux - Networking 6 11-21-2008 12:24 AM
Getting things straight: Apache, SSL, Multiple External IPs / Internal IPs robin.com.au Linux - Server 21 10-13-2007 11:39 PM
block all IPs except one how in my setup?? cranium2004 Linux - Networking 3 03-20-2005 03:24 PM
how to define a specific range of IPs and/or multiple IPs in an iptables rule?... TheHellsMaster Linux - Security 9 09-20-2004 10:06 AM

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

All times are GMT -5. The time now is 07:05 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