Context
The test environment database resides in an internal network, while my computer can only connect via a jump server. To enable local code access, I tested MobaXterm
for SSH tunneling.
Installation
- Download the free version from the official site: https://mobaxterm.mobatek.net/download.html
- Choose between the portable version (no installation) or installer. I selected the installer for straightforward setup.
Configuration
- Open MobaXterm, navigate to
Tunneling
>New SSH tunnel
- Configure three key sections:
- ① Internal database server IP/port
- ② Jump server SSH credentials (IP, user, port)
- ③ Local port (choose an unused port)
- Click the key icon to configure SSH key authentication for the jump server.
- Restart tunnels via
Stop all tunnels
>Start all tunnels
to apply changes.
Verification
Check port forwarding status:
# Check port 3306 listening status
netstat -ano | findstr "3306"
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 18356
TCP [::]:3306 [::]:0 LISTENING 18356
# Test MySQL service connectivity
telnet 127.0.0.1 3306
N
5.7.22-log [xxx]mysql_native_password
# Random characters indicate successful tunneling
Update database connection string to:
mysql:username:password@tcp(127.0.0.1:3306)/database
- This method also works for Redis and other internal services.