Jump to content

SSH Port Forwarding:Quickstart

From jb-vpn.uk Wiki
Revision as of 13:44, 1 January 2026 by Josh (talk | contribs) (Major update - troubleshooting guide: SSH Port Forwarding - Quick Start Guide (25 sections))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

What Changed?

[edit]

The SSH port forwarding system has been refactored from hardcoded iptables rules to a flexible, configuration-driven system. This makes it easy to add SSH access to multiple devices on your VPN.

Before

[edit]
  • Hardcoded iptables rules in /etc/iptables/rules.v4
  • Manual rule management
  • Difficult to add new devices

After

[edit]
  • Configuration file: /etc/ssh-port-forwards.conf
  • Management script: ssh-forward (or ssh-port-forward-manager.sh)
  • Easy to add/remove devices
  • Automatic rule application

Your Existing Setup

[edit]

Your Synology NAS SSH forward has been migrated automatically:

  • Device: synology
  • External Port: 22222
  • VPN IP: 10.8.0.2
  • SSH Port: 22
  • Access: ssh -p 22222 user@87.106.61.62

No changes needed - everything continues to work as before!

Adding a New Device

[edit]

Example: Add a Raspberry Pi

[edit]

Verify the device is on VPN:

[edit]
=== Check if device is connected ===
   cat /etc/openvpn/server/ipp.txt
   ping -c 2 10.8.0.3  # Replace with your device's VPN IP

Add the port forward:

[edit]
   sudo ssh-forward add raspberrypi 22223 10.8.0.3 22

Verify it's active:

[edit]
   sudo ssh-forward list

Test from external location:

[edit]
   ssh -p 22223 user@87.106.61.62

Configure IONOS firewall:

[edit]
  * Log in to https://dcd.ionos.com/
  * Navigate to: Server & Cloud → Servers → [Your VPS] → Firewall
  * Add rule: TCP port 22223 → Allow

Common Commands

[edit]
=== List all SSH port forwards ===
sudo ssh-forward list

== Add a new device ==
sudo ssh-forward add <name> <external_port> <vpn_ip> [ssh_port] # Remove a device
sudo ssh-forward remove <name>

== Reapply all forwards (after manual config edit) ==
sudo ssh-forward apply

Port Recommendations

[edit]
  • 22222-22299: Reserved for SSH port forwards
  • 22222: Synology NAS (already in use)
  • 22223+: Available for new devices

Configuration File

[edit]

Location: /etc/ssh-port-forwards.conf

Format:

device_name:external_port:vpn_ip:ssh_port

Example:

synology:22222:10.8.0.2:22
raspberrypi:22223:10.8.0.3:22

Troubleshooting

[edit]

Port forward not working?

[edit]

Check device is on VPN:

[edit]
   ping -c 2 <vpn_ip>

Verify rules exist:

[edit]
   sudo ssh-forward list
   iptables -t nat -L PREROUTING -n | grep <external_port>

Reapply rules:

[edit]
   sudo ssh-forward apply

Check IONOS firewall allows the port

[edit]

Need more help?

[edit]

See the complete documentation: [SSH Port Forwarding Management](index.md)


Quick Reference: ssh-forward or /usr/local/bin/ssh-port-forward-manager.sh