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 06-05-2006, 05:24 PM   #1
xxrsc
LQ Newbie
 
Registered: Nov 2005
Posts: 11

Rep: Reputation: 0
iptables firewall rule question


I have a Fedora machine set up with a wireless card that accesses wireless router. This ip address is 192.168.0.1 range. This machine also has a NIC with ip address range 172.16.0.0. This NIC is connected to a switch in which other Windows machines are connected with the 172.16.0.0 range. With ip masquerade/NAT set up these machines have no problem accessing the internet as well as machines on the 192.168.0.0 side. But I can't access the 172.16.0.0 machines from the 192.168.0.0 side.

So after reading some stuff about iptables and rules, with my limited knowledge of networking, I would like some help on how to allow only say 192.168.0.3 to access 172.16.0.6. Hopefully I am making some sense here.
 
Old 06-05-2006, 07:27 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
On all your 192.168.0.0/24 machines (except wireless router and the fedora machine) make a route for the 172.16.0.0 network pointing to the fedora machine. Enable forwarding on the fedora machine. See if it works with flushed (clean slate) iptables. If so, see if it works with the current iptables. If not, post back with your iptables script, and we'll see what the problem is.
 
Old 06-05-2006, 07:48 PM   #3
xxrsc
LQ Newbie
 
Registered: Nov 2005
Posts: 11

Original Poster
Rep: Reputation: 0
I should have mentioned that the 192.168.0.0 side has a route. I can ping 172.16.0.1 which is the internal NIC on the Fedora box. But I can't ping past it. So I figure the Fedora box is dropping those pings/packets that are outgoing from the 172.16.0.1 NIC. Anyway here's part of the script. Thanks for the help.



echo " Clearing any existing rules and setting default policy.."
$IPTABLES -P INPUT ACCEPT
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
$IPTABLES -t nat -F

echo " FWD: Allow all connections OUT and only existing and related ones IN"
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT
$IPTABLES -A FORWARD -j LOG

echo " Enabling SNAT (MASQUERADE) functionality on $EXTIF"
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE
 
Old 06-05-2006, 07:52 PM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
one question: are you willing to use DNAT to do it??

also, what's your output of "/sbin/route -n" look like??

Last edited by win32sux; 06-05-2006 at 08:03 PM.
 
Old 06-05-2006, 08:04 PM   #5
xxrsc
LQ Newbie
 
Registered: Nov 2005
Posts: 11

Original Poster
Rep: Reputation: 0
I'm not familiar with DNAT. What are the advantages and/or drawbacks?
 
Old 06-05-2006, 09:51 PM   #6
xxrsc
LQ Newbie
 
Registered: Nov 2005
Posts: 11

Original Poster
Rep: Reputation: 0
Results of route -n


Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 wlan0
 
Old 06-06-2006, 06:41 PM   #7
xxrsc
LQ Newbie
 
Registered: Nov 2005
Posts: 11

Original Poster
Rep: Reputation: 0
Any ideas?
 
Old 06-06-2006, 07:28 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 xxrsc
Any ideas?
here's one idea you could try:
Code:
echo "0" > /proc/sys/net/ipv4/ip_forward

$IPTABLES -F
$IPTABLES -F -t nat
$IPTABLES -F -t mangle

$IPTABLES -X
$IPTABLES -X -t nat
$IPTABLES -X -t mangle

$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD DROP

$IPTABLES -A FORWARD -m state --state \
ESTABLISHED,RELATED -j ACCEPT

$IPTABLES -A FORWARD -i $INTIF -o $EXTIF \
-m state --state NEW -j ACCEPT

$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -s 192.168.0.0/24 \
-d 172.16.0.0/24 -m state --state NEW -j ACCEPT

$IPTABLES -A FORWARD -j LOG --log-prefix "FORWARD DROP: "

$IPTABLES -t nat -A PREROUTING -i $EXTIF \
-d 192.168.100.6 -j DNAT 172.16.0.6

$IPTABLES -t nat -A PREROUTING -i $EXTIF \
-d 192.168.100.7 -j DNAT 172.16.0.7

$IPTABLES -t nat -A PREROUTING -i $EXTIF \
-d 192.168.100.8 -j DNAT 172.16.0.8

$IPTABLES -t nat -A PREROUTING -i $EXTIF \
-d 192.168.100.9 -j DNAT 172.16.0.9

$IPTABLES -t nat -A PREROUTING -i $EXTIF \
-d 192.168.100.10 -j DNAT 172.16.0.10

# Etc, etc, etc...

$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
echo "1" > /proc/sys/net/ipv4/ip_forward
this should allow the boxes on 192.168.0.0/24 to connect to the boxes on 172.16.0.0/24, by having them connect to a respective 192.168.100.0/24 address, which would be an aliased IP on $EXTIF... the destination address of 192.168.100.0/24 on the packets coming from the 192.168.0.0/24 network would get *translated* (DNAT = destination network address translation) into destinations in the 172.16.0.0/24 network...

just my ...

Last edited by win32sux; 06-06-2006 at 07:38 PM.
 
Old 06-07-2006, 02:57 PM   #9
xxrsc
LQ Newbie
 
Registered: Nov 2005
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks. When I get some free time I'll work with it and see what happens.
 
  


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
Question about IPtables/firewall rules ilan1 Linux - Security 3 02-20-2006 11:58 PM
Question about a iptables rule? rjw1678 Linux - Security 2 11-18-2005 07:46 AM
Firewall question - stumped by 1 rule! thekillerbean Linux - Networking 4 08-27-2005 01:59 AM
Iptables question? What is this? :RH-Firewall-1-INPUT - [0:0] abcampa Linux - Security 3 05-09-2005 12:44 PM
firewall/iptables question iceman47 Linux - Networking 4 12-19-2002 02:37 PM

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

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