Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have linux box which has two network interface, eth0, eth1. from eth1 I can access an internal website, say under port 8080. from outside the box, I can't access that network. my question is, is there a way I set up something so from outside the box, there appears to be a web server running in port 8080 and when I connect to it, it automatically forwards to eht1 the internal site? I tried to enable ip forward and add a static route, but it doesn't work. thanks.

share|improve this question

migrated from stackoverflow.com Mar 24 '10 at 7:34

This question came from our site for professional and enthusiast programmers.

    
This isn't clear. Where is the website you're trying to access? On a different network? Provide examples with IP addresses at least. –  wazoox Mar 24 '10 at 8:09
add comment

1 Answer

Is this box routing the traffic between those interfaces? From what you wrote I assume that on eth0 there is a public network connected to the Internet, while there is a private local network on eth1.

If thats the setup and you want to access webserver on local network from the Internet you have to use Network Address Translation (NAT).

Basicly you need to figure an external IP address on the "outside" interface and add iptables rule:

iptables -t nat -A PREROUTING -p tcp -d X.X.X.X --dport 8080 -j DNAT --to Y.Y.Y.Y:8080

X.X.X.X is the external address while Y.Y.Y.Y is the internal one running webserver. In that scenario you also have to make sure you are allowing the traffic in the forward chain:

iptables -A FORWARD -p tcp -d Y.Y.Y.Y --dport 8080 -j ACCEPT

Your box has to have forwarding enabled for this:

sysctl net.ipv4.ip_forward=1 

or

echo 1 > /proc/sys/net/ipv4/ip_forward

Not sure if thats answer your question, but gave very little details in you question.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.