Home > Command-Line, Open Source > Port Forwarding Using Iptables

Port Forwarding Using Iptables

If our server is located behind our firewall and it is using private ip, we can do port forwarding to enable access from outside to our server.

iptables -t nat -A PREROUTING -d [firewall public address] -p tcp --dport [local port] -j DNAT --to [remote machine]:[remote port]

As an example:

iptables -t nat -A PREROUTING -d -p tcp --dport 8080 -j DNAT --to

Therefore, if a web browser is pointing to our public address at port 8080, she will be forwarded to our server running behind our firewall (but you must set proper SNAT or MASQUERADE setting first).

Categories: Command-Line, Open Source
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: