内网穿透的英文叫做NAT traversal,又被称为端口映射或内网映射,内网穿透是网络连接术语,如下图如果我(局域网A中的一台服务器)想访问另一个局域网c中的一台服务器,可以通过拥有公网ip的B服务器加上frp服务完成端口转发,达到访问效果。
frps/frpc的工具包的github地址是:
https://github.com/fatedier/frp/releases/
根据对应服务器架构下载适合自己的工具包
#上传后解压
[root@VM-120-2-centos ~]# tar -xvf frp_0.38.0_linux_amd64.tar.gz
[root@VM-120-2-centos ~]# mv frp_0.38.0_linux_amd64 /usr/local/frp/
#创建frp.service
[root@VM-120-2-centos ~]# vim /usr/lib/systemd/system/frp.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.ini
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
StandardOutput=syslog
StandardError=inherit
[Install]
WantedBy=multi-user.target
[root@VM-120-2-centos ~]# cd /usr/local/frp/
[root@VM-120-2-centos ~]# vim frps.ini
[common]
bind_port = 7000
dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = admin
authentication_method = token
token = pass123456
[root@VM-120-2-centos ~]# systemctl daemon-reload
[root@VM-120-2-centos ~]# systemctl enable --now frp
[root@VM-120-2-centos ~]# netstat -ntlp
[root@VM-120-10-centos ~]# tar -xvf frp_0.38.0_linux_amd64.tar.gz
mv frp_0.38.0_linux_amd64 /usr/local/frp/
cd /usr/local/frp/
vim frpc.ini
[common]
#服务器公网ip
server_addr = 43.137.8.225
authentication_method = token
token = pass123456
server_port = 7000
[Fusion-ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 20022
[Fusion-rdp]
type = tcp
local_ip = 127.0.0.1
local_port = 3389
remote_port = 23389
[nginx]
type = tcp
local_ip = 127.0.0.1
local_port = 80
remote_port = 18080
nohup ./frpc -c ./frpc.ini &
#在服务端上执行
[root@VM-120-2-centos ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1586/sshd
tcp6 0 0 :::23389 :::* LISTEN 15020/frps
tcp6 0 0 :::18080 :::* LISTEN 15020/frps
tcp6 0 0 :::7500 :::* LISTEN 15020/frps
tcp6 0 0 :::20022 :::* LISTEN 15020/frps
tcp6 0 0 :::7000 :::* LISTEN 15020/frps
Windows中打开cmd
现在通过主机A(WIndows)进行ssh访问,我们还知道主机B和主机C都是linux系统。
那么ssh命令的格式是为: ssh -p 公网的转发端口 主机C的用户名@公网的ip(如下图)