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 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 192.168.1.2.

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

Linux system router ip suppose 192.168.1.1 (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 192.168.1.1 --dport 22 -j DNAT --to-destination 192.168.1.2:22

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 at 13:12

2 Answers 2

up vote 0 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 192.168.1.2:22

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 at 13:39
    
Yes, just replace the port number. Use 80 for HTTP –  sandeep.s85 Jan 1 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 accessible.help me. –  Rahul Jan 1 at 14:17
    
Try to first open the site from your LAN 192.168.1.2/path 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 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 192.168.1.2
iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 22 -j DNAT --to 192.168.1.2
iptables -A FORWARD -p tcp -d 192.168.1.2 --dport 80 -m state --state NEW,ESTABLISHED,RELATED-j ACCEPT
iptables -A FORWARD -p tcp -d 192.168.1.2 --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

 
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.