LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-30-2003, 11:57 AM   #1
groovin
Member
 
Registered: Oct 2002
Distribution: RH 8
Posts: 83

Rep: Reputation: 15
iptables help


ive done some iptables before, but for some reason im having a problem right now trying to set something simple up...

all i want is to have nat forward www requests to x.x.x.x (eth0) to 192.168.25.4 so people can visit a web server behind the nat.

im using RH8, i have 3 nics in this machine...

eth0 with IP x.x.x.x
eth1 192.168.1.1 (not pluggin into anything)
eth2 192.168.25.1

the web server is at 192.168.25.4

i can ping the web server... i can access the webpage from the firewall. the iptables box can access the outside world and vice versa.

so im thinking htere must be something wrong with either my /etc/sysconfig/iptables or somethign else like my hosts file.

here are the configs:

-----/etc/sysconfig/iptables--------

# Generated by iptables-save on…
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0}
-A PREROUTING –d x.x.x.x –p tcp –m tcp --dport 80 –j DNAT --to-destination 192.168.25.4
-A PREROUTING –s 192.168.25.4/255.255.255.0 –j ACCEPT
-A PREROUTING –d 192.168.25.4/255.255.255.0 –j ACCEPT
-A POSTROUTING –s 192.168.25.4/255.255.255.0 –j MASQUERADE
-A POSTROUTING –s 192.168.25.4/255.255.255.0 –j ACCEPT
-OUTPUT –s 192.168.25.4/255.255.255.0 –j ACCEPT
-OUTPUT –d 192.168.25.4/255.255.255.0 –j ACCEPT

COMMIT
#...
#...
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT –s 192.168.25.4/255.255.255.0 –j ACCEPT
-A INPUT –d 192.168.25.4/255.255.255.0–j ACCEPT
-A FORWARD –d 192.168.25.4/255.255.255.0–j ACCEPT
-A FORWARD –s 192.168.25.4/255.255.255.0 –j ACCEPT
-A OUTPUT –d 192.168.25.4/255.255.255.0 –j ACCEPT
-A OUTPUT –s 192.168.25.4/255.255.255.0 –j ACCEPT
COMMIT

--/etc/hosts----------

127.0.0.1 localhost.localdomain localhost

-------------------------

# netstat -r shows what looks like a correct routing table as well.

any ideas? thanks

Last edited by groovin; 04-30-2003 at 12:01 PM.
 
Old 04-30-2003, 06:48 PM   #2
groovin
Member
 
Registered: Oct 2002
Distribution: RH 8
Posts: 83

Original Poster
Rep: Reputation: 15
bump
 
Old 04-30-2003, 07:20 PM   #3
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
You might need to specify the interfaces. To get forwarding to work with my webserver, I did the following:

In the NAT table:
-A PREROUTING -d XXX.XXX.XXX.XXX -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.0.2

And in the filter table, I have:
-A FORWARD -i eth0 -o eth1 -p tcp -m tcp --dport 80 -m state --state NEW,RELATED -j ACCEPT
-A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth1 -o eth0 -j ACCEPT


So substitute eth1 with eth2 and it should work. Also, you're not editing the actual /etc/sysconfig/iptables directly are you?
 
Old 05-01-2003, 10:48 AM   #4
groovin
Member
 
Registered: Oct 2002
Distribution: RH 8
Posts: 83

Original Poster
Rep: Reputation: 15
no, i am using iptables and iptables-save commands

ill give that a try and let u know how it works.. thanks!
 
Old 05-01-2003, 01:26 PM   #5
groovin
Member
 
Registered: Oct 2002
Distribution: RH 8
Posts: 83

Original Poster
Rep: Reputation: 15
it didnt work,

to test, i started apache on the firewall. then i stopped iptables, and tried to access x.x.x.x via a browser from a computer on a different network. i got to the page on the firewall ok, so then i started iptables back up, and refreshed the browser. ok so if i all went well, it should have fwd'd me to the real webserver behind the firewall... the browser sat there for a while and then replied an error message. so, because the web page on the firewall didnt show up, i can only assume that iptables is trying to do something with port 80 traffic.. but for some reason its not getting to the web server.

are there any other settings i should check?
 
Old 05-01-2003, 04:07 PM   #6
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
Flush all of the old rules in the NAT table and set it up like this:
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A PREROUTING -d xxx.xxx.xxx.xxx -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.25.4
-A POSTROUTING -o eth0 -j MASQUERADE

Some of those other NAT rules might be the problem. The above NAT rules work for the exactly same setup you have. Make sure to keep the 3 FORWARDING rules that I posted in the filter. You might also want to fireup tcpdump or ethereal and see directly what is happening to the packets. It sounds like they're being forwarded, but not getting back out properly or something. Also set the Apache log level to DEBUG and look at what's going on.
HTH
 
Old 05-01-2003, 05:47 PM   #7
groovin
Member
 
Registered: Oct 2002
Distribution: RH 8
Posts: 83

Original Poster
Rep: Reputation: 15
yeah, i flushed all the chains prior to adding the rules.

tcpdump on eth0 shows the request coming into the firewall...
but tcpdump on eth2 does not show the request passin onto the web server.
 
Old 05-01-2003, 09:33 PM   #8
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
Try changing your default OUTPUT policy to ACCEPT. It's usually easier to just filter out all the bad outgoing packets, rather than specifically specify which ones you want to allow out (it can be tricky to do it like that). I didn't catch it the first time I looked at your rules.
 
Old 05-02-2003, 10:14 AM   #9
groovin
Member
 
Registered: Oct 2002
Distribution: RH 8
Posts: 83

Original Poster
Rep: Reputation: 15
im starting to think there might be somethign wrong with something else besides iptables. ive tried a ton of different rules and the same problem each time.
 
  


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
An error occured getting IPtables status from the command /etc/rc.d/init.d/iptables s CrazyMAzeY Linux - Newbie 10 08-12-2010 05:25 AM
Iptables - Couldn't load target `ACCPET':/lib/iptables/libipt_ACCPET.so: z00t Linux - Security 3 01-26-2004 02:24 AM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
iptables book wich one can you pll recomment to be an iptables expert? linuxownt Linux - General 2 06-26-2003 04:38 PM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

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

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