tobaru
Port forwarding tool written in Rust with advanced features, such as:
- Multiple target addresses: Forwards to different target addresses based on IP and TLS SNI/ALPN.
- IPv4/IPv6 allowlists: Only forwards connections from known IP ranges.
- TLS support:
- Accept and connect to unencrypted and TLS-enabled connections
- Detect and clients to optionally use TLS on a single port
- Hot reloading: Updated configs are automatically reloaded.
- iptables support: Automatically configures iptables to drop packets from unallowed ranges.
- IP groups: named groups of IPs that can be reused amongst different server configurations.
Here's a quick example of TLS-based forwarding:
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, target: address to forward to.
- allowlist: list of comma separated netmasks to allow. if this is omitted, all source addresses are allowed.
- tcp_nodelay: enables tcp_nodelay.
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