通信安全及优化

加密与压缩

注: 当 frpc 和 frps 之间启用了 TLS 之后,流量会被全局加密,不再需要配置单个代理上的加密,新版本中已经默认启用。

每一个代理都可以选择是否启用加密和压缩的功能。

加密算法采用 aes-128-cfb,压缩算法采用 snappy。

在每一个代理的配置中使用如下参数指定:

[[proxies]]
    name = "ssh"
    type = "tcp"
    localPort = 22
    remotePort = 6000
    transport.useEncryption = true
    transport.useCompression = true
    

通过设置 transport.useEncryption = true,将 frpc 与 frps 之间的通信内容加密传输,将会有效防止传输内容被截取。

如果传输的报文长度较长,通过设置 transport.useCompression = true 对传输内容进行压缩,可以有效减小 frpc 与 frps 之间的网络流量,加快流量转发速度,但是会额外消耗一些 CPU 资源。

TCP 多路复用

客户端和服务器端之间的连接支持多路复用,不再需要为每一个用户请求创建一个连接,使连接建立的延迟降低,并且避免了大量文件描述符的占用,使 frp 可以承载更高的并发数。

该功能默认启用,如需关闭,可以在 frps.toml 和 frpc.toml 中配置,该配置项在服务端和客户端必须一致:

# frps.toml 和 frpc.toml 中
    transport.tcpMux = false
    

连接池

默认情况下,当用户请求建立连接后,frps 才会请求 frpc 主动与后端服务建立一个连接。当为指定的代理启用连接池后,frp 会预先和后端服务建立起指定数量的连接,每次接收到用户请求后,会从连接池中取出一个连接和用户连接关联起来,避免了等待与后端服务建立连接以及 frpc 和 frps 之间传递控制信息的时间。

这一功能适合有大量短连接请求时开启。

注: 当 TCP 多路复用启用后,连接池的提升有限,一般场景下无需关心。

  1. 首先可以在 frps.toml 中设置每个代理可以创建的连接池上限,避免大量资源占用,客户端设置超过此配置后会被调整到当前值:

    # frps.toml
        transport.maxPoolCount = 5
        
  2. 在 frpc.toml 中为客户端启用连接池,指定预创建连接的数量:

    # frpc.toml
        transport.poolCount = 1
        

支持 KCP 协议

底层通信协议支持选择 KCP 协议,相比于 TCP,在弱网环境下传输效率提升明显,但是会有一些额外的流量消耗。

开启 KCP 协议支持:

  1. 在 frps.toml 中启用 KCP 协议支持,指定一个 UDP 端口用于接收客户端请求:

    # frps.toml
        bindPort = 7000
        # kcp 绑定的是 UDP 端口,可以和 bindPort 一样
        kcpBindPort = 7000
        
  2. 在 frpc.toml 指定需要使用的协议类型,其他代理配置不需要变更:

    # frpc.toml
        serverAddr = "x.x.x.x"
        # serverPort 指定为 frps 的 kcpBindPort
        serverPort = 7000
        transport.protocol = "kcp"
        

支持 QUIC 协议

底层通信协议支持选择 QUIC 协议,底层采用 UDP 传输,解决了 TCP 上的一些问题,传输效率更高,连接延迟低。

开启 QUIC 协议支持:

  1. 在 frps.toml 中启用 QUIC 协议支持,指定一个 UDP 端口用于接收客户端请求:

    # frps.toml
        bindPort = 7000
        # QUIC 绑定的是 UDP 端口,可以和 bindPort 一样
        quicBindPort = 7000
        
  2. 在 frpc.toml 指定需要使用的协议类型,其他代理配置不需要变更:

    # frpc.toml
        serverAddr = "x.x.x.x"
        # serverPort 指定为 frps 的 quicBindPort
        serverPort = 7000
        transport.protocol = "quic"
        
