# frpc - 被控端

### Windows RDP

#### frpc.toml

```toml
serverAddr = "8.137.15.230"
serverPort = 8000
# 如果默认的 STUN 服务器不可用，可以配置一个新的 STUN 服务器
natHoleStunServer = "stun.qq.com:3478"
auth.method = "token"
auth.token = "frpPassW0rd."

[[proxies]]
name = "p2p_rdp"
type = "xtcp"
# 只有共享密钥 (secretKey) 与服务器端一致的用户才能访问该服务
secretKey = "frp.3389"
localIP = "127.0.0.1"
localPort = 3389
```

#### 启动方式 - Windows定时任务

**start\_frpc.bat**

```batch
@echo off
%1 start mshta vbscript:createobject("wscript.shell").run("""%~0"" ::",0)(window.close)&&exit
start /b C:\Users\Will\Software\frp_0.52.3_windows_amd64\frpc.exe -c C:\Users\Will\Software\frp_0.52.3_windows_amd64\frpc.toml >> C:\Users\Will\Software\frp_0.52.3_windows_amd64\frpc.log
```

<figure><img src="https://2457808883-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRxJcEoJGnxpkBfWvFRPw%2Fuploads%2F4ajTHsrex4AiRMokI8k7%2Fimage.png?alt=media&#x26;token=7c279bf2-cbef-45ef-96e7-f0f068bfec67" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2457808883-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRxJcEoJGnxpkBfWvFRPw%2Fuploads%2Fwdwbb1UobzpPtuvVVLZL%2Fimage.png?alt=media&#x26;token=374d0364-88b0-4a81-b480-f3237b724a85" alt=""><figcaption></figcaption></figure>

Win11需要点击“更改用户或组”，输入 SYSTEM，使用SYSTEM用户运行

<figure><img src="https://2457808883-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRxJcEoJGnxpkBfWvFRPw%2Fuploads%2FtMxVBwWskKdz790iQPle%2Fimage.png?alt=media&#x26;token=f4101be8-abd5-447a-9f8d-c8a4ebb6701b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2457808883-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRxJcEoJGnxpkBfWvFRPw%2Fuploads%2FJVSIz8MPvDTIs0ir8Yhd%2Fimage.png?alt=media&#x26;token=ec5e8ce3-0862-4657-9137-07b8b63a58f3" alt=""><figcaption></figcaption></figure>

定时任务的“**常规**” “**触发器**” “**操作**” 按上图配置，其余项按需配置即可

#### addAliyunSecGroup.bat (增加阿里云安全组规则)

此方法使用阿里云CLI进行更新，需要先安装“阿里云CLI”，并配置AccessKey凭证，文档见：

<https://help.aliyun.com/document_detail/121510.html>

<https://help.aliyun.com/document_detail/121258.html#section-5pj-p7j-06z>

```batch
@echo off
setlocal enabledelayedexpansion

for /f "delims=" %%i in ('curl -s 4.ipw.cn') do set IP=%%i

:: 分割IP地址并获取前两个八位段
for /f "tokens=1,2 delims=." %%a in ("!IP!") do (
    set firstPart=%%a
    set secondPart=%%b
)

:: 构造子网掩码为16位的IP地址
set subnetIP=!firstPart!.!secondPart!.0.0/16

echo %date% %time% >> ./aliyunSecGroup.logs
echo !subnetIP! >> ./aliyunSecGroup.logs

"C:\Tools\aliyun-cli-windows-3.0.196-amd64\aliyun.exe" --config-path C:\Users\wd007\.aliyun\config.json ecs AuthorizeSecurityGroup --region cn-chengdu --RegionId cn-chengdu --SecurityGroupId sg-2vc07xnnr7j1ahxq8x9n --Permissions.1.SourceCidrIp !subnetIP! --Permissions.1.IpProtocol TCP --Permissions.1.PortRange 8000/8000 --Permissions.1.Description frp --force >> ./aliyunSecGroup.logs 2>&1
"C:\Tools\aliyun-cli-windows-3.0.196-amd64\aliyun.exe" --config-path C:\Users\wd007\.aliyun\config.json ecs AuthorizeSecurityGroup --region cn-chengdu --RegionId cn-chengdu --SecurityGroupId sg-2vc07xnnr7j1ahxq8x9n --Permissions.1.SourceCidrIp !subnetIP! --Permissions.1.IpProtocol TCP --Permissions.1.PortRange 8500/8500 --Permissions.1.Description frp_web --force >> ./aliyunSecGroup.logs 2>&1

echo. >> ./aliyunSecGroup.logs
::pause
```

### Linux SSH

#### frpc.toml

```toml
serverAddr = "8.137.15.230"
serverPort = 8000
# 如果默认的 STUN 服务器不可用，可以配置一个新的 STUN 服务器
natHoleStunServer = "stun.qq.com:3478"
auth.method = "token"
auth.token = "frpPassW0rd."

[[proxies]]
name = "p2p_ssh"
type = "xtcp"
# 只有共享密钥 (secretKey) 与服务器端一致的用户才能访问该服务
secretKey = "frp.22"
localIP = "127.0.0.1"
localPort = 22

# console or real logFile path like ./frpc.log
log.to = "/usr/local/frp/frpc.log"
# trace, debug, info, warn, error
log.level = "info"
log.maxDays = 30
# disable log colors when log.to is console, default is false
log.disablePrintColor = false
```

#### 启动方式 - frpc.service（systemd方式）

```bash
sudo vim /etc/systemd/system/frpc.service
```

```toml
[Unit]
# 服务名称，可自定义
Description = frpc server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
# 延迟 10s 启动
ExecStartPre=/bin/sleep 10
# 启动frpc的命令，需修改为您的frpc的安装路径
ExecStart = /usr/local/frp/frpc -c /usr/local/frp/frpc.toml
# 启动失败一直重启
Restart=always

[Install]
WantedBy = multi-user.target

```

```bash
systemctl start frpc
systemctl enable frpc
```

#### 启动方式 - Docker

**Dockerfile**

```docker
FROM alpine:latest

ADD ./frp_0.58.1_linux_amd64.tar.gz /usr/local
RUN ln -s /usr/local/frp_0.58.1_linux_amd64 /usr/local/frp

ENV TZ=Asia/Shanghai

ENTRYPOINT ["/usr/local/frp/frpc","-c", "/usr/local/frp/frpc.toml"]
```

**启动命令**

```bash
docker run --name frpc -d \
  --network host \
  -v /usr/local/frp/frpc.toml:/usr/local/frp/frpc.toml \
  frpc:0.58.0
```
