1

Here's my situation:

  • I have a computer (Mac) on a school network that I want to port forward TCP 5222 to for ejabberd, but of course I can't.
  • I have a server at home (Mac with FreeBSD VM) that I can port forward to.

Is there a simple way to set up my home server to relay incoming and outgoing TCP traffic over port 5222 to/from my computer at school? I know it's possible to make my computer at school connect to the one at home and send/receive everything through it, and I could write a program to do this, but I want to know if there's an easier way. It seems like there would already be a Unix utility to do this.

4
  • 3
    ssh does port forwarding. That's by far the most common.
    – derobert
    Nov 4, 2014 at 22:05
  • I knew about ssh tunneling for connecting to servers through a tunnel but didn't know it could be used for port forwarding. Good idea.
    – sudo
    Nov 5, 2014 at 0:36
  • 1
    SOCKS would be a good approach for generic relaying
    – roaima
    Oct 20, 2021 at 14:34
  • A trip through memory lane. I asked this question in my freshman college year then soon found out that they actually gave us each a separate public IP address anyway in the dorms without a NAT.
    – sudo
    Nov 5, 2021 at 5:20

1 Answer 1

1

My home server already has sshd running. I read up on ssh tunneling as derobert suggested, and I figured it out with the help of some further Googling:

  1. Set up necessary port forwarding, firewall passthrough, etc. to TCP 5222 on the server at home.
  2. Enable gateway ports: Edit /private/etc/sshd_config on Mac (or /etc/ssh/sshd_config on Linux) so that it has the line GatewayPorts yes exactly once and no contradictory GatewayPorts no line.
  3. Restart sshd on the server (launchctl stop com.openssh.sshd then launchctl start com.openssh.sshd on Mac)
  4. On my computer at school, ssh -R 5222:localhost:5222 user@home_ip_address

Now, connections to home_ip_address on port 5222 are tunneled to my computer at school. Yay!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.