Achieving interconnection between two private networks through Cloudflare Argo Tunnel, supporting TCP/UDP protocol forwarding and TUN devices.
git clone https://github.com/fmnx/cftun.git
cd cftun
go build
This document describes how to deploy the Tunnel service using a JSON configuration file. The configuration file is divided into two main sections: server and client. Users can adjust these according to their requirements.
The JSON configuration file contains two main sections:
- server:Server-related configurations
- client:Client-related configurations
-
token
Authentication token for the server. Use the token generated after creating a tunnel in the Cloudflare dashboard. If you don't have a Cloudflare account, usequick
to request a temporary domain via try.cloudflare.com. The temporary domain remains valid while the server is running. If the server stays offline for over 10 minutes, the domain will expire and change upon restart. Note: Temporary domains require using the client'sglobal-url
withremote
specified in each tunnel configuration. -
edge-ips (optional)
Preferred IP list for the server. The following ranges are supported, with port7844
.198.41.192.0/20 2606:4700:a0::/48 2606:4700:a1::/48 2606:4700:a8::/48 2606:4700:a9::/48
-
ha-conn (optional)
Number of high-availability QUIC connections. Adjust according to network environment. -
bind-address (optional)
Specify the server's egress network interface IP. Leave empty if not required. -
warp (optional)
Add dual-stack support for warp on server egress (based on WireGuard).-
auto (optional)
Whether to automatically apply for warp. Default: false [true|false] -
endpoint (optional)
WireGuard endpoint. Required whenauto
isfalse
. -
ipv4 (optional)
WireGuard IPv4 address. Required whenauto
isfalse
. -
ipv6 (optional)
WireGuard IPv6 address. -
reserved (optional)
Set Warp's WireGuard reserved field. -
private-key (optional)
WireGuard private key. Required whenauto
isfalse
. -
public-key (optional)
WireGuard public key. Required whenauto
isfalse
. -
proxy4 (optional)
Whether to use warp to proxy IPv4 traffic at the egress. [true|false] -
proxy6 (optional)
Whether to use warp to proxy IPv6 traffic at the egress. [true|false]
-
-
cdn-ip (optional)
Preferred Cloudflare Anycast IP. If empty, resolves the domain in the URL. -
cdn-port (optional)
CDN port settings. standard ws port80
, wss port443
, default: 443. -
scheme (optional)
Protocol scheme:ws
orwss
. default: wss.(Required when using non-standard ports). -
global-url (optional)
Tunnel dashboard configuration path. Include full path if applicable. -
tun (optional)
Tun device configuration.-
enable (optional)
Enable the tun device. Default is false. [true|false] -
name (optional)
Tun device name. Defaults tocftun0
. -
ipv4 (optional)
Custom TUN device IPv4 address. -
ipv6 (optional)
Custom TUN device IPv6 address. -
mtu (optional)
Custom TUN device MTU size. -
interface (optional)
Specifies the egress network interface for the tun device. Defaults to the system's primary network interface. -
log-level (optional)
Tun device log level: [debug|info|warn|error|silent]. Defaults toinfo
. -
routes (optional)
TUN device route matching rules. -
ex-routes (optional)
TUN device route exclusion rules.
-
-
tunnels (optional)
List of tunnel configurations:-
listen (required)
Local listening address and port (recommend 127.0.0.1). -
remote (optional)
Forward to specified target address (empty uses dashboard configuration). -
url (optional)
Priority configuration (uses global-url if empty). -
protocol (optional)
tunnel protocol: tcp or udp (default: tcp). -
timeout (optional)
UDP connection timeout in seconds (default: 60).
-
{
"server": {
"token": "quick",
"edge-ips": [
"198.41.192.77:7844",
"198.41.197.78:7844",
"198.41.202.79:7844",
"198.41.207.80:7844"
],
"ha-conn": 4,
"bind-address": ""
}
}
{
"client": {
"cdn-ip": "104.17.143.163",
"cdn-port": 80,
"scheme": "ws",
"global-url": "argo.s01.dev",
"tun": {
"enable": true,
"name": "tun1",
"interface": "eth0",
"log-level": "error",
"routes": [
"0.0.0.0/0",
"::/1"
]
}
}
}
{
"client": {
"cdn-ip": "104.17.143.163",
"cdn-port": 80,
"scheme": "ws",
"global-url": "argo.s01.dev",
"tunnels": [
{
"listen": "127.0.0.1:2408",
"remote": "162.159.192.1:2408",
"protocol": "udp",
"timeout": 30
},
{
"listen": "127.0.0.1:2222",
"remote": "127.0.0.1:22",
"protocol": "tcp"
},
{
"listen": "127.0.0.1:5201",
"remote": "127.0.0.1:5201",
"protocol": "udp",
"timeout": 30
},
{
"listen": "127.0.0.1:5201",
"remote": "127.0.0.1:5201",
"protocol": "tcp"
}
]
}
}