theweaselking: (Default)
[personal profile] theweaselking
I have a Ubuntu 6.06 server.

I want all tcp connections to port *X* on the server to automatically be seamlessly and quietly redirected to port *Y* on that very same server. And, obviously, the responses need to go back to the original host on that port. However, normal connections directly to port *Y* should not be affected.

I also want this change to be server-side only. No router changes, no nothing.

How can I do it?

EDIT: [livejournal.com profile] zastrazzi came through with the correct wording of iptables I needed, and now I see my error. Yay!

(no subject)

Date: 2008-05-08 12:39 pm (UTC)
From: [identity profile] zastrazzi.livejournal.com
To redirect port 80 to 8080 use:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

(no subject)

Date: 2008-05-08 12:45 pm (UTC)
From: [identity profile] theweaselking.livejournal.com
There we go. I was trying to redirect to localhost:Y, and it was breaking things.

Problem solved! Thanks.

(no subject)

Date: 2008-05-08 12:49 pm (UTC)
From: [identity profile] zastrazzi.livejournal.com
No problem. It was mostly knowing what to google and recognizing the result :)

(no subject)

Date: 2008-05-08 12:59 pm (UTC)
From: [identity profile] theweaselking.livejournal.com
I was googling, but all my results were for forwarding to a different machine, and the server did not like that.

And don't undervalue the ability to google *and* comprehend. It's important!

(no subject)

Date: 2008-05-08 01:31 pm (UTC)
From: [identity profile] jsbowden.livejournal.com
Comprehension is over rated.

(no subject)

Date: 2008-05-08 06:29 pm (UTC)
From: [identity profile] rbarclay.livejournal.com
iptables, bah. Far too elegant a solution. Real Geeks(tm)'d do it with netcat and inetd ;)

(no subject)

Date: 2008-05-08 07:04 pm (UTC)
From: [identity profile] theweaselking.livejournal.com
I was open to any solution. I just was figuring iptables made the most sense, and was discovering that I couldn't make the fucking thing do what I wanted.

It's because I didn't have --to-port. I was just trying to redirect to localhost:Y and that was causing issues with the server process.

Profile

theweaselking: (Default)theweaselking
Page generated Feb. 6th, 2026 03:05 pm