LinuxQuestions.org
Visit Jeremy's Blog.
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 12-18-2009, 07:11 PM   #1
Phunction
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Rep: Reputation: 0
iptables help


Hi,
I have a debian box setup as a gateway/firewall using iptables, and a second box to run a web site.

The rules work fine and everything is working.

What I would like to do is to be able to preserve the original ip address of the visitor going to the web server, for log stats, etc. Right now the ip address is always the ip of the gateway/firewall box.

I googled around and it mentions something about using MARK?

Does someone have a howto the can send me to that describes doing this?

Thanks
 
Old 12-18-2009, 07:31 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555
http://www.bec.at/support/iptables-tutorial/index.html

Sections 10.3.10 and 11.8 at the above link should explain the MARK functionality for you.

Sasha

PS - Welcome to LQ
 
Old 12-19-2009, 10:57 AM   #3
Phunction
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Strange

I looked through that, but it seems to mostly talk about load balancing and splitting isp connections.

There must be a simple example out there for this, I can't believe I am the only one with a setup like this?

Linux firewall box
Linux web box

Simply want originating ip address passed to web box. Seems like a reasonable and common thing to me.
 
Old 12-19-2009, 11:48 AM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
It sounds like you're doing SNAT for inbound packets (typically it's only done for outbound ones). Otherwise, the original source IP addresses on the packets should remain. Please post the output of this from the gateway/firewall:
Code:
iptables -nvL -t nat

Last edited by win32sux; 12-19-2009 at 11:51 AM.
 
Old 12-19-2009, 12:09 PM   #5
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555
And actually, regardless of what's happening to the incoming traffic, I would think that a "LOG" target as the first action on the incoming traffic at the firewall box, would accurately record the incoming IP. You could further log the masquerade/DNAT/SNAT traffic rules, so you could if you really wanted to, track what IP's traffic went where.

MARK is often used for marking traffic so that something like a shaper can identify it, though probably other reasons too, but I'm not really sure you need MARK for what you're trying to do.

Anyhow, as Win32sux wrote, posting that output may clarify things.

Sasha
 
Old 12-19-2009, 02:05 PM   #6
Phunction
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Setup

To re-clarify.

I have 2 seperate linux boxes, one for the firewall/gateway and one for the web server.

I need the originating ip address kept in-tact for the web server.

To get traffic from the firewall to the web server I do this:

$IPTABLES -A FORWARD -i $INET_IFACE -o $INET_IFACE2 -p tcp --dport 80 -d 192.168.1.100 -j ACCEPT
$IPTABLES -t nat -A PREROUTING -i $INET_IFACE -p tcp -dport 80 -j DNAT --to 192.168.1.100

$INET_IFACE is eth0 going the the internet
$INET_IFACE2 is eth1 connecting to the network that has the web server.

This works, but DNAT of course re-writes the incoming ip address from the internet before it is sent to the webserver, so the webserver only sees the ip address assigned to eth1 on the gateway.

Is there another way? The only thing I found so far that is supposed to preserve the ip address as it passes through the firewall is to use the MARK option and a routing table.
 
Old 12-19-2009, 03:10 PM   #7
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by Phunction View Post
This works, but DNAT of course re-writes the incoming ip address from the internet before it is sent to the webserver, so the webserver only sees the ip address assigned to eth1 on the gateway.
DNAT only changes the destination IP. It has nothing to do with the source IP which the server sees. Could you post the requested output please, so that we may see what's going on in your NAT table?
 
Old 12-19-2009, 04:59 PM   #8
Phunction
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Output

Shoot , I should have done that to begin with. It turns out I had a snat in my iptables config that was messing things up.

Well, thanks for the help. It is doing what I wanted now.
 
Old 12-19-2009, 05:02 PM   #9
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by Phunction View Post
It turns out I had a snat in my iptables config that was messing things up.

Well, thanks for the help. It is doing what I wanted now.
Glad you worked things out. HTH.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
On what basis CHAIN integer values are generated in IPtables under iptables file? haariseshu Linux - Server 3 11-05-2009 04:25 AM
[SOLVED] Rather huge IPtables chain, iptables: Memory allocation problem. Gangrif Linux - Networking 10 09-11-2009 03:30 PM
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
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 - Security

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