traffics

command module
v0.0.0-...-3be1a74 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2025 License: MIT Imports: 31 Imported by: 0

README

Traffics

A simple but powerful port forwarding service

Overview

Traffics is a lightweight port forwarding tool that supports TCP, UDP, and mixed protocol traffic forwarding. It features simple configuration and high performance.

Installation

# Clone the project
git clone --depth=1 --branch=main https://github.com/woshikedayaa/traffics.git

# Build the project
cd traffics/
mkdir -p bin/ && CGO_ENABLED=0 go build -ldflags="-w -s" -v -o bin/traffics .

# Optional: Install to system PATH
install -o root -g root -m 0755 bin/traffics /usr/bin/traffics

Architecture

Traffics uses a Binds (listeners) + Remotes (targets) architecture:

  • Binds: Local listening configuration, defines ports and protocols to listen on
  • Remotes: Remote target configuration, defines destination servers for forwarding

Traffic flow: Client → Bind Listener → Remote Target Server

Usage

Zero Config Mode (Command Line)

Supports multiple forwarding rules:

# Single rule
traffics -l "tcp+udp://:5353?remote=dns" -r "dns://1.1.1.1:53"

# Multiple rules
traffics \
  -l "tcp+udp://:5353?remote=dns" \
  -l "tcp://:8080?remote=web" \
  -r "dns://1.1.1.1:53?timeout=5s" \
  -r "web://192.168.1.100:80?tfo=true"
Configuration File Mode
traffics -c config.json

Configuration File Format

Configuration files support two formats: URL shorthand and complete configuration, which can be mixed.

Basic Structure
{
  "log": {
    "level": "info"
  },
  "binds": [
    "tcp+udp://:5353?remote=dns&udp_ttl=60s",
    {
      "listen": "::",
      "port": 8080,
      "network": "tcp",
      "remote": "web"
    }
  ],
  "remotes": [
    "dns://1.1.1.1:53?strategy=prefer_ipv4&timeout=5s",
    {
      "name": "web",
      "server": "192.168.1.100", 
      "port": 80,
      "timeout": "10s"
    }
  ]
}
URL Formats
Bind URL
protocol://[address]:port?param=value&param=value
Remote URL
name://server:port?param=value&param=value

Configuration Reference

Log Configuration
  • disable: Disable logging (default: false)
  • level: Log level - trace, debug, info, warn, error, fatal, panic
Bind Configuration

Required fields:

  • listen: Listen address
  • port: Listen port
  • remote: Associated remote service name

Optional fields:

  • name: Bind configuration name
  • network: Network protocol - tcp, udp, tcp+udp (default: tcp+udp)
  • family: IP version - 4 or 6
  • interface: Bind to network interface
  • reuse_addr: Enable address reuse
  • tfo: TCP Fast Open
  • mptcp: Multipath TCP
  • udp_ttl: UDP connection timeout (e.g., "60s")
  • udp_buffer_size: UDP buffer size (default: 65507)
  • udp_fragment: UDP fragmentation support
Remote Configuration

Required fields:

  • server: Target server address
  • port: Target server port
  • name: Remote service name (corresponds to remote field in bind)

Optional fields:

  • dns: Custom DNS server
  • strategy: DNS resolution strategy - prefer_ipv4, prefer_ipv6, ipv4_only, ipv6_only
  • interface: Outbound network interface
  • timeout: Connection timeout (e.g., "5s")
  • reuse_addr: Enable address reuse
  • bind_address4: IPv4 bind address
  • bind_address6: IPv6 bind address
  • fwmark: Firewall marka
  • mptcp: Multipath TCP
  • udp_fragment: UDP fragmentation support

Note: URL parameters use the same field names as JSON configuration.

Example Configuration

{
  "log": {
    "level": "info"
  },
  "binds": [
    "tcp+udp://:5353?remote=dns&udp_ttl=60s",
    {
      "listen": "0.0.0.0",
      "port": 8080,
      "network": "tcp", 
      "remote": "web",
      "tfo": true
    }
  ],
  "remotes": [
    "dns://1.1.1.1:53?strategy=prefer_ipv4&timeout=10s",
    {
      "name": "web",
      "server": "backend.example.com",
      "port": 80,
      "timeout": "15s"
    }
  ]
}

Important Notes

  1. In tcp+udp mode, both TCP and UDP traffic will be forwarded to the same remote service
  2. The remote field in binds must match the name field in remotes configuration
  3. URL parameters and JSON field names are identical
  4. Both URL and complete configuration formats can be mixed in the same configuration file

Acknowledgments

This project uses the following excellent open-source libraries:

  • tfo-go - TCP Fast Open implementation for Go
  • dns - DNS library in Go
  • sing - Universal proxy platform

We are grateful to all contributors and maintainers of these projects for their valuable work.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
infra
proxy

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL