Skip to content

Command line ​

ours <command> [flags]
CommandWhat it does
runRuns the proxy with a configuration
checkChecks a configuration without opening anything; with flags, compares, shows, downloads subscriptions
explainShows where a connection or a DNS query would go and which rules decided it
formatChecks a configuration and tidies up spaces and blank lines
schemaPrints the JSON Schema of the configuration format for an editor
generateUUIDs, random bytes, REALITY (X25519, ML-DSA-65) and WireGuard keys, Admin API password hashes
rule-setCompiles, decompiles and converts rule-sets and checks what matches in them
toolsDownloads a URL or connects to an address through an outbound of the configuration
cleanRemoves nftables tables, rules and routes left behind by a killed process
clientClients: WireGuard peers and their configurations, links and the subscription of inbounds
versionVersion and features of the build

ours --help (or ours help) lists the commands, ours help <command> and ours <command> --help the command's flags. An unknown command, an unknown flag or a flag of another command ends with an error and the command's help. ours --version and ours -V are the same as ours version.

Where the configuration comes from ​

The configuration is one YAML file (.yaml or .yml). How the file is laid out is in Configuration.

FlagMeaning
-c, --config <path>The configuration file. config.yaml by default. The value - (or stdin) reads from standard input. For run, check, explain, format and clean the path can also be written without the flag: ours check config.yaml
-C, --config-directory <directory>A directory holding exactly one *.yaml or *.yml file (subdirectories are ignored)
-D, --directory <directory>The working directory: the process changes to it before reading the configuration, and relative paths (including -c) are taken from it. A directory that does not exist is created

run, check and explain take one configuration: -c or -C is given once (otherwise the error is one configuration: give `-c` or `-C` once), and a second path without a flag is an error too. A -C directory must contain exactly one YAML file, otherwise the error is the configuration directory holds N YAML files; the runtime takes one. There is no merging of several files.

A file with another extension is an error; a directory in -c is an error with a hint about -C. The value of a long flag can be written after =: --config=/etc/ours/config.yaml.

run ​

sh
ours run -c /etc/ours/config.yaml
FlagMeaning
--watchReload the configuration when the -c files or a .yaml or .yml file in a -C directory changes
--dashboard <ip:port>Open the Admin API and the dashboard on a loopback address — Dashboard; takes precedence over admin.listen
--cpus auto|0,1,…, --cpu-affinity pin|none, --shards <N>Replace the fields of the same name in the runtime section; also apply on reload

The log starts with a line about the build, ours 0.1.0 (<commit>, <build date>, <target>) starting; then the process writes ours started (…) and runs until a signal. Loading warnings (an empty group, a skipped subscription server) go to the log after startup.

Signals ​

SignalAction
SIGHUPReread the configuration from disk and apply it without a restart
SIGUSR1Reopen the active log file
SIGINT, SIGTERMStop: remove the auto_nft interception, close inbounds and connections

Shutdown closes live connections without draining. Once interception is removed, component shutdown has 10 seconds. If components do not close in time, or a second SIGINT or SIGTERM comes during this wait, the process exits with code 1.

A reload (by SIGHUP, --watch or from the dashboard) is applied as a whole or not at all: on any error the previous configuration keeps running, and the error is written to the log as reload: …. A successful reload writes how many components changed and how many connections were closed and kept. What happens to live connections is set by reload.

Reload also applies changes to the log level, format and output, and to the runtime settings other than the number of shards.

check ​

sh
ours check -c config.yaml

Without extra flags check parses the file, checks names and references and builds all components the same way as run, but does not open listeners and does not go to the network. Subscriptions are taken from their file source or from the cache. Warnings are printed as WARN … lines. For a TProxy listener or a privileged inbound port in the current network namespace, check reads Linux's effective capabilities for the checking process and warns when the process lacks the capability needed by that listener.

check does not touch the directory of the cache section: it neither creates nor locks it.

FlagWhat it prints
--diff <file>What a reload from the -c configuration to <file> would change: which components are rebuilt, removed, kept; how the configured choice of groups changes
--viewThe configuration as the dashboard sees it: JSON with the parsed sections (config) and the place of each object in the YAML (objects). Passwords, UUIDs, keys, short_id, *_seed, tokens, and URL paths and queries are replaced with REDACTED, so the output can be attached to an issue
--view --secretsThe same with the secrets
--fetchDownloads each subscription and prints what is in it: the number of servers, the format, the names, the provider's groups, what was skipped and why

--diff compares only files: it does not see a choice made by hand in a running process or probe results. A difference between configurations is not an error: the exit code is 0.

--fetch goes to the network: remote through the subscription's via, file is read from disk. Names are printed as the provider served them, before rename and the filters. If at least one subscription fails to download, the exit code is 1.

explain ​

Runs the route rules on the connection described by the flags, with the same code and the same rule-sets as the live process. Sniffing is not performed: what it would find is given by flags.

