All of lore.kernel.org
 help / color / mirror / Atom feed
* Port redirection
@ 2009-08-05  4:57 Steve Fink
  2009-08-05 14:04 ` Pascal Hambourg
  0 siblings, 1 reply; 12+ messages in thread
From: Steve Fink @ 2009-08-05  4:57 UTC (permalink / raw)
  To: netfilter

I am trying to redirect all traffic generated on box $SRC to a
particular UDP port to a different host $SPY. I've done similar things
with whole TCP connections using DNAT and SNAT, but this time I want
UDP and I want to be able to start up the redirection after the
"connection" has been established. (I never see these packets in the
'nat' table.)

The only option that seemed viable, me not knowing much about
networking, was to use the 'mangle' table to set a mark on the
outgoing packets, then use 'ip' to route the packet to $SPY. I've used
iptables a fair amount, but ip not at all.

On $SRC, I ran:
 iptables -t mangle -A OUTPUT -p udp --dport 8765 -j MARK --set-mark 1
 ip rule add fwmark 1 table 50
 ip route add via $SPY table 50
 sysctl net.ipv4.ip_forward=1 # Dunno if this matters
 ip route flush cache

On $SPY, I ran:
 sysctl net.ipv4.ip_forward=1 # Makes sense here

$SRC, $SPY, and $ORIG_DEST (the original destination) can all reach each other.

According to iptables, the mark is getting set on the packets I want
redirected. But tcpdump shows packets still going to the original
destination, not $SPY. I am testing by running this on $SRC

  nc -v -u $ORIG_DEST 8765

And I trigger packets to be sent by hitting enter in that window. The
packets are making it to my dummy server on $ORIG_DEST. They do not
show up to tcpdump on $SPY.

I don't know how to read the output of 'ip route show cache', but it includes

$SPY from $SRC tos lowdelay dev tun0
    cache  mtu 1412 advmss 1372 hoplimit 64
local $SRC from $SPY tos lowdelay dev lo  src $SRC
    cache <local,src-direct>  iif tun0

(I'm testing this over a VPN, hence the tun0 device. Both $ORIG_DEST
and $SPY are accessible via the VPN.)

The only thing I can think of is that $SPY needs to be reachable in a
single hop, but then I'd expect some other error message. On the other
hand, I just tried the above commands on my actual $SRC box, and it
gave me "RTNETLINK answers: Network is unreachable". But as I said,
all three boxes can reach each other via ping and pretty much
anything.

By the way, I don't care if the packets arrive at $SPY with the
destination IP addresses still set to something else; I just want them
to be filterable via another iptables mess. (I'll probably just write
them all out to a file with tcpdump and analyze them after the fact,
but I could imagine writing a application protocol-specific netfilter
module to do the checking that I really want.)

I'd really like for some way to rewrite the destination IP address and
do routing on the resulting packet, but I couldn't figure out how to
do that. Like I said, these packets don't go through the 'nat' table,
and I don't know how to rewrite the destination IP any other way.

Help?

^ permalink raw reply	[flat|nested] 12+ messages in thread
* port redirection
@ 2006-08-13  0:18 Brian Lewis
  2006-08-13  6:18 ` Graham Murray
  0 siblings, 1 reply; 12+ messages in thread
From: Brian Lewis @ 2006-08-13  0:18 UTC (permalink / raw)
  To: netfilter

I run a servlet container that wants to listen on TCP 8080. I want to
redirect TCP 80 on my machine to 8080 on the same machine.

If I do -t nat -I PREROUTING -i $IF -d $IP -p tcp --dport 80 -j REDIRECT
--to-port 8080, it works in that I reach the 8080 server when I connect
to 80.

But I have to allow 8080 through. Is there a way to provide access to the
8080 server via port 80 without having to allow 8080?

Stating the problem a different way, suppose that for security through
obscurity purposes you wanted sshd to appear as if it was running on 2200
via firewall rules. The above method of redirecting 2200 -> 22 would work,
but not offer much help because 22 would still have to be open.

