tobaru
Port forwarding tool written in Rust with advanced features, such as:
- Allowlists: Only forwards connections from known IPv4 or IPv6 ranges.
- iptables support: Automatically configures iptables to drop packets from unallowed ranges.
- Multiple target addresses: Forwards to different target addresses based on IP.
- TLS encryption/decryption: Accepts unencrypted and TLS-enabled connections, and connects to both unencrypted and TLS-enabled destinations.
- TLS detection: Allows clients to optionally use TLS, and forward them without the TLS layer if they aren't.
- IP groups: named groups of IPs that can be reused amongst different server configurations.
Usage
tobaru <config URL or file> [config URL or file..]
Simple configuration
Simple configuration can be done by passing in URLs on the command line. The format is as follows:
<protocol>://<bind ip>:<bind port>?to=<target ip>:<target port>&key=value&key2=value2&...
- protocol: one of
tcporudp. - bind ip and bind port: ip of the interface and port to listen on
Supported query keys:
- to, targetAddress, target: address to forward to.
- allowlist: list of comma separated netmasks to allow. if this is omitted, all source addresses are allowed.
- tcp_nodelay, nodelay, tcpNodelay: enables tcp_nodelay.
- early_connect, earlyConnect: enables early connect.
Advanced Configuration
Advanced configuration is done using JSON files. One difference from JSON is that configuration files can contain comment lines that begin with //.
Examples
Simple forwarding (command line)
Listens for udp traffic on port 5353 of all interfaces, and forwards to 192.168.8.1 port 8053. All source addresses are allowed.
Simple forwarding (config file)
or with multiple servers and specific IP ranges:
Connections from addresses that are not specified in allowlist will either be dropped (if iptables is set to true), or be immediately closed after accept.
Round-robin forwarding
Multiple destinations based on IP address
TLS support
iptables support
Note that tobaru will need root access in order to configure iptables. It might be possible to do this without root by using setcap(8). Please file a pull request with instructions if you are able to do so.
IP groups
IP groups can be used to quickly specify groups of IPs in multiple servers. Note that IP ranges can be specified in any file and can be reused across different files, for example, it could be convenient invoke tobaru with all IP groups in an individual file: tobaru ip_groups.json http_servers.json ssh_servers.json