vpn+frp内网穿透全协议打通

/ Linux_manage / 没有评论 / 1196浏览

1. Environment

frpsfrps.ini 放到具有公网 IP 的机器上。server端

frpcfrpc.ini 放到处于内网环境的机器上。client端

HostOS网络防火墙ip地址Software
阿里云主机Ubuntu 18.04.2 LTS可连接internet,固定ip关闭,相关安全组打开1.1.1.1frps
内网主机Ubuntu 18.04.4 LTS可连接internet,没有固定ip关闭192.168.0.123frpc openvpn

openvpn:192.168.0.123 :1194

2. Install frp server use Official script

地址:https://github.com/fatedier/frp

中文地址:https://github.com/fatedier/frp/blob/master/README_zh.md

在阿里云服务器上部署server端,server端需要公网ip

# apt 更新
apt-get update

# 下载frps服务端脚本
wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh

# 修改脚本权限
chmod 700 ./install-frps.sh

# 执行脚本安装
./install-frps.sh install


Please select frps download url:
[1].aliyun (default)
[2].github
Enter your choice (1, 2 or exit. default [aliyun]): 1
---------------------------------------
Your select: 1
---------------------------------------
Loading network version for frps, please wait...
frps Latest release file frp_0.20.0_linux_amd64.tar.gz
Loading You Server IP, please wait...
You Server IP:1.1.1.1
Please input your server setting:

Please input frps bind_port [1-65535](Default Server Port: 5443):
frps bind_port: 5443


Please input frps vhost_http_port [1-65535](Default vhost_http_port: 80):4534
frps vhost_http_port: 4534


Please input frps vhost_https_port [1-65535](Default vhost_https_port: 443):4443
frps vhost_https_port: 4443


Please input frps dashboard_port [1-65535](Default dashboard_port: 6443):
frps dashboard_port: 6443

Please input dashboard_user (Default: admin):
frps dashboard_user: admin

Please input dashboard_pwd (Default: XyQbHI54):Swl19960706
frps dashboard_pwd: Swl19960706

Please input token (Default: oTmRbwfBJ6fE4cKE):
frps token: oTmRbwfBJ6fE4cKE


Please input frps max_pool_count [1-200]
(Default max_pool_count: 50):
frps max_pool_count: 50

##### Please select log_level #####
1: info (default)
2: warn
3: error
4: debug
#####################################################
Enter your choice (1, 2, 3, 4 or exit. default [1]):
log_level: info


Please input frps log_max_days [1-30]
(Default log_max_days: 3 day):30
frps log_max_days: 30

##### Please select log_file #####
1: enable (default)
2: disable
#####################################################
Enter your choice (1, 2 or exit. default [1]):
log_file: enable

##### Please select tcp_mux #####
1: enable (default)
2: disable
#####################################################
Enter your choice (1, 2 or exit. default [1]):
tcp_mux: true

##### Please select kcp support #####
1: enable (default)
2: disable
#####################################################
Enter your choice (1, 2 or exit. default [1]):
kcp support: true

============== Check your input ==============
You Server IP      : 1.1.1.1
Bind port          : 5443
kcp support        : true
vhost http port    : 4534
vhost https port   : 4443
Dashboard port     : 6443
Dashboard user     : admin
Dashboard password : password
token              : oTmRbwfBJ6fE4cKE
tcp_mux            : true
Max Pool count     : 50
Log level          : info
Log max days       : 30
Log file           : enable
==============================================

Press any key to start...or Press Ctrl+c to cancel
frps install path:/usr/local/frps
config file for frps ... done
download frps ... done
download /etc/init.d/frps... done
setting frps boot... done

+--------------------------------------------------+
|        Manager for Frps, Written by Clang        |
+--------------------------------------------------+
| Intro: http://koolshare.cn/thread-65379-1-1.html |
+--------------------------------------------------+

