I have three machines: A local PC (public IP, an Ubuntu 10 Server box in a datacentre (eth0 on public IP), and a third-party server hosting a website outside of my network (let's say Slashdot on

  • Using iptables, how do I access Slashdot from my local machine using ?
  • Would this process differ if Slashdot was on the same LAN as my Ubuntu box?
  • Can this be done with just NAT PREROUTING/POSTROUTING, or do I need MASQUERADE?
   PC ----- Ubuntu 10 Server ----- Slashdot 
(      (        (
  1. Enable the IP forwarding on Ubuntu:

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

    and add the following rules:

    iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 8080 -j DNAT \
    iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source
  2. No.

  3. You should use MASQUERADE if the Ubuntu has a dynamic IP:

    iptables -t nat -A POSTROUTING -j MASQUERADE

You can also use SSH local port forwarding in this case by executing the below command on the Ubuntu:

$ ssh -L -N user@

There's still another (or more) way to do this. Take a look at the rinetd:

Name       : rinetd
Arch       : i386
Version    : 0.62
Release    : 6.el5.art
Size       : 41 k
Repo       : installed
Summary    : TCP redirection server
URL        : http://www.boutell.com/rinetd
License    : GPL
Description: rinetd is a daemon which redirects TCP connections from one IP address
           : and port to another IP address and port. This daemon is often used to
           : access services behind a firewall.

The configuration is very simple. Add the belows line into /etc/rinetd.conf: 8080 80

and start:

# /etc/init.d/rinetd start
Starting rinetd:                                           [  OK  ]

It will do everything for you.

  • Fantastic. The iptables version works like a charm. I was missing the POSTROUTING rule, and was getting nowhere. If anyone's trying to do this with a saved .conf file, this is what you're after: *nat -A PREROUTING -p tcp -m tcp -i eth0 --dport 8080 -j DNAT --to-destination -A POSTROUTING -o eth0 -j SNAT --to-source COMMIT – jetboy Nov 1 '11 at 13:25
  • Follow-up question here: serverfault.com/questions/326837/… – jetboy Nov 1 '11 at 22:16
  • Perfect! Just a quick question. When the response packet comes back to the ubuntu server with a destination address of, what is the module responsible for modifying the packet and returning it back to Is it the "connection tracking" module? – Keeto Aug 11 '17 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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