LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-02-2009, 07:59 PM   #1
Venomal
LQ Newbie
 
Registered: Sep 2009
Location: Pakistan
Distribution: Redhat/Ubuntu Server
Posts: 6

Rep: Reputation: 0
Port Forwarding between several machines and then to a proxy server


Hello mates,

I've looked at all available posts made related to port forwarding but couldnt find a suitable answer.

Senario: University Network connected to another backbone network managed by a Network Admin hired by the university. (Netadmin has blocked all ports except 8080/80)
I have access to the student side servers which are connected to the backbone network.

1- I have a proxy server which is used to connect to the internet through port 8080. Hosted on the Backbone network

2- I have 3 servers under me, lets say : A - B - C

3- Now I use server A as my gateway (connected to A through a switch). Server A uses server B as a gateway and server B uses server C as a gateway.

4- Server C is connected to the backbone network which provides internet access.

Now that I have explained the LAN Setup, here is what I want to do..

I want to forward a port "eg: 3000" which is used by an application so that the application can connect to the internet.

I dont want to use Proxifier and Your-freedom but want to do simple port forwarding through the available linux servers.

How can I make that application send data to Server A which in turn DNAT's my request to Server C (bypassing B since A knows that its gw is B) and then C sends that data to the available proxy "eg: 192.168.1.1:8080"...

I have tried to do a lot of things but couldnt succeed...

DNAT on A :
iptables -t nat -A PREROUTING -p tcp -s 192.168.x.x --sport 3000 -j DNAT --to-destination 192.168.1.1:8080

but I know this wont work since server A doesnt know where 1.1 is located.

even simple port forwarding doesnt pick up packets on A:
iptables -A FORWARD -p tcp -s 192.168.x.x -d 0/0 --source-port 3000 -j ACCEPT

and I cannot add a SNAT/DNAT on server C since packets from my PC cannot reach server C in the first place..
-----------------------------------------------------------------
Hope i've explained my problem...

I'd be more that glad if any one of you people can help me in this..

Thanks! =)
 
Old 10-03-2009, 07:08 AM   #2
Venomal
LQ Newbie
 
Registered: Sep 2009
Location: Pakistan
Distribution: Redhat/Ubuntu Server
Posts: 6

Original Poster
Rep: Reputation: 0
Id be grateful if I can get some sort of an answer...

Ty
 
Old 10-03-2009, 06:36 PM   #3
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
maybe you want --dport instead of --sport, source port is the port the application is coming from not going to
 
Old 10-04-2009, 09:12 AM   #4
Venomal
LQ Newbie
 
Registered: Sep 2009
Location: Pakistan
Distribution: Redhat/Ubuntu Server
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks!!

Can you please tell me in steps, what to do!
 
Old 10-06-2009, 10:39 AM   #5
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
if B doesn't know how to reach the machine your app is running on you'll need to masquerade on A, something like:
iptables -t nat -A POSTROUTING -o eth0 -s 172.16.0.0/24 -j MASQUERADE

the 172.16.0.0/24 would be replaced with the ip block your machine that is running the app is in
and eth0 would be the outbound interface to B

if C doesn't know how to reach A then you'll need to masquerade on B

iptables -t nat -A POSTROUTING -o eth1 -s 172.16.1.1 -j MASQUERADE
the 172.16.1.1 would be replaced with the ip of A and eth1 would be the outbound interface to C

if the proxy server doesn't know how to reach B then you'll need to masquerade on C as well as DNATing on C

iptables -t nat -A POSTROUTING -o eth1 -s 172.16.2.1 -j MASQUERADE
the 172.16.1.1 would be replaced with the ip of B and eth1 would be the outbound interface to C

iptables -t nat -A PREROUTING -p tcp --dport 3000 -j DNAT --to-destination 192.168.1.1:8080


And don't forget to turn on forwarding cat 1 > /proc/sys/net/ipv4/ip_forward
you can also usually edit your sysctl.conf to make that a permanent change

Last edited by estabroo; 10-06-2009 at 10:40 AM. Reason: forwarding
 
Old 10-08-2009, 05:28 PM   #6
Venomal
LQ Newbie
 
Registered: Sep 2009
Location: Pakistan
Distribution: Redhat/Ubuntu Server
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by estabroo View Post
if B doesn't know how to reach the machine your app is running on you'll need to masquerade on A, something like:
iptables -t nat -A POSTROUTING -o eth0 -s 172.16.0.0/24 -j MASQUERADE

the 172.16.0.0/24 would be replaced with the ip block your machine that is running the app is in
and eth0 would be the outbound interface to B

if C doesn't know how to reach A then you'll need to masquerade on B

iptables -t nat -A POSTROUTING -o eth1 -s 172.16.1.1 -j MASQUERADE
the 172.16.1.1 would be replaced with the ip of A and eth1 would be the outbound interface to C

if the proxy server doesn't know how to reach B then you'll need to masquerade on C as well as DNATing on C

iptables -t nat -A POSTROUTING -o eth1 -s 172.16.2.1 -j MASQUERADE
the 172.16.1.1 would be replaced with the ip of B and eth1 would be the outbound interface to C

iptables -t nat -A PREROUTING -p tcp --dport 3000 -j DNAT --to-destination 192.168.1.1:8080


And don't forget to turn on forwarding cat 1 > /proc/sys/net/ipv4/ip_forward
you can also usually edit your sysctl.conf to make that a permanent change
Ty for helping...ill give it a go tomorrow..and get back to you.

Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
port forwarding or maybe proxy pingtoft Linux - Networking 2 10-03-2009 09:42 PM
ssh port forwarding as a proxy server: how to be aware of the current connections Gozer404 Linux - Security 2 07-15-2009 11:22 AM
Proxy/port forwarding meldron Linux - Networking 1 07-18-2008 01:17 PM
apache proxy and port forwarding Furlinastis Linux - Networking 0 03-26-2007 10:42 AM
Port Forwarding w/2 Machines & 1 Switch TastyWheat Linux - Networking 0 02-26-2004 11:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration