Networking Forums

Networking Forums > Computer Networking > Linux Networking > transparent proxies / iptables: Mini How To by Daniel Kiracofe

Reply
Thread Tools Display Modes

transparent proxies / iptables: Mini How To by Daniel Kiracofe

 
 
Wolfgang Wyremba
Guest
Posts: n/a

 
      01-15-2004, 10:09 AM
Hello!

I have difficulties to understand the iptables statements in chapter 6
"Transparent Proxy to a Remote Box" of Daniel Kiracofe´s Mini-How-To
"Transparent Proxy with Linux and Squid"
(http://tldp.org/HOWTO/TransparentProxy-6.html)

As I know when packets are forwarded they are processed in the following way
(chains): PREROUTING --> FORWARD --> POSTROUTING
(http://iptables-tutorial.frozentux.n...#TRAVERSINGOFT
ABLES)

Daniel uses the following 3 iptables statements and explains them with the
following sentences:

iptables -t nat -A PREROUTING -i eth0 -s ! squid-box -p tcp --dport 80 -j
DNAT --to squid-box:3128
iptables -t nat -A POSTROUTING -o eth0 -s local-network -d squid-box -j
SNAT --to iptables-box
iptables -A FORWARD -s local-network -d squid-box -i eth0 -o eth0 -p
tcp --dport 3128 -j ACCEPT

"The first one sends the packets to squid-box from iptables-box.
The second makes sure that the reply gets sent back through iptables-box,
instead of directly to the client (this is very important!).
The last one makes sure the iptables-box will forward the appropriate
packets to squid-box.
It may not be needed. YMMV."

Lets assume the following:
local-network: 192.168.1.0/24
Client-PC: 192.168.1.1/24
iptables-box (default-gateway): 192.168.1.100/24
squid-box: 192.168.1.2/24

I now want to explain how I understand it:
a) The first statement:
If the Client (192.168.1.1) wants to visit (e.g.) www.kernel.org it sends
its packet to its default-gateway (192.168.1.100).
The default-gateway changes the destination ip address to 192.168.1.2 and
destination port to 3128 so that the packet gets forwarded
to the proxy.

b) The third statements:
The packet has the destination ip address of the proxy and gets therefore
into the FORWARD chain where it has to be accepted.

c) I don´t understand the second statement:
When the packet leaves the FORWARD chain and enters the POSTROUTING chain
it gets the source ip address of the default-
gateway (192.168.1.100).
Why?

When leaving the POSTROUTING chain the packet gets forwarded to the
proxy.
The proxy opens the connection to www.kernel.org and sends the HTTP
request.
The HTTP reply gets send back to the proxy.

And now the question:
How can the proxy know that it has to send the reply to the Client
(192.168.1.1) and not to the
default-gateway (192.168.1.100). The second statement changes the source
ip address so that it looks like the packet
comes from the default-gateway.

I hope someone of you can tell me how it works.

Thanks!

Wolfi


 
Reply With Quote
 
 
 
 
Horst Knobloch
Guest
Posts: n/a

 
      01-15-2004, 07:50 PM
Wolfgang Wyremba <(E-Mail Removed)> wrote:


> (http://tldp.org/HOWTO/TransparentProxy-6.html)

[...]
> Daniel uses the following 3 iptables statements and explains them with
> the following sentences:
>
> iptables -t nat -A PREROUTING -i eth0 -s ! squid-box -p tcp --dport 80 -j
> DNAT --to squid-box:3128
> iptables -t nat -A POSTROUTING -o eth0 -s local-network -d squid-box -j
> SNAT --to iptables-box
> iptables -A FORWARD -s local-network -d squid-box -i eth0 -o eth0 -p
> tcp --dport 3128 -j ACCEPT
>
> "The first one sends the packets to squid-box from iptables-box.
> The second makes sure that the reply gets sent back through iptables-box,
> instead of directly to the client (this is very important!).
> The last one makes sure the iptables-box will forward the appropriate
> packets to squid-box.
> It may not be needed. YMMV."
>
> Lets assume the following:
> local-network: 192.168.1.0/24
> Client-PC: 192.168.1.1/24
> iptables-box (default-gateway): 192.168.1.100/24
> squid-box: 192.168.1.2/24
>
> I now want to explain how I understand it:
> a) The first statement:
> If the Client (192.168.1.1) wants to visit (e.g.) www.kernel.org it
> sends its packet to its default-gateway (192.168.1.100).
> The default-gateway changes the destination ip address to 192.168.1.2
> and destination port to 3128 so that the packet gets forwarded
> to the proxy.
>
> b) The third statements:
> The packet has the destination ip address of the proxy and gets
> therefore into the FORWARD chain where it has to be accepted.
>
> c) I don´t understand the second statement:
> When the packet leaves the FORWARD chain and enters the POSTROUTING
> chain it gets the source ip address of the default-gateway
> (192.168.1.100).
> Why?


Because the answer to the client must be sent back via the
iptables box to the client and not directly to the client.
The answer packet need to pass the iptables box so that DNAT
can be "undone". Remember, the client wants to have the replies
coming from the IP address of www.kernel.org and from port 80
and not from the squid address and port 3128.

Ciao, Horst
--
»When pings go wrong (It hurts me too)« E.Clapton/E.James/P.Tscharn
 
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Supply Mini-Com Coupler Modules ,Mini-com Coupler Modules,Panduit Mini-com Coupler Module,Panduit Minicom Modules,Panduit Mini-Com Module,Panduit Mini-com Fiber Optic Adapter Modules samul888@vip.163.com Broadband 0 04-23-2006 01:48 PM
transparent proxy - iptables+ squid+2 routers Igor Linux Networking 3 10-13-2005 03:54 AM
Iptables Transparent Proxy and Browser on localhost Fritz Bayer Linux Networking 3 06-19-2004 09:24 AM
iptables transparent proxy Cameron Kerr Linux Networking 7 06-14-2004 08:57 AM
Daniel (null@void.net) DaveC Wireless Internet 0 06-03-2004 01:28 PM



1 2 3 4 5 6 7 8 9 10 11