最后修改 November 15, 2023: fix 404 (#71) (626ce4d)

Communication security and optimization

Encryption and compression

Note: When TLS is enabled between frpc and frps Afterwards, the traffic will be globally encrypted, eliminating the need to configure a single Agent The encryption on has been enabled by default in the new version

Each agent can choose whether to enable encryption and compression features

The encryption algorithm uses AES-128-CFB, and the compression algorithm uses Snappy

In the Configuration of each Agent, use the following parameters to specify:

[[proxies]]
    name = "ssh"
    type = "tcp"
    localPort = 22
    remotePort = 6000
    transport.useEncryption = true
    transport.useCompression = true
    

By settingtransport. useEncryption=true, frpc The encrypted transmission of communication content between FRPS will effectively prevent the transmission content from being intercepted.

If the length of the transmitted message is long, set it to transport. useCompression=true Compressing the transmitted content can effectively reduce FRPC and FRPS The network traffic between them accelerates the speed of traffic forwarding, but it will consume some additional CPU Resources.

TCP multiplexing

The connection between the client and server supports multiplexing, eliminating the need to create a connection for each user request, reducing the latency of connection establishment and avoiding the occupation of a large number of file descriptors, making FRP can handle higher concurrency.

This feature is enabled by default. If you want to disable it, you can access it in frps.toml and frpc.toml Configuration, which is located on the Server side Consistent with the client:

# frps.toml 和 frpc.toml 中
    transport.tcpMux = false
    

Connection pool

By default, FRPS only requests FRPC after the user requests to establish a connection Proactively establish a connection with the backend service. When connection pooling is enabled for the specified Agent, frp We will establish a specified number of connections with the backend service in advance. After receiving a user request, we will retrieve a connection from the connection pool and associate it with the user's connection, avoiding waiting for a connection to be established with the backend service The time for transmitting control information between FRPC and FRPS.

This feature is suitable for enabling when there are a large number of short connection requests

Note: When TCP After enabling multiplexing, the improvement of connection pooling is limited and generally not a concern in general scenarios

  1. Firstly, each Agent can be set in frps.toml The maximum number of connection pools that can be created to avoid excessive resource consumption. If the client setting exceeds this configuration, it will be adjusted to the current value:

    # frps.toml
        transport.maxPoolCount = 5
        
  2. Enable connection pooling for Client in frpc.toml, specifying the number of pre-created connections:

    # frpc.toml
        transport.poolCount = 1
        

Supports KCP protocol

The underlying communication protocol supports the selection of KCP protocol, compared to TCP significantly improves transmission efficiency in weak network environments, but there may be some additional traffic consumption.

Enable KCP protocol support:

  1. Enable KCP protocol support in frps.toml and specify a UDP The port is used to receive client requests:

    # frps.toml
        bindPort = 7000
        # kcp 绑定的是 UDP 端口,可以和 bindPort 一样
        kcpBindPort = 7000
        
  2. Specify the protocol type that needs to be used in frpc.toml, other agents Configuration does not require changes:

    # frpc.toml
        serverAddr = "x.x.x.x"
        # serverPort Designated as frps 的 kcpBindPort
        serverPort = 7000
        transport.protocol = "kcp"
        

支持 QUIC 协议

The underlying communication protocol supports the choice of QUIC protocol, and the underlying layer adopts UDP transmission, solving the problem of TCP There are some issues with higher transmission efficiency and lower connection latency.

Enable QUIC protocol support:

  1. Enable QUIC protocol support in frps.toml and specify a UDP The port is used to receive client requests:

    # frps.toml
        bindPort = 7000
        # QUIC 绑定的是 UDP 端口,可以和 bindPort 一样
        quicBindPort = 7000
        
  2. Specify the protocol type that needs to be used in frpc.toml, other agents Configuration does not require changes:

    # frpc.toml
        serverAddr = "x.x.x.x"
        # serverPort 指定为 frps 的 quicBindPort
        serverPort = 7000
        transport.protocol = "quic"
        
Last modified November 15, 2023: fix 404 (#71) (626ce4d)