Tunnel HTTP(S) traffic through a server using SSH
Programming Estimated reading time: ~1 minutes
Sometimes only certain IP addresses are allowed to access an HTTP API endpoint. While developing an application which has to use this API you might want to access the secured API from your developer workstation, though the IP of your workstation is not allowed to access the API (only a server under your control is).
This can be done by proxying your local HTTP traffic through a SOCKS proxy. SOCKS is an Internet protocol that exchanges network packets between a client and server through a proxy server.
The SOCKS proxy will be provided by an ssh
client running on
your developer workstation.
ssh
then forwards the traffic sent to the SOCKS proxy to
your server (which is allowed to access the API endpoint).
Any finally your server makes the request to the API endpoint.
ssh -v -NCD localhost:8080 <username>@server-allowed-to-access-api.com
You can then access the secured API from your local developer workstation by issueing e.g. the following command:
curl -v --socks5-hostname localhost:8080 \
-H "ACCEPT: application/json; charset=UTF-8" \
'http://secured-server.com/api/events'
A note about Netcup (advertisement)
Netcup is a German hosting company. Netcup offers inexpensive, yet powerfull web hosting packages, KVM-based root servers or dedicated servers for example. Using a coupon code from my Netcup coupon code web app you can even save more money (6$ on your first purchase, 30% off any KVM-based root server, ...).