Home > Database > Mysql Tutorial > body text

SSH tunnel external access MySQL tutorial

零下一度
Release: 2019-02-22 17:36:16
Original
2390 people have browsed it

Port mapping is actually to convert a port of one of the network devices (a router, a computer or server) to another network device. The actual The above is a type of NAT address translation.

Recommended related mysql video tutorials: "mysql tutorial"

linuxThe port forwarding function implemented by the ssh connection command, in the explanation of port forwarding Before, let’s first understand the parameters of ssh command:

-f background authentication user/password, usually used in conjunction with -N, without logging in to the remote host;

-p The sshd service port of the logged-in ssd server;

-L forwards a certain port of the local machine (client) to the specified port of the remote specified machine. The working principle is as follows. A socket listening port is allocated on the local machine. Once there is a connection on this port, the connection is forwarded through the Secure channel, and at the same time the remote host and the host's hostport port are established. connect. Port forwarding can be specified in the configuration file. Only root can forward privileged ports;

-R forwards a port of the remote host (server) to the specified port of the local specified machine. The working principle is as follows. A socket listening port is allocated on the remote host. Once there is a connection on this port, the connection is redirected out through the secure channel, and a connection is established between the local host and the host's hostport port.
You can specify port forwarding in the configuration file. Only logging in to the remote host as root can forward privileged ports.

-D specifies a local machine "dynamic" application port forwarding. The working principle is this, a socket listening port is allocated on the local machine. Once there is a connection on this port, the connection It is forwarded through the secure channel, and you can determine where the remote host will connect according to the protocol of the application. Currently, it supports the SOCKS4 protocol and will act as a SOCKS4 server. Only root can forward privileged ports. Dynamic port forwarding can be specified in the configuration file.

-C compresses data transmission.
-N does not execute scripts or commands. It is usually used with -f.
-g allows remote hosts to connect to the established forwarded port. If this parameter is not added, only The local host establishes a connection.

Note: Commands and parameters under Linux are strictly case-sensitive.

Example:

Open port 8080 of a certain host to port 8080 of the local host. Tunnel
ssh -N -L8080:localhost:80 Remote host
Now you can directly enter localhost:8080 in the browser to access this website

The three commonly used forwarding commands are:

ssh -C -f -N -g -L 
list
en_port:DST_Host:DST_port user@Tunnel_Host
ssh -C -f -N -g -R listen_port:DST_Host:DST_port user@Tunnel_Host
ssh -C -f -N -g -D listen_port user@Tunnel_Host
Copy after login

Based on security considerations,

MySQLThe 3306 port of the server can only be accessed internally, and the firewall only opens the ssh port externally. In this case, we can use the SSH tunnel to directly access MySQL from outside. .

ssh -p22 -CNg -L 3307:rds1r2cp34235345236.mysql.rds.aliyuncs.com:3306 root@localhost

The password is the ssh root user password

and then The Windows client connects to the server IP, the port is mapped 3307, the user of aliyun-mysql, the password is

[Related recommendations]

1.

Free mysql online video tutorial

2.

MySQL latest manual tutorial

3.

Boolean Education Yan Shiba mysql introductory video tutorial

The above is the detailed content of SSH tunnel external access MySQL tutorial. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!