All of lore.kernel.org
 help / color / mirror / Atom feed
* iptables / ebtables IP address intercept
@ 2010-07-31 14:24 Alex Bligh
  2010-08-03 16:54 ` Grant Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Alex Bligh @ 2010-07-31 14:24 UTC (permalink / raw)
  To: netfilter; +Cc: Alex Bligh

On a machine acting as a bridge, I want to intercept calls to a specific
IP address, and serve them locally. So, the bridge config looks like (e.g.)

  10.10.0.1/29     ethernet   eth0         tap1.1       10.10.0.2/29
  default router <-------------> br0 bridge <---------> testbox

                                    | 192.200.3.2/24
                                    | eth1
                                    V
                                second default router (192.200.3.1/24)


I have control over the bridge running br0, and I want to intercept
on the bridge tcp requests to (e.g.) 192.0.200.1:80, and remap them
locally to (e.g.) 192.0.200.2:8080. What I want to achieve is that
when testbox makes a connection to 192.0.200.1:80, this is remapped
by SNAT and DNAT within the bridge so that 192.0.200.2 sees a connection
to its port 8080 coming from 192.200.3.2 (i.e. the public IP of the
bridge).

I have a config which works if I put an IP address on the bridge's
ethernet interface of (e.g.) 10.10.0.3/29 (*)

The main components are:
  # masquerade on the output interface
  iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

  # allow backtrafic back in
  iptables -A FORWARD -i eth1 \! -o eth1 -m state \
    --state RELATED,ESTABLISHED -j ACCEPT

  # Rewrite destination address and port
  iptables -t nat -A PREROUTING --p tcp --match multiport --dports 80 \
    -d 192.0.200.1 -j DNAT --to 192.0.200.2:8080

This all works fine, but my problem is that I can't put an IP interface
on the ethernet interface (i.e. I can't do the step labeled (*) above)
because I don't know how the network is numbered (here it's labeled
10.10.0.0 but I don't know what the true labeling is).

So I am trying to use ebtables (which I am less familiar with) to turn
the bridge into a brouter. I use this:

 ebtables -t broute -A BROUTING -p IPv4 --ip-dst 192.0.200.1 \
  -j redirect

I think what that should do is redirect the MAC address for requests
to the IP address to the internal brouter, and indeed it seems to
work. My problem is on return traffic. The brouter unmangles the
IP addresses correctly, and wants to send traffic back to
10.10.0.2. However, it does this by looking in the internal routing
table, which results in the packet being sent out of eth1 (not
tap1.1) whereupon bad things happen. This is because the
machine doesn't (and can't) have a route to 10.10.0.0/24, so
doesn't know what interface to send it out of.

What I really want is for the masquerade line to remember not only
the input IP address but also the input interface associated with
the connection, and ignore the routing table. I am, however, open
to any other ideas. I should say that the bridge box concerned
carries hundreds of VLANs - I am happy using connmark to track
traffic, but I can't see how to match connmark in iptables and
use that to set output interface and output mac address.

-- 
Alex Bligh

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-08-06 21:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-31 14:24 iptables / ebtables IP address intercept Alex Bligh
2010-08-03 16:54 ` Grant Taylor
2010-08-03 18:06   ` Alex Bligh
2010-08-03 20:23     ` Grant Taylor
2010-08-04  8:08       ` Alex Bligh
2010-08-06 21:07         ` Grant Taylor

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.