Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I currently have a NAS box running under port 80. To access the NAS from the outside, I mapped the port 8080 to port 80 on the NAS as follow:

iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 10.32.25.2:80

This is working like a charm. However, this is working only if I am accessing the website from the outside of the network (at work, at diffrent house, etc). So when I type in mywebsite.com:8080, IPTables do the job correctly and everything is working fine.

Now, the problem I have is, how can I redirect this port from the inside of the network ? My domain name mywebsite.com point to my router (my linux server) from the inside (10.32.25.1) but I want to redirect port 8080 to port 80 on 10.32.25.2 from the inside.

Any clue?

Edit #1

Attempting to help facilitate this question I put this diagram together. Please feel free to update if it's incorrect or misrepresenting what you're looking for.

                                 iptables
                                     |                   .---------------.
    .-,(  ),-.                       v               port 80             |
 .-(          )-.        port 8080________               |               |
(    internet    )------------>[_...__...°]------------->|      NAS      |
 '-(          ).-'     10.32.25.2    ^   10.32.25.1      |               |
     '-.( ).-'                       |                   |               |
                                     |                   '---------------'
                                     |
                                     |
                                   __  _ 
                                  [__]|=|
                                  /::/|_|
share|improve this question
    
@slm Exactly. Nothing happen on 10.32.25.2:8080 because the server is on port 80. From the outside, the NAT redirect from port 8080 to port 80 on the specified IP (10.32.25.2). NET -> NAT:8080 -> 10.32.25.2:80. I need the rule from the inside and I don't know what to put there. –  David Bélanger May 18 '13 at 20:04
    
@slm Yes. I don't know how I can achieve something like that. I want to say 10.32.25.1:8080 redirect to 10.32.25.2:80. My rule above is working from the outside, but not from the inside of my network. So if I am at the office, I can access my NAS from website.com:8080 and it's completly transparent. From my home, website.com:8080 point to 10.32.25.1 because it's my router aka Linux server. I want to redirect the port 8080 to the NAS also on port 80 but again, in a transparent way. –  David Bélanger May 18 '13 at 23:38
    
@slm Yes, everything is fine and working. I just want to redirect port 10.32.25.1:8080 to 10.32.25.2:80 from the internal network. –  David Bélanger May 18 '13 at 23:44
    
also mention interface like eth0 10.32.25.2, so that we can able to write iptables use based on inbound interface –  Rahul Patil May 19 '13 at 5:35
    
Opps sorry, I just saw.. you already solve the issue.. –  Rahul Patil May 19 '13 at 5:36

1 Answer 1

up vote 2 down vote accepted

I finally found how-to. First, I had to add -i eth1 to my "outside" rule (eth1 is my WAN connection). I also needed to add two others rules. Here in the end what I came with :

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 8080 -j DNAT --to 10.32.25.2:80
iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to 10.32.25.2:80
iptables -t nat -A POSTROUTING -p tcp -d 10.32.25.2 --dport 80 -j MASQUERADE
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.