Two IP's and forward a port - help.

Hello,

I'm new with iptables but I would like some pointers.

My linode has two ip addresses (ipA and ipB) and I have two processes that I want to expose using port 80 (internally the process run as processA:80 and processB:8080)

So I would like to do this

ipA:80 -> processA:80 (webserver)

ipB:80 -> processB:8080 (test custom webserver)

Any info is appriciated… be gentle :)

Thanks

3 Replies

There is no reason for iptables to be involved here. Ports are IP-specific, not system-wide. You need to bind your webserver to a specific IP address/port combination rather than blindly binding to all IPs on the system.

Check the documentation for the webserver daemon you're using. If it's Apache, it's the 'Listen' directive you'll want to read about.

As mentioned, you should be able to get the server(s) to bind on the same port with different IP's… But if you can't (for whatever reason):

iptables -t nat -A PREROUTING -p tcp -m tcp -d XXX.XXX.XXX.XXX --dport 80 -j REDIRECT --to-ports 8080

Replace XXX.XXX.XXX.XX with your second IP.

Thanks a lot Nknight,Fukawi2.

I used the example of webserver port 80 becuase i thought somebody had run in to it before. BUT that helped understand what the solution was.

I'm using a piece of code that does not have a way to bind to a specific IP (it will be fixed). But now I have a temp solution using iptables until it's fixed.

Thanks for answering these basic questions which made me realized what the real problem was and the temp solution.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct