Dynamic Port Forwarding with SOCKS
Dynamic forwarding turns SshTunnel into a local SOCKS4 or SOCKS5 server. Unlike static forwarding, the destination is supplied by each SOCKS client request rather than by DestHostname and DestPort.
The local client must understand SOCKS. Chilkat parses the SOCKS request inside the application process and opens the requested destination through the SSH server.
Where each part runs
| Part | Location | Execution form |
|---|---|---|
| SOCKS-aware client | Usually the local computer | Separate browser, tool, or application process configured to use a SOCKS proxy |
| SOCKS listener | Local computer, inside your application process | Chilkat listener background thread |
| SOCKS parsing and SSH relay | Same application process | Chilkat tunnel-pool and client background threads |
| SSH server | Remote computer | Separate SSH server process that opens each requested destination |
| Destination services | Remote or internal network | Potentially many separate service processes |
Required settings
tunnel.DynamicPortForwarding = true
tunnel.InboundSocksVersion = 5
tunnel.ListenBindIpAddress = "127.0.0.1"
success = tunnel.Connect("ssh.example.com", 22)
// Verify HostKeyFingerprint, then authenticate.
success = tunnel.AuthenticatePk("ssh-user", privateKey)
success = tunnel.BeginAccepting(1080)
When DynamicPortForwarding is true, DestHostname and DestPort are unused. Set InboundSocksVersion to 4 or 5.
Optional inbound SOCKS5 authentication
Set InboundSocksUsername and InboundSocksPassword when clients must authenticate before using the local SOCKS5 listener. When no inbound username is configured, the listener does not require SOCKS authentication. SOCKS4 does not provide password authentication.
127.0.0.1 unless remote clients are intentionally allowed, and require authentication when exposure beyond the local computer is necessary.Inbound SOCKS versus outbound SOCKS
| Purpose | Properties | Direction |
|---|---|---|
| Dynamic forwarding listener | DynamicPortForwarding, InboundSocksVersion, InboundSocksUsername, InboundSocksPassword | A client connects into SshTunnel. |
| Reach the SSH server through an existing SOCKS proxy | SocksVersion, SocksHostname, SocksPort, SocksUsername, SocksPassword | SshTunnel connects outward through a proxy. |
When dynamic forwarding is appropriate
- One browser or tool must reach several remote hosts through the SSH server.
- The destination changes per connection.
- The client software already supports SOCKS4 or SOCKS5 configuration.
Use static forwarding instead when the client does not support SOCKS or when a stable local-port-to-destination mapping is simpler.