sh
ours explain -c config.yaml --inbound local --destination example.com:443 --protocol tls
FlagMeaning
--inbound <name>The inbound the connection came to; required
--destination <host:port>Where the connection goes; required
--network tcp|udptcp by default
--source <ip:port>The source; 0.0.0.0:0 by default
--protocol <name>What sniffing would find: tls, http, quic, dns, stun, bittorrent, dtls, ssh, rdp, ntp
--domain <name>The domain sniffing would find
--client <name>The client sniffing would find

The output is every rule checked, with its result (matched, no match) and an explanation by condition, then the decision: => outbound <name> (rule[N]), => outbound <name> (route.final: …), => reject, => hijack-dns. If a rule replaced the destination address, to … is printed below.

DNS query ​

sh
ours explain -c config.yaml --dns example.com --type AAAA
FlagMeaning
--dns <domain>Which domain is asked for
--type <type>The query type: A (default), AAAA or any other by name or number
--inbound <name>, --source <ip:port>Where the query came from, for conditions on the inbound and the source

The steps through dns.rules are printed (matched, no match, or undecided for conditions on the answer: servers are not queried), then the decision.

explain loads rule-sets as at startup: remote ones are taken from the cache or initial_path, otherwise downloaded.

schema ​

sh
ours schema schema.json

Writes the JSON Schema (Draft 2020-12) of the configuration format to a file or, without an argument, to standard output. The schema describes the sections and field names of exactly this build, for autocompletion and highlighting unknown keys in an editor. The schema hardly checks field values: types and references are checked by check. To use it in an editor with yaml-language-server, add a line at the top of the file:

yaml
# yaml-language-server: $schema=./schema.json

format ​

sh
ours format -c config.yaml        # print
ours format -c config.yaml -w     # write back to the file

First the configuration is loaded the same way as in check before the components are built: an error in it is an error of the command. Then the text is tidied line by line: LF line endings, no trailing spaces, no blank lines at the start, no more than one blank line in a row, one newline at the end. Comments, key order, indentation and quotes stay as written. If such an edit would change the content (spaces inside a | block scalar), the file is output as is with a WARN warning.

With -w (--write) the result is written to the same file, only if it changed; the path of the changed file is printed to stderr. A configuration from stdin cannot be written.

generate ​

CommandWhat it prints
generate uuidA version 4 UUID, for the uuid of VLESS and TUIC users
generate rand <length> [--base64 | --hex]<length> random bytes: raw, in base64 or hex, for passwords and REALITY short_id (--hex)
generate reality-keypairX25519 PrivateKey: and PublicKey: in base64url without =, for the server's reality.private_key and the client's public_key
generate mldsa65-keypairML-DSA-65 Seed: and Verify: in base64url without =, like xray mldsa65, for the server's reality.mldsa65_seed and the client's mldsa65_verify
generate wg-keypairWireGuard PrivateKey: and PublicKey: in base64
generate password-hashAn argon2id password hash in PHC format (m=19456,t=2,p=1, per OWASP), for password_hash in admin.users. From a terminal it asks for the password twice without echo; if stdin is not a terminal it takes the first line of stdin

The output matches sing-box generate; mldsa65-keypair matches xray mldsa65. password-hash has no counterpart in sing-box or Xray.

rule-set ​

Works with rule-set files without a configuration, with the same code that rule_sets reads them with. stdin can be written instead of a path.

sh
ours rule-set compile rules.json                     # → rules.srs
ours rule-set decompile -o rules.json rules.srs
ours rule-set convert -t adguard filter.txt          # → filter.srs
ours rule-set convert -t dat --category cn --category google@cn geosite.dat   # → geosite-cn-google@cn.srs
ours rule-set match rules.srs example.com
ours rule-set match --category private geoip.dat 192.168.1.1
ActionWhat it does
compile [-o file] <source.json>sing-box JSON format → .srs in the lowest version that holds the rules (like sing-box rule-set compile). By default .json is replaced with .srs
decompile [-o file] <file.srs>.srs → JSON. AdGuard rules are not translated back: an error, as in sing-box
convert -t adguard [-o file] <filter.txt>An AdGuard DNS filter → .srs (version 2), adguard_domain rules. Unsupported lines are skipped and their number is printed to stderr: parsed rules: N/M
convert -t dat --category <code>… [-o file] <file.dat>geosite.dat/geoip.dat categories → .srs; by default <name>-<codes joined by ->.srs
match [-f source|binary|dat] [--category <code>…] <file> <domain | IP>Prints the rules of the file that matched: match rules.[N]: <rule>

The default format of match follows the extension: .srs is binary, .dat is dat, otherwise source. --category is written as in rule_sets (cn, google@cn, !cn) and is repeated for several codes. match checks only the destination address: the port is 0, the network TCP.

tools ​

sh
ours tools fetch -c config.yaml -o proxy https://example.com/
echo -e 'GET / HTTP/1.0\r\n\r' | ours tools connect -c config.yaml example.com:80
ours tools connect -n udp -o proxy 1.1.1.1:53 < query.bin

Builds the configuration, starts DNS and the outbounds, but does not open inbounds, so it can run next to a working ours. Without -c/-C and without config.yaml in the working directory, connections go directly.

