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

Notices


Reply
  Search this Thread
Old 01-18-2010, 12:34 AM   #1
aquiline
LQ Newbie
 
Registered: Mar 2005
Location: Cyberspace
Distribution: redhat
Posts: 20

Rep: Reputation: 0
Deny--Redirect--Subnets--iptables


Please share your expertise, here's my setup:

OS---Debian-5-(lenny)
Network-Interfaces:
eth0---(used for DHCP--leasing for Subnet-A and Subnet-B)
eth1---(for NATing..SNAT...DNAT..Masqurading..etc)
---
Subnets--(LAN-1)
Subnet-A1---10.10.64.0/18
Subnet-B2---10.10.128.0/18
----
Subnets---(LAN-2)
Subnet-A11---172.26.64.0/18
Subnet-B22---172.26.128.0/18
Query (?)
(1)
I want to deny Subnet-A to access Subnet-B (both subnets denied to access each other)?
(2)
to REDIRECT subnet-A1 (10.10.64.0/18) to another subnet-A11 (172.26.64.0/18) and as well redirect subnet-B2 to subnet-B22(10.10.128.0/18--->172.26.128.0/18)?
(3)
Deny all others. (to be more secure)
Caution!
I'm new to iptables, so please show few examples. What approach should be use..iptables..NATing..SNAT...DNAT..Masqurading...etc...What's most efficent solution, when Security, Reliability and high availablity is concerned.?
Thank you for your time.
 
Old 01-19-2010, 04:53 AM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
These subnets are all attached to the same interface on this box, right?

Please post the output of these two commands:
Code:
/sbin/ifconfig
Code:
/sbin/route
 
Old 01-19-2010, 05:35 AM   #3
aquiline
LQ Newbie
 
Registered: Mar 2005
Location: Cyberspace
Distribution: redhat
Posts: 20

Original Poster
Rep: Reputation: 0
Here's outputs.........
# ifconfig -a

eth0 inet addr:10.10.64.1 Mask:255.255.192.0
eth0:1 inet addr:172.26.64.1 Mask:255.255.192.0
----------
eth1 inet addr:10.10.128.1 Mask:255.255.192.0
eth1:2 inet addr:172.26.128.1 Mask:255.255.192.0
------------------------------------------------------
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.26.128.0 0.0.0.0 255.255.192.0 U 0 0 0 eth1
10.10.128.0 0.0.0.0 255.255.192.0 U 0 0 0 eth1
10.10.64.0 0.0.0.0 255.255.192.0 U 0 0 0 eth0
172.26.64.0 0.0.0.0 255.255.192.0 U 0 0 0 eth0
------------------------------------------------------------------------------
 
Old 01-19-2010, 09:56 AM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by aquiline View Post
Destination Gateway Genmask Flags Metric Ref Use Iface
172.26.128.0 0.0.0.0 255.255.192.0 U 0 0 0 eth1
10.10.128.0 0.0.0.0 255.255.192.0 U 0 0 0 eth1
10.10.64.0 0.0.0.0 255.255.192.0 U 0 0 0 eth0
172.26.64.0 0.0.0.0 255.255.192.0 U 0 0 0 eth0
Did you leave one line out of the output? Or does this box not have a gateway?

If what you want is to deny access between each of these two LANs, simply disable forwarding. If what you want is to deny traffic between two subnets on the same physical network (172.26.128.0 and 10.10.128.0, for example), then keep in mind that there's nothing other than non-root privileges to stop those hosts from contacting the other subnets directly, without the need to go through this box. You mentioned that you were concerned about security, so I want to make sure you're aware of this fact.
 
Old 01-19-2010, 11:21 PM   #5
aquiline
LQ Newbie
 
Registered: Mar 2005
Location: Cyberspace
Distribution: redhat
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Did you leave one line out of the output? Or does this box not have a gateway?
No, I haven't leave out any line, it's complete output, yes this box not have a gateway.

Quote:
to deny access between each of these two LANs, simply disable forwarding.
ok, now I have Disabled the ip forwarding.

Quote:
to deny traffic between two subnets on the same physical network (172.26.128.0 and 10.10.128.0, for example), then keep in mind that there's nothing other than non-root privileges to stop those hosts from contacting the other subnets directly, without the need to go through this box.
well its clear that subnets will not able to communicate "cross-subnets" (A--to--B or B--to--A etc).

Please also give example howto REDIRECT or Translate these subnets into different subnets:
(A) 10.10.64.0---->> into---->> 172.26.64.0
(B) 10.10.128.0---->> into---->> 172.26.128.0
so that users of Subnet 10.10.64.0 can use/share resources of 172.26.64.0?

thank you for time.
 
Old 01-20-2010, 12:06 AM   #6
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by aquiline View Post
(A) 10.10.64.0---->> into---->> 172.26.64.0
(B) 10.10.128.0---->> into---->> 172.26.128.0
To do SNAT for (A) you could do:
Code:
iptables -t nat -A POSTROUTING -o eth0 -s 10.10.64.0/18 -j SNAT --to-source 172.26.64.1
To do SNAT for (B) you could do:
Code:
iptables -t nat -A POSTROUTING -o eth0 -s 10.10.128.0/18 -j SNAT --to-source 172.26.128.1
The FORWARD rules might look like:
Code:
iptables -P FORWARD DROP
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o eth0 -s 10.10.64.0/18 -d 172.26.64.0/18 -m state --state NEW -j ACCEPT
iptables -A FORWARD -i eth1 -o eth1 -s 10.10.128.0/18 -d 172.26.128.0/18 -m state --state NEW -j ACCEPT
Of course, you'll need to re-enable forwarding.

BTW, I'm moving this to Networking so that it may gain better exposure. I'm kind of hoping that some of the LQ members who frequent that forum will chime in here and provide feedback as to whether or not doing this with iptables is a good idea (and/or to suggest a much better approach, which I suspect exists).

Last edited by win32sux; 01-20-2010 at 11:04 AM. Reason: I had accidentally left out the prefix lengths.
 
Old 01-20-2010, 03:10 AM   #7
aquiline
LQ Newbie
 
Registered: Mar 2005
Location: Cyberspace
Distribution: redhat
Posts: 20

Original Poster
Rep: Reputation: 0
Deny--Redirect--Subnets--iptables-[SOLVED]-Update#1

Dear win32sux;
Thank you very much for your kind help and examples of iptables. I am currently testing your solution, and it's working. Also I'm doing some experimenting to change few parameters.
Sure I'll add more to this thread later on and thanx for moving it to appropriate forum.
Quote:
hoping that some of the LQ members who frequent that forum will chime in here and provide feedback as to whether or not doing this with iptables is a good idea (and/or to suggest a much better approach, which I suspect exists).
HOPE for the Best.
Have a great time.
 
Old 01-20-2010, 11:02 AM   #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 aquiline View Post
Dear win32sux;
Thank you very much for your kind help and examples of iptables. I am currently testing your solution, and it's working. Also I'm doing some experimenting to change few parameters.
Sure I'll add more to this thread later on and thanx for moving it to appropriate forum.
Glad to be of service!
 
  


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
Help with iptables, 2 nic's + 2 subnets bilbod Linux - Networking 3 06-23-2009 12:58 AM
See subnets with OpenVpn/IpTables Niels@debian Linux - Networking 0 01-26-2008 10:56 AM
Applying iptables rules to multiple subnets eggi Linux - Networking 2 01-04-2006 10:29 PM
iptables block IP subnets bratch Linux - Networking 5 02-07-2005 02:03 AM
Using iptables to only allow certain subnets access ThePlague Linux - Networking 7 12-29-2004 11:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:46 AM.

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