frp-内网穿透

https://github.com/fatedier/frp

http://fs.as4k.com:7777/fs/mnt/fs/soft/frp_0.29.0_linux_amd64.tar.gz

快速使用

server


[root@ip-172-31-42-40 frp_0.29.0_linux_amd64]# cat xfrps_7001.sh 
#!/bin/bash
# frp server manager script

fdir=/as4k/frp_0.29.0_linux_amd64
frps_config_file=$fdir/frps_7001.ini

kill `ps aux | grep "$frps_config_file" | grep -v grep | awk '{print $2}'` &> /dev/null
sleep 1
cat << 'EOF' > $frps_config_file
[common]
bind_port = 7001
EOF

nohup $fdir/frps -c $frps_config_file &>> $fdir/frps.log &
sleep 2
tail $fdir/frps.log

client



root@DESKTOP-PM5KOT8:~# cat xfrpc_7001.sh 
#!/bin/bash

fdir=/as4k/frp_0.29.0_linux_amd64
frpc_config_file=$fdir/frpc_7001.ini

kill `ps aux | grep "$frpc_config_file" | grep -v grep | awk '{print $2}'` &> /dev/null
sleep 1
cat << 'EOF' > $frpc_config_file
[common]
server_addr = aws.as4k.top
server_port = 7001

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 3306
remote_port = 6001
EOF

nohup $fdir/frpc -c $frpc_config_file &>> $fdir/frps.log &
sleep 2
tail $fdir/frps.log

Access your computer in LAN by SSH

  1. Modify frps.ini:

    # frps.ini
    [common]
    bind_port = 7000
    
  2. Start frps:

./frps -c ./frps.ini

  1. Modify frpc.ini, server_addr is your frps’s server IP:

    # frpc.ini
    [common]
    server_addr = x.x.x.x
    server_port = 7000
    
    [ssh]
    type = tcp
    local_ip = 127.0.0.1
    local_port = 22
    remote_port = 6000
    
  2. Start frpc:

./frpc -c ./frpc.ini

  1. Connect to server in LAN by ssh assuming that username is test:

ssh -oPort=6000 test@x.x.x.x

服务端设置

[root@dp-file-share frp]# ls
frp_0.29.0_linux_amd64  frp_0.29.0_linux_amd64.tar.gz  README.md
[root@dp-file-share frp]# 
[root@dp-file-share frp]# tree frp_0.29.0_linux_amd64
frp_0.29.0_linux_amd64
├── frpc
├── frpc_full.ini
├── frpc.ini
├── frps
├── frps_full.ini
├── frps.ini
├── LICENSE
└── systemd
    ├── frpc.service
    ├── frpc@.service
    ├── frps.service
    └── frps@.service

1 directory, 11 files



[root@dp-file-share frp_0.29.0_linux_amd64]# cat systemd/frps.service 
[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini

[Install]
WantedBy=multi-user.target




[root@dp-file-share frp_0.29.0_linux_amd64]# cat frps.ini 
[common]
bind_port = 7000

[root@dp-file-share frp_0.29.0_linux_amd64]# cp frps /usr/bin
[root@dp-file-share frp_0.29.0_linux_amd64]# ls -l /usr/bin/frps
-rwxr-xr-x. 1 root root 11456096 Oct 23 08:24 /usr/bin/frps


/usr/lib/systemd/system/frps.service

systemctl daemon-reload
systemctl enable frps.service
systemctl start frps.service



[root@dp-file-share frp_0.29.0_linux_amd64]# systemctl status frps.service
● frps.service - Frp Server Service
   Loaded: loaded (/usr/lib/systemd/system/frps.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-10-23 08:25:37 UTC; 4s ago
 Main PID: 7238 (frps)
    Tasks: 4
   Memory: 6.0M
   CGroup: /system.slice/frps.service
           └─7238 /usr/bin/frps -c /etc/frp/frps.ini

Oct 23 08:25:37 dp-file-share systemd[1]: Started Frp Server Service.
Oct 23 08:25:37 dp-file-share frps[7238]: 2019/10/23 08:25:37 [I] [service.go:139] frps tcp listen on 0.0.0.0:7000
Oct 23 08:25:37 dp-file-share frps[7238]: 2019/10/23 08:25:37 [I] [root.go:205] Start frps success

客户端设置

[root@frp-manager frp_0.29.0_linux_amd64]# ls
frpc  frpc_full.ini  frpc.ini  frps  frps_full.ini  frps.ini  LICENSE  systemd



[root@frp-manager frp_0.29.0_linux_amd64]# cat systemd/frpc.service 
[Unit]
Description=Frp Client Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frpc -c /etc/frp/frpc.ini
ExecReload=/usr/bin/frpc reload -c /etc/frp/frpc.ini

[Install]
WantedBy=multi-user.target





[root@frp-manager frp_0.29.0_linux_amd64]# mkdir /etc/frp


[root@frp-manager frp_0.29.0_linux_amd64]# cp frpc /usr/bin
[root@frp-manager frp_0.29.0_linux_amd64]# ls -l /usr/bin/frpc
-rwxr-xr-x 1 root root 10733408 Oct 23 16:43 /usr/bin/frpc


/usr/lib/systemd/system/frpc.service



[root@frp-manager frp_0.29.0_linux_amd64]# cat /etc/frp/frpc.ini
[common]
server_addr = 139.217.99.118
server_port = 7000

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000




systemctl daemon-reload
systemctl enable frpc.service
systemctl start frpc.service



[root@frp-manager frp_0.29.0_linux_amd64]# systemctl status  frpc.service 
● frpc.service - Frp Client Service
   Loaded: loaded (/usr/lib/systemd/system/frpc.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-10-23 16:47:26 CST; 4s ago
 Main PID: 10882 (frpc)
   CGroup: /system.slice/frpc.service
           └─10882 /usr/bin/frpc -c /etc/frp/frpc.ini

Oct 23 16:47:26 frp-manager systemd[1]: Started Frp Client Service.
Oct 23 16:47:26 frp-manager frpc[10882]: 2019/10/23 16:47:26 [I] [service.go:234] login to server success, get run id [fc86e98f209fc6b7], server udp port [0]
Oct 23 16:47:26 frp-manager frpc[10882]: 2019/10/23 16:47:26 [I] [proxy_manager.go:144] [fc86e98f209fc6b7] proxy added: [ssh]
Oct 23 16:47:26 frp-manager frpc[10882]: 2019/10/23 16:47:26 [I] [control.go:153] [ssh] start proxy success

登陆内网机器

ssh -oPort=6000 root@fs.as4k.com