Thank you.


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Port redirection
@ 2005-05-31 19:25 Chris NoSurname
  2005-05-31 22:42 ` Anthony Sadler
  2005-06-01  2:45 ` Jason Opperisano
  0 siblings, 2 replies; 12+ messages in thread
From: Chris NoSurname @ 2005-05-31 19:25 UTC (permalink / raw)
  To: netfilter

Hi all.

I've searched and searched and I cannot seem to get
this working.

I'm trying to redirect port 80 to a different port so
that I can run the Resin application server as
non-root user.  I've got the following command..

iptables -t nat -A PREROUTING -p tcp --dport 80 -d
x.x.x.x -j REDIRECT --to-ports 8900

It comes up as 

    0     0 REDIRECT   tcp  --  any    any    
anywhere             www.mydomain.com   tcp dpt:http
redir ports 8900

Yet, if I connect to the http port it is closed.  Port
8900 is open and does accept connections if I specify
it in the address.

I am unclear of why the rules shows up in status, but
does not work.

Thanks for any help you can offer.

David

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Port Redirection
@ 2003-04-30 14:43 nassri abokhalaf
  0 siblings, 0 replies; 12+ messages in thread
From: nassri abokhalaf @ 2003-04-30 14:43 UTC (permalink / raw)
  To: netfilter

Hello to all,

I need to redirect some services to my ssh port.
my firewall has two interfaces and i want to redirect all traffic to port 22,
so i added this code to my firewall script

...initialisation code....

My_PORTS_TCP="22 ftp telnet squid socks kazaa back_or"

echo -n "TCP port "
for i in $My_PORTS_TCP;
do
        echo -n "$i "
        $IPT -t nat -A PREROUTING -p TCP -d $EXTNET --dport $i -j REDIRECT --to-ports  22

        fi
done

but when i do tcpdump to port 22 i see no traffic at all, although i am doing ftp to my firewall !?!
questions:
1-Is the rule wrong ?
2-Is the tcpdump leastning in a raw socket before redirection ?
3-How can i confirm that redirection is functioning ?

please comment,


nassri


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Port Redirection
@ 2003-04-30 14:38 ABOKHALAF, Nassri Abdellatif
  0 siblings, 0 replies; 12+ messages in thread
From: ABOKHALAF, Nassri Abdellatif @ 2003-04-30 14:38 UTC (permalink / raw)
  To: netfilter

Hello to all,

I need to redirect some services to my ssh port.
my firewall has two interfaces and i want to redirect all traffic to port 22,
so i added this code to my firewall script

....initialisation code....

My_PORTS_TCP="22 ftp telnet squid socks kazaa back_or"

echo -n "TCP port "
for i in $My_PORTS_TCP;
do
        echo -n "$i "
        $IPT -t nat -A PREROUTING -p TCP -d $EXTNET --dport $i -j REDIRECT --to-ports  22

        fi
done

but when i do tcpdump to port 22 i see no traffic at all, although i am doing ftp to my firewall !?!
questions:
1-Is the rule wrong ?
2-Is the tcpdump leastning in a raw socket before redirection ?
3-How can i confirm that redirection is functioning ?

please comment,


nassri





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

end of thread, other threads:[~2009-08-05 18:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <200505312248.j4VMmKcQ016084@rti02.co-lo.riverviewtech.net>
2005-05-31 23:37 ` Port redirection Taylor, Grant
2009-08-05  4:57 Steve Fink
2009-08-05 14:04 ` Pascal Hambourg
2009-08-05 18:30   ` Steve Fink
  -- strict thread matches above, loose matches on Subject: below --
2006-08-13  0:18 port redirection Brian Lewis
2006-08-13  6:18 ` Graham Murray
2006-08-13  7:54   ` Brian Lewis
2005-05-31 19:25 Port redirection Chris NoSurname
2005-05-31 22:42 ` Anthony Sadler
2005-06-01  2:45 ` Jason Opperisano
2003-04-30 14:43 Port Redirection nassri abokhalaf
2003-04-30 14:38 ABOKHALAF, Nassri Abdellatif

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.