November 23, 2024, 08:55:13 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: how to configure port forwarding  (Read 6747 times)

Offline neilg_cebu

  • Linux Noob !
  • *
  • Posts: 16
how to configure port forwarding
« on: April 21, 2005, 05:29:51 AM »
hi gurus,

i would like to setup port forwarding. i am using linux redhat 9.0. i am not expert on this OS yet. but our requirements need this kind of thing - port forwarding.

this requirement arises when we started to use Remote Administrator Software.  This software works like pc anywhere.  Linux is the only PC visible to the internet. behind it are many PC's with private IP's. To connect to private IP's we need to pass thru linux public IP, then linux forwards it to private IP thru port forwarding.

Now, my problem is how to setup port forwarding...

Any help will be greatly appreciated.

Thanks In Advance,
Neil

P.S. - As I have stated above, I am still a novice to this OS, if possible please provide step by step instructions.

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
how to configure port forwarding
« Reply #1 on: April 21, 2005, 10:48:09 AM »
Well..
First of all I would like you to suggest that you try to search previous post of the forum as I have answered few such questions already.

Offline neilg_cebu

  • Linux Noob !
  • *
  • Posts: 16
how to configure port forwarding
« Reply #2 on: April 22, 2005, 01:46:55 AM »
Hi Ricky,

I am new to this forum, but i am a member of several forums already. It is my SOP to do google first before posting. But, honestly i am having hard time finding similar topics as i posted. I tried searching the posts with keyword port forwarding but the resulting posts is not really similar to what i wanted.

Please guide me where i can find the posts similar to mine, please give me link if there is any.  Thank you so much.

Regards,
Neil

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
how to configure port forwarding
« Reply #3 on: April 23, 2005, 03:03:39 AM »
Ok.. here is the solution ..

let xxx.xxx.xxx.xxx is your public ip (ie the ip of linux box which is connected directly to internet) and yyy.yyy.yyy.yyy as the ip of your machine running in LAN and you want to access it from outside. and take port 6041 as the port which you want to forward .
so here are the rules for iptables.
Code: [Select]
# this one is to redirect request on specific port to internal machine
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d xxx.xxx.xxx.xxx
--dport 6401 -j DNAT --to yyy.yyy.yyy.yyy:6401
# this is to accept the replies
/sbin/iptables -A FORWARD -p tcp -i eth0 -d yyy.yyy.yyy.yyy --dport 6401 -j ACCEPT

Offline neilg_cebu

  • Linux Noob !
  • *
  • Posts: 16
how to configure port forwarding
« Reply #4 on: April 25, 2005, 04:14:36 AM »
Hi Ricky,

Thanks for your help... seems i am on the right way now. But still i am not getting it to work.

I tried creating a rc.forward file and put those script there. Then I add a line on rc.local to run it when the linux run. After that, I can no longer connect to internet. So, I removed it and my internet works back again.

my setup is like this:

eth0 - public IP
eth1 - private IP

I also have a firewall script. It is on rc.firewall file, I just add a line to rc.local to run it when linux run.

Where should I supposed to put those script you have given above? Please be patient in helping me on this -> I am still a beginner on linux.
Thank you so much.

Regards,
Neil

Offline neilg_cebu

  • Linux Noob !
  • *
  • Posts: 16
how to configure port forwarding
« Reply #5 on: April 25, 2005, 07:11:04 AM »
Hi Ricky,

Sorry my mistake. I got it to work now. Thank you very much.

One more question, Do I need to Accept all forwarded ports? such that, If I have 2 lines of PREROUTING, I will also have 2 lines of FORWARD?

Please clear my mind of these things. Thanks.

Cheers,
Neil