FlagMeaning
-o, --outbound <name>An outbound or a group; route.final by default
-n, --network tcp|udpconnect only; tcp by default

fetch <url>… downloads over HTTP/1.1 (http, https; without a scheme, http), following redirects, with User-Agent: ours/<version>, and writes the body to stdout. A status other than 2xx is printed to stderr.

connect <host:port> copies stdin into the connection and the answer to stdout. Over TCP, after the end of stdin the sending side is closed and the answer is read until the server closes. Over UDP each chunk read from stdin is a separate packet; after the end of stdin, answers are awaited until 5 seconds pass without any.

version ​

sh
ours version       # ours version 0.1.0, commit, build date, target, platform, features
ours version -n    # the number only

The commit is a short hash, with -dirty if the working tree had uncommitted changes, and unknown when built outside a git checkout. The build date is UTC; when SOURCE_DATE_EPOCH is set, it is taken from there.

clean ​

sh
ours clean -c config.yaml

Removes what the process installs in the kernel and did not manage to remove because it was killed (SIGKILL, OOM, panic): the inet ours table and the auto_nft policy routing rules of the tproxy inbound, the inet ours-tun table, the auto_redirect rule and local routes, and the auto_route rules of the tun inbound at its priorities. The configuration is needed to learn the routing table, the mark and the priorities; if it cannot be read, the defaults are used. While another ours process runs in the same network namespace, the command refuses. It needs CAP_NET_ADMIN. The former name ours auto-nft clean works the same way.

At startup ours run, if it is the only ours process in the namespace, does the same cleanup, but only when its inet ours or inet ours-tun tables are left over: otherwise routing table 100 and the rule priorities (9000…9010, 32768) may belong to the host or to sing-box. The tun inbound removes rules at its own priorities when it starts. Without a supervisor, a killed process leaves the host and the LAN without network until the next start; the systemd unit runs ours clean after every exit.

ours client ​

sh
ours client list -c config.yaml
ours client add wg --name phone [--format wg|awg|qr|sing-box|xray|json] -c config.yaml > phone.conf
ours client remove wg phone -c config.yaml
ours client export wg phone [--format ...]                  # without the private key
ours client export vless-in [alice] [--host vpn.example.com] [--format links|subscription|qr|json]
ours client export --format subscription [--host ...]       # all inbounds with links

Works with files, not with the running process: add and remove write the peer where the endpoint keeps its peers, in its config_file (a [Peer] section at the end of the file) or in peers of this YAML (-c, one file; through a temporary file and rename). A running ours applies the change on SIGHUP (or by itself, with --watch and peers in the YAML). The same done from the dashboard (the "Clients" section) applies immediately.

  • add creates keys (like wg genkey) and a PSK, takes the next free address from each address subnet of the endpoint (/32 and /128) and prints the client's configuration. The client's private key is printed only here and is not stored anywhere. The default format is wg, or awg if the endpoint uses AmneziaWG; wg, sing-box and xray are not available for AmneziaWG and for ciphers without chacha20-poly1305. qr is an SVG of the configuration for the WireGuard/AmneziaVPN app. sing-box is an endpoints element (1.11+), xray an outbounds element. The server's RandomTrailers and DisableCookies go into awg only as a comment: awg setconf does not know such keys.
  • The server address for the client is the endpoint's public_endpoint; auto takes the WAN address and warns if it is private or CGNAT.
  • Links are for users of the vless (TCP, WebSocket, HTTPUpgrade, gRPC, HTTP, XHTTP; TLS and REALITY), hysteria2 and tuic inbounds, in the format read by v2rayN, NekoBox, Hiddify and the link import of Xray/sing-box clients; subscription is the same links line by line in base64. The host is --host, otherwise the certificate name (tls.sni, except for REALITY), otherwise the WAN address.
  • With a config_file that cannot be written, add and remove end with the error not writable … adding and removing clients is disabled.

Exit codes and errors ​

CodeWhen
0The command succeeded; for run, the process stopped cleanly on a signal
1Any error: wrong flags, an error loading or building the configuration, a failed start, a failed subscription download in check --fetch
2ours without a command: help on stderr

An error is printed to stderr as a single FATAL … line. An error in the file gives the line and column, including one found only when a component is built: at the entity or rule it is about:

FATAL config.yaml: 12:7: no outbound `prxy`, did you mean `proxy`?
FATAL config.yaml: 6:3: outbound `proxy`: a `tls` block is required

The line of the file follows the message, with the place underlined:

FATAL config.yaml: 2:3: log.level: unknown level `loud`, expected one of: …
  |
2 |   level: loud
  |   ^^^^^

Build features ​

A configuration that uses something this build leaves out fails with an error naming the feature, for example inbound type `tuic` is not built in (feature `tuic-inbound`). Commands and flags need these features: --dashboard needs api, ours client needs clients, ours tools needs tools, ours rule-set needs rule-set-binary and rule-set-local. How to choose features is in Build your own.

GPL-3.0-or-later