54

I'd like to make all incoming connections to port 1000 of my host (IP: 200.234.XXX.XXX) to be forward to the port 80 on host 10.211.55.5

How can I do it on my host? It is running Mac OS X 10.5.8

1
  • 1
    ah, you're also running parallels, having the same problem as I? :)
    – CodeSmile
    Commented Feb 21, 2013 at 10:36

7 Answers 7

43

Quite simple to do, Firstly you will need to enable the remote login service on your mac (System Preferences -> Sharing -> Remote Login). This starts your ssh server.

Then run the following command in your OS X Terminal:

ssh -L 200.234.XXX.XXX:10000:10.211.55.5:80 -N 127.0.0.1

You may need to accept the server fingerprint initially as well as type in your local password for ssh login. (You can also set up a local to local ssh public / private key to make it not prompt for a password, will leave that as an exercise for the reader.)

The format is:

ssh -L local_addr:local_port:remote_addr:remote_port -N 127.0.0.1
4
  • 1
    Can we do it if port 22 is not open? Commented Oct 14, 2015 at 16:14
  • 1
    You need to connect somehow. But you can always run ssh on another port... perhaps http port? or the BIND (DNS) port? Those are mostly open on firewalls.
    – Marius
    Commented Nov 11, 2015 at 22:53
  • I get connection refused, even though I can connect to the remote server from the browser.
    – Leo
    Commented Apr 14, 2020 at 3:15
  • Just enable Remote Access in MacOS Sharing Settings. You need an enabled ssh server for this to work :) Commented Oct 13, 2020 at 14:47
26

Very simple using the versatile tool ncat:

sudo ncat --sh-exec "ncat 10.211.55.5 80" -l 1000 --keep-open

Get the binaries of ncat/nmap for Mac OS X from the official website: http://nmap.org/download.html#macosx

EDIT: added sudo to listen on a restricted port <1024

4
  • 1
    thanks. it is very simple besides it doesn't need to reboot! Commented Jun 8, 2017 at 7:38
  • 2
    Also you don't need to start the SSH server on your macOS. Commented Jun 14, 2017 at 14:44
  • 3
    You can also install the ncat/nmap via homebrew: brew install nmap. Commented Apr 28, 2020 at 9:02
  • Work for local connections, is there any way to make it accept requests from other clients in the same network?
    – Ghedeon
    Commented Jul 17, 2023 at 14:28
8

Assuming you have a UPnP router, its easy to configure ports by using PortMap

It has a very simple UI.

alt text

1
  • why is your image so tiny?
    – barlop
    Commented Jan 20, 2017 at 11:57
3

Well, I can tell you how I do that sort of thing on my Mac OS X 10.5.8 system.

I started on an answer about NAT, but I think you actually want a TCP forwarder program instead (you mention 'proxy' and port forwarding.)

There's a few ways of doing this, depending upon your needs even 'SSH' can be pressed into action, though my favourite short and sweet way is a Perl script tcpforward.

If you need some HTTP manipulation (you might need to tweak HTTP redirects, so that when a request comes for a URL without a trailing '/' you don't get redirected to the real, inaccessible, server), then Apache can do the job of a reverse proxy. You'll want to look at mod_proxy and specifically ProxyPass and ProxyPassReverse. Do not enable ProxyRequests, that's for forward proxying. It should be possible to use Mac OS's own Apache to do this, if you've got it running. It does come with mod_proxy and /etc/httpd/httpd.conf is the config file to update.

Even with Apache, you need to make sure that all the links in the real server's content are relative, if they reference the real server then you could try the mod_proxy_html module (I have no experience of how well that works.)

1
  • 1
    +1 for tcpforward, Perl never stops being useful. Commented Feb 22, 2019 at 1:39
2

If you're still interested, I've developed an App for port forwarding on macOS. You can check it out here:

https://github.com/hronro/iPortForwarder

It allows you to easily forward a single port or a range of ports without modifying the system firewall.

scrrenshot

2
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jun 29, 2023 at 17:46
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Destroy666
    Commented Jun 29, 2023 at 20:45
0

Is your machine connected directly to the internet (IE - without a router)? Normally you do the port forwarding on the router, but if you do use a modem to connect directly, iptables is probably the best way.

3
  • 1
    I have no idea why this was voted down because it's the truth. Commented Nov 21, 2009 at 0:27
  • 6
    @HasaanChop This is downvoted because it isn't helpful. If it detailed exactly how to use iptables to accomplish what the question asked, that could be useful.
    – Jon-Eric
    Commented Jan 22, 2013 at 21:42
  • 1
    There is no iptables on mac os x.
    – User366
    Commented Oct 7, 2017 at 12:10
-1

Here is a good article: http://www.cyberhq.nl/article/384/port-forwarding-in-macos-x

But since you are forwarding to 80 I'm assuming you want it to go to a web server so I would just change the web server config to set up a reverse proxy or something like that.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .