Find the answer to your Linux question:
Results 1 to 7 of 7
I want the equivalent of ssh 192.168.0.2 -L 5900:192.168.0.2:5901 (the machine I am on is 192.168.0.3) but without SSHing! I thought you could do this with iptables, but I tried ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    41

    iptables Local Port Forwarding?


    I want the equivalent of
    ssh 192.168.0.2 -L 5900:192.168.0.2:5901
    (the machine I am on is 192.168.0.3)

    but without SSHing! I thought you could do this with iptables, but I tried this

    sudo iptables -t nat -A PREROUTING -p tcp -d 192.168.0.3 --dport 5900 -j DNAT --to 192.168.02:5901
    sudo service iptables save

    but it doesn't seem to work. Basically I want any traffic coming to .0.3 on a particular port to be forwarded to .0.2 on a different port.

    Please let me know if you know how to do this.

    Thanks!

    David

  2. #2
    Just Joined! vigour's Avatar
    Join Date
    Oct 2007
    Posts
    68
    If you are redirecting the traffic to a local port on the machine, I suggest you use REDIRECT instead of DNAT.

  3. #3
    Just Joined!
    Join Date
    Apr 2007
    Posts
    41
    is that command correct though if I want to forward traffic on a port on the local machine to a different machine on the network?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,677
    If you are redirecting to another machine then DNAT is correct.
    Also turn on FORWARDing and set that up as well.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

  6. #5
    Just Joined!
    Join Date
    Jan 2008
    Posts
    9
    I also can't get this working locally at my home PC. Has anybody managed the issue?

    P.S. DNAT doesn't work locally, REDIRECT is not applicable in above-mentioned situation.

  7. #6
    Just Joined!
    Join Date
    Apr 2007
    Posts
    41
    artemn and all: check this out:
    Portfwd

    worked great for me!

  8. #7
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,677
    This is a great Tutorial for IPTABLES.

    http://iptables.rlworkman.net/chunkyhtml/index.html

    Check it out it might give you waht you are looking for.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •