Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I do not have the router so i make the Linux system into router having centos 6.4 for forwarding the Public network traffic to my local LAN.It has the two NIC card. one for public ip (eth1) and another for private ip (eth2).

I have a server which is connected to my local LAN suppose

x.x.x.x is for public ip (this ip is on eth1).

Linux system router ip suppose (this ip is on eth2)

I want that when someone from any network from anywhere use this i.e

ssh x.x..x.x (public ip) or using putty

it will goes to server.

I disable the Selinux and iptables firewall on server

I did some Iptables modification on the Linux system router but it goes to itself which work as a router not to the main server from other network and same network also.

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

but not works.

and again i want to forward all the http (80) traffic to my internal server using iptables from same Linux system router.

I need this kindly give me solution over this.

share|improve this question
Can you provide your iptables -L output? – Gabriel Talavera Jan 1 '14 at 13:12
up vote 4 down vote accepted

First of all make sure the packet forwarding is enabled in the kernel

# echo 1 > /proc/sys/net/ipv4/ipforward

You can also make it permanent by adding below line to /etc/sysctl.conf

net.ipv4.ip_forward = 1

You have to do this on Linux Machine acting as a router. You can try the following rule on router machine.

iptables -t nat -A PREROUTING -i eth1 -d x.x.x.x -p tcp --dport 22 -j  DNAT --to-destination

Also let us know the output of your NAT Rules from the router box.

iptables -t nat -L -n -v
share|improve this answer
Thanks a lot. can i forward the same for http. – Rahul Jan 1 '14 at 13:39
Yes, just replace the port number. Use 80 for HTTP – sandeep.s85 Jan 1 '14 at 13:41
Hi, sandeep i want one thing that in my server i made a apache webserver. i want to access the particular site which is hosted on server. how i can do this. on browser publicip:80/path to directory but not me. – Rahul Jan 1 '14 at 14:17
Try to first open the site from your LAN then see what happens. If you are still facing issues, I suggest opening a new thread with detailed problem description explaining what have you configured with Apache. – sandeep.s85 Jan 1 '14 at 14:29

First of all, enable routing in the linux gateway:

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

Then add the following rules:

iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 80 -j DNAT --to
iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 22 -j DNAT --to
iptables -A FORWARD -p tcp -d --dport 80 -m state --state NEW,ESTABLISHED,RELATED-j ACCEPT
iptables -A FORWARD -p tcp -d --dport 22 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

Check your rules with iptables -L -v, the pkts and bytes columns will show you which rules are being matched.

share|improve this answer

Your Answer


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.