> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/welcome/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/welcome/cn/elastic-compute/load-balancing/edit-listener.md).

# 编辑监听器

监听器创建完成后，您可以在监听器列表页选择 **Actions** > **Edit Listener** 修改其转发规则。

### 协议

监听器将使用该协议接收客户端流量。

请注意，监听器创建后协议不可更改。

#### TCP

适用于需要可靠、面向连接的数据传输场景，例如 Web 服务、数据库、文件传输、电子邮件服务和远程访问。

#### UDP

适用于优先考虑低延迟和实时通信而非可靠性的场景，例如视频会议、在线游戏、DNS 服务和实时数据流。

### 监听端口

监听端口定义了监听器接受客户端请求的端口。有效范围：`1` 至 `65535`。

* 您可以为监听器指定一个或多个端口。
* 每个端口使用所选协议监听传入流量。
* 在这些端口上接收的流量将转发至后端配置中定义的后端服务器端口。

**示例：**

* 监听端口：`443`
* 后端服务器端口：`8443`

{% hint style="info" %} <mark style="color:blue;">**注意**</mark>

<mark style="color:blue;">当转发模式为直接路由时，后端服务器端口必须与监听端口一致。</mark>
{% endhint %}

### 转发模式

转发模式决定流量如何转发至后端服务器。

目前，新创建的监听器仅支持目标 NAT（DNAT）模式。

#### 目标 NAT（DNAT）

负载均衡器将数据包的目标 IP 地址改写为所选后端服务器的 IP，同时保留客户端源 IP 地址。后端服务器可以获取真实客户端 IP。

#### 全量 NAT（FNAT）

负载均衡器在将数据包转发至后端服务器之前，同时改写源 IP 地址和目标 IP 地址。后端服务器将看到负载均衡器的 IP 作为源 IP。

#### 直接路由（DR）

负载均衡器在不修改目标 IP 地址的情况下将流量转发至后端服务器。后端服务器直接向客户端回复。

### 调度算法

调度算法决定流量如何在后端服务器之间分发。

#### Maglev 哈希（mh）

基于一致性哈希的算法，在后端服务器添加或移除时提供均匀的流量分发并最大限度减少重新映射。适用于大规模高并发工作负载。

#### 加权轮询（wrr）

根据分配的权重按顺序将请求分发到后端服务器。权重越高的服务器接收的流量越多。

#### 最少连接（lc）

将新请求路由到当前活跃连接数最少的后端服务器。

#### 加权最少连接（wIc）

根据活跃连接数和服务器权重共同分发流量。权重越高的服务器可处理更多连接。

#### 源地址哈希（sh）

根据客户端源 IP 地址的哈希值分发流量，确保来自同一客户端的请求始终路由到同一台后端服务器。

#### 目标地址哈希（dh）

根据目标 IP 地址的哈希值分发流量。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.console.zenlayer.com/welcome/cn/elastic-compute/load-balancing/edit-listener.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