Starting Frps(0.20.0)... done
Frps (pid 28794)is running.

+---------------------------------------------------------+
|        frps for Linux Server, Written by Clang          |
+---------------------------------------------------------+
|     A tool to auto-compile & install frps on Linux      |
You Server IP      : 1.1.1.1
+---------------------------------------------------------+
|    Intro: http://koolshare.cn/thread-65379-1-1.html     |
+---------------------------------------------------------+


Congratulations, frps install completed!
==============================================
You Server IP      : 1.1.1.1
Bind port          : 5443
KCP support        : true
vhost http port    : 4534
vhost https port   : 4443
Dashboard port     : 6443
token              : oTmRbwfBJ6fE4cKE
tcp_mux            : true
Max Pool count     : 50
Log level          : info
root@ali:/usr/local/frps# frps start
2020/06/14 17:45:22 [I] [service.go:128] frps tcp listen on 0.0.0.0:7000
2020/06/14 17:45:22 [I] [root.go:190] Start frps success

Log max days       : 30
Log file           : enable
==============================================
frps Dashboard     : http://1.1.1.1:6443/
Dashboard user     : admin
Dashboard password : password

3. dashboard on browser

http://1.1.1.1/6443 Dashboard user : admin Dashboard password : password

4. Port usage on frp server

在frp

root@ali:~# netstat -lntup | grep frp
tcp6       0      0 :::80                   :::*                    LISTEN      29895/frps
tcp6       0      0 :::4534                 :::*                    LISTEN      28794/frps
tcp6       0      0 :::7000                 :::*                    LISTEN      29895/frps
tcp6       0      0 :::443                  :::*                    LISTEN      29895/frps
tcp6       0      0 :::4443                 :::*                    LISTEN      28794/frps
tcp6       0      0 :::5443                 :::*                    LISTEN      28794/frps
tcp6       0      0 :::6443                 :::*                    LISTEN      28794/frps
udp6       0      0 :::1995                 :::*                                29895/frps
udp6       0      0 :::5443                 :::*                                28794/frps

5.Install fro client on linux and 64

下载地址:https://github.com/fatedier/frp/releases/

国内下载地址:https://file.kskxs.com/?dir=frp

root@jms-ansible-prom-123:/usr/local/frp_0.32.1_linux_amd64# pwd
/usr/local/frp_0.32.1_linux_amd64

5.1 opevpn

5.1 Client configuration file

frpcfrpc.ini 放到处于内网环境的机器上。client端

dns 配置块,注意 vpn的默认端口改为1995

root@jms-ansible-prom-123:/usr/local/frp_0.32.1_linux_amd64# cat frpc.ini
[common]
server_addr = 1.1.1.1
server_port = 7000
privilege_token = oTmRbwfBJ6fE4cKE
[dns]
type = udp
local_ip = 192.168.0.123
local_port = 1194
remote_port = 1995

附赠一个https 协议的

# root @ k8s-master-171 in /tmp/frp_0.32.1_linux_amd64 [20:38:41]
$ cat frpc.ini
[common]
server_addr = 1.1.1.1
server_port = 7000
privilege_token = oTmRbwfBJ6fE4cKE

[https]
type = tcp
local_ip = 1.1.1.1
local_port = 443
remote_port = 443
custom_domains = 1.1.1.1

[http]
type = tcp
local_ip = 192.168.0.171
local_port = 80
remote_port = 80
custom_domains = 1.1.1.1

5.2 run frpc

$ ./frpc -c ./frpc.ini

Supervisor conf

[program:frpc]
directory = /usr/local/frp_0.32.1_linux_amd64
command = /usr/local/frp_0.32.1_linux_amd64/frpc -c frpc.ini
user=root
numprocs=1
stopsignal=KILL
startretries=1
autostart=true
redirect_stderr=true
stdout_logfile = /opt/supervisord/var/log/frpc.log

6 demo

Vpn 连接

内网连接测试