Xray-docs-next/docs/en/config/inbound.md

162 lines
7.2 KiB
Markdown
Raw Normal View History

# Inbound Proxy
2021-05-26 11:05:53 +00:00
Inbound connections are used to receive incoming data and the available protocols are listed in [inbound protocols](./inbounds/).
2021-05-26 11:05:53 +00:00
## InboundObject
The `InboundObject` corresponds to a subelement of the `inbounds` item in the configuration file.
2021-05-26 11:05:53 +00:00
```json
{
"inbounds": [
{
"listen": "127.0.0.1",
"port": 1080,
"protocol": "protocol_name",
2021-05-26 11:05:53 +00:00
"settings": {},
"streamSettings": {},
"tag": "identifier",
2021-05-26 11:05:53 +00:00
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"allocate": {
"strategy": "always",
"refresh": 5,
"concurrency": 3
}
}
]
}
```
> `listen`: address
The listening address, either an IP address or a Unix domain socket. The default value is `"0.0.0.0"`, which means accepting connections on all network interfaces.
2021-05-26 11:05:53 +00:00
An available system IP address can be specified.
2021-05-26 11:05:53 +00:00
Unix domain socket can also be specified by providing the absolute path in the form of `"/dev/shm/domain.socket"`. The `@` symbol can be added at the beginning to represent [abstract](https://www.man7.org/linux/man-pages/man7/unix.7.html), and `@@` represents padded abstract.
2021-05-26 11:05:53 +00:00
When Unix domain socket is specified, `port` and `allocate` will be ignored. The protocol currently supports VLESS, VMess, and Trojan. The transport methods available are TCP, WebSocket, HTTP/2, and gRPC.
When specifying a Unix domain socket, you can add a comma and an access permission indicator after the socket, such as `"/dev/shm/domain.socket,0666"`, to specify the access permission of the socket. This can be used to solve the socket access permission issue that occurs by default.
2021-05-26 11:05:53 +00:00
> `port`: number | "env:variable" | string
Port. The accepted formats are:
2021-05-26 11:05:53 +00:00
- Integer: the actual port number.
- Environment variable: starts with `"env:"`, followed by the name of an environment variable, such as `"env:PORT"`. Xray will parse this environment variable as a string.
- String: can be a numeric string, such as `"1234"`, or a range of port numbers, such as `"5-10"` which represents ports 5 through 10, a total of 6 ports. You can use commas to separate multiple ranges, such as `11,13,15-17`, which represents ports 11, 13, and 15 through 17, a total of 5 ports.
2021-05-26 11:05:53 +00:00
When only one port is specified, Xray listens for inbound connections on that port. When a range of ports is specified, it depends on the `allocate` setting.
2021-05-26 11:05:53 +00:00
> `protocol`: string
The connection protocol name. The optional protocol types are listed in [inbound protocols](./inbounds/).
2021-05-26 11:05:53 +00:00
> `settings`: InboundConfigurationObject
The specific configuration content depends on the protocol. See `InboundConfigurationObject` in each protocol for details.
2021-05-26 11:05:53 +00:00
> `streamSettings`: [StreamSettingsObject](./transport.md#streamsettingsobject)
The underlying transport method is how the current Xray node interfaces with other nodes.
2021-05-26 11:05:53 +00:00
> `tag`: string
>
> The identifier of this inbound connection, used to locate this connection in other configurations.
2021-05-26 11:05:53 +00:00
::: danger
When it is not empty, its value must be **unique** among all `tag`s.
2021-05-26 11:05:53 +00:00
:::
> `sniffing`: [SniffingObject](#sniffingobject)
Traffic sniffing is mainly used in transparent proxies, for example:
2021-05-26 11:05:53 +00:00
1. If a device wants to access `abc.com` while connected to the internet, it will first query the IP address of `abc.com` via DNS and get `1.2.3.4`. Then the device will initiate a connection to `1.2.3.4`.
2. If sniffing is not set up, Xray will receive a connection request for `1.2.3.4`, which cannot be used for routing based on domain rules.
3. When `enable` in `sniffing` is set to `true`, Xray will sniff the domain name, `abc.com`, from the traffic data when processing the traffic of this connection.
4. Xray will reset `1.2.3.4` to `abc.com`. Routing can then be based on domain rules.
2021-05-26 11:05:53 +00:00
Since the connection is now to `abc.com`, more can be done, such as routing based on domain rules, and even re-resolving the DNS.
2021-05-26 11:05:53 +00:00
When `enable` in `sniffing` is set to `true`, it can also sniff out bittorrent traffic and then configure the "protocol" item in routing rules to handle bittorrent traffic, such as intercepting bittorrent traffic on the server or forwarding bittorrent traffic to a VPS on the client side.
2021-05-26 11:05:53 +00:00
> `allocate`: [AllocateObject](#allocateobject)
Specifies the specific settings for port allocation when multiple ports are set up.
2021-05-26 11:05:53 +00:00
### SniffingObject
```json
{
"enabled": true,
"destOverride": ["http", "tls", "quic", "fakedns", "fakedns+others"],
"metadataOnly": false,
"domainsExcluded": [],
"routeOnly": false
2021-05-26 11:05:53 +00:00
}
```
> `enabled`: true | false
Whether to enable traffic sniffing.
2021-05-26 11:05:53 +00:00
> `destOverride`: ["http" | "tls" | "quic" | "fakedns" | "fakedns+others" ]
2021-05-26 11:05:53 +00:00
When the traffic is of a specified type, reset the destination of the current connection to the target address included in the list.
2021-05-26 11:05:53 +00:00
`["fakedns+others"]` is equivalent to `["http", "tls", "quic", "fakedns"]`, and when the IP address is in the FakeIP range but no domain records are hit, `http`, `tls`, and `quic` will be used for matching. This option is only effective when `metadataOnly` is set to `false`.
2021-05-26 11:05:53 +00:00
> `metadataOnly`: true | false
When enabled, only use the connection's metadata to sniff the target address. In this case, sniffer other than `fakedns` (including `fakedns+others`) cannot be activated.
If metadata-only is disabled, the client must send data before the proxy server actually establishes the connection. This behavior is incompatible with protocols that require the server to initiate the first message, such as the SMTP protocol.
> `domainsExcluded`: [string] <Badge text="WIP" type="warning"/>
A list of domain names. If the traffic sniffing result matches a domain name in this list, the target address will **not** be reset.
::: warning
Currently, `domainsExcluded` does not support domain name matching in the routing sense. This option may change in the future and cross-version compatibility is not guaranteed.
:::
> `routeOnly`: true | false
Use the sniffed domain name for routing only, and keep the target address as the IP address. The default value is `false`.
This option requires `destOverride` to be enabled.
::: tip
When it is possible to ensure that **the proxied connection can obtain correct DNS resolution**, by using `routeOnly` and enabling `destOverride`, and setting the routing matching strategy `domainStrategy` to `AsIs`, it is possible to achieve domain and IP separation without DNS resolution throughout the process. The IP used when encountering an IP rule match is the original IP of the domain.
:::
2021-05-26 11:05:53 +00:00
### AllocateObject
```json
{
"strategy": "always",
"refresh": 5,
"concurrency": 3
}
```
> `strategy`: "always" | "random"
The port allocation strategy.
2021-05-26 11:05:53 +00:00
- `"always"` means all specified ports in `port` will be allocated, and Xray will listen on these ports.
- `"random"` means ports will be randomly selected from the `port` range every `refresh` minutes, and `concurrency` ports will be listened on.
2021-05-26 11:05:53 +00:00
> `refresh`: number
The interval for refreshing randomly allocated ports in minutes. The minimum value is `2`, and it is recommended to set to `5`. This property is only effective when `strategy` is set to `"random"`.
2021-05-26 11:05:53 +00:00
> `concurrency`: number
The number of randomly allocated ports. The minimum value is `1`, and the maximum value is one-third of the `port` range. It is recommended to set to `3`.