* Matching packets by HTTP header "Host"
@ 2007-03-13 10:47 Giovanni Lovato
2007-03-13 11:15 ` Joris Dobbelsteen
2007-03-13 18:38 ` Pascal Hambourg
0 siblings, 2 replies; 4+ messages in thread
From: Giovanni Lovato @ 2007-03-13 10:47 UTC (permalink / raw)
To: netfilter
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all.
I'm trying to forward packets to different hosts depending on the "Host"
header in HTTP packets, e.g. packets on port 80 requesting "Host:
one.example.org" to 192.168.0.1 and all other on port 80 to 192.128.0.2.
I did:
iptables -t nat -A PREROUTING -p TCP -i eth0 -m string --algo bm
- --string "Host: one.example.org" --destination-port 80 -j DNAT
- --to-destination 192.168.0.1
iptables -t nat -A PREROUTING -p TCP -i eth0 --destination-port 80 -j
DNAT --to-destination 192.168.0.2
But all packets are going to 192.168.0.2. Do I miss something?
Regards,
G.L.
- --
www.aldu.net/~heruan
giovanni.lovato@aldu.net
ldaps://pgpkeys.aldu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFF9oFZaWLXrn9dopwRAjfbAKCAyWaZ5h/1w9Bvaj5aOhmsj0GIgACfXbbM
l3+Z0tatK47gMv7iMANg6u4=
=LAJU
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Matching packets by HTTP header "Host"
2007-03-13 10:47 Matching packets by HTTP header "Host" Giovanni Lovato
@ 2007-03-13 11:15 ` Joris Dobbelsteen
2007-03-13 18:38 ` Pascal Hambourg
1 sibling, 0 replies; 4+ messages in thread
From: Joris Dobbelsteen @ 2007-03-13 11:15 UTC (permalink / raw)
To: Giovanni Lovato, netfilter
>-----Original Message-----
>From: netfilter-bounces@lists.netfilter.org
>[mailto:netfilter-bounces@lists.netfilter.org] On Behalf Of
>Giovanni Lovato
>Sent: dinsdag 13 maart 2007 11:48
>To: netfilter@lists.netfilter.org
>Subject: Matching packets by HTTP header "Host"
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Hi all.
>I'm trying to forward packets to different hosts depending on
>the "Host"
>header in HTTP packets, e.g. packets on port 80 requesting "Host:
>one.example.org" to 192.168.0.1 and all other on port 80 to
>192.128.0.2.
This processing is at a too high level for NetFilter (without proper
extensions).
You should rather use a HTTP proxy, like squid or apache with proxy
module, for this operation. These are capable of handling such requests.
>I did:
>iptables -t nat -A PREROUTING -p TCP -i eth0 -m string --algo bm
>- --string "Host: one.example.org" --destination-port 80 -j DNAT
>- --to-destination 192.168.0.1
>
>iptables -t nat -A PREROUTING -p TCP -i eth0
>--destination-port 80 -j DNAT --to-destination 192.168.0.2
>
>But all packets are going to 192.168.0.2. Do I miss something?
The problem is that at connection-time there you cannot make the choice
to which server you must connect. This can only be decided when you are
already connected.
- Joris
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Matching packets by HTTP header "Host"
2007-03-13 10:47 Matching packets by HTTP header "Host" Giovanni Lovato
2007-03-13 11:15 ` Joris Dobbelsteen
@ 2007-03-13 18:38 ` Pascal Hambourg
2007-03-13 18:50 ` Giovanni Lovato
1 sibling, 1 reply; 4+ messages in thread
From: Pascal Hambourg @ 2007-03-13 18:38 UTC (permalink / raw)
To: netfilter
Hello,
Giovanni Lovato a écrit :
>
> I'm trying to forward packets to different hosts depending on the "Host"
> header in HTTP packets, e.g. packets on port 80 requesting "Host:
> one.example.org" to 192.168.0.1 and all other on port 80 to 192.128.0.2.
> I did:
>
> iptables -t nat -A PREROUTING -p TCP -i eth0 -m string --algo bm
> - --string "Host: one.example.org" --destination-port 80 -j DNAT
> - --to-destination 192.168.0.1
>
> iptables -t nat -A PREROUTING -p TCP -i eth0 --destination-port 80 -j
> DNAT --to-destination 192.168.0.2
>
> But all packets are going to 192.168.0.2. Do I miss something?
Rules in the 'nat' table apply only to the first packet of a new
connection. NAT operations for the whole connection is determined by the
NAT rules applied to the first (SYN) packet of the connection, which
does not contain any HTTP payload data such as the "Host" header. So the
first rule never matches a packet. As suggested, use a HTTP proxy instead.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Matching packets by HTTP header "Host"
2007-03-13 18:38 ` Pascal Hambourg
@ 2007-03-13 18:50 ` Giovanni Lovato
0 siblings, 0 replies; 4+ messages in thread
From: Giovanni Lovato @ 2007-03-13 18:50 UTC (permalink / raw)
To: netfilter
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Pascal Hambourg wrote:
> Hello,
>
> Giovanni Lovato a écrit :
>>
>> I'm trying to forward packets to different hosts depending on the "Host"
>> header in HTTP packets, e.g. packets on port 80 requesting "Host:
>> one.example.org" to 192.168.0.1 and all other on port 80 to 192.128.0.2.
>> I did:
>>
>> iptables -t nat -A PREROUTING -p TCP -i eth0 -m string --algo bm
>> - --string "Host: one.example.org" --destination-port 80 -j DNAT
>> - --to-destination 192.168.0.1
>>
>> iptables -t nat -A PREROUTING -p TCP -i eth0 --destination-port 80 -j
>> DNAT --to-destination 192.168.0.2
>>
>> But all packets are going to 192.168.0.2. Do I miss something?
>
> Rules in the 'nat' table apply only to the first packet of a new
> connection. NAT operations for the whole connection is determined by the
> NAT rules applied to the first (SYN) packet of the connection, which
> does not contain any HTTP payload data such as the "Host" header. So the
> first rule never matches a packet. As suggested, use a HTTP proxy instead.
Thank you all.
I used Apache mod_proxy_http to gain my needs!
G.L.
- --
www.aldu.net/~heruan
giovanni.lovato@aldu.net
ldaps://pgpkeys.aldu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFF9vKJaWLXrn9dopwRAm8AAJ9QJ/EkKwVh6+rNrLGRABVT/gqz5ACfbw1Y
AV92Cm4Mo4AlN/2zcDEXiUU=
=NNvp
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-03-13 18:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-13 10:47 Matching packets by HTTP header "Host" Giovanni Lovato
2007-03-13 11:15 ` Joris Dobbelsteen
2007-03-13 18:38 ` Pascal Hambourg
2007-03-13 18:50 ` Giovanni Lovato
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.