> 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/virtual-machine/overview/security-group.md).

# 安全组

安全组充当虚拟防火墙，用于控制虚拟机实例的入站和出站流量，以提高安全性。安全组提供状态包检查（SPI）和包过滤功能。您可以使用安全组及其规则在云中定义安全域。

## **限制**

<table><thead><tr><th width="662">项</th><th>限制</th></tr></thead><tbody><tr><td>最大安全组数量</td><td>2</td></tr><tr><td>单个实例上可部署的最大安全组数量</td><td>2</td></tr><tr><td>单个安全组中的最大规则数量</td><td>40<br></td></tr></tbody></table>

## **实际建议**

* 如果您未创建安全组，系统将为您的实例应用一个默认安全组，该组允许入站连接到 TCP 端口 22（Linux）、TCP 端口 3389（Windows）和 ICMP 协议，以及出站连接到所有流量以进行远程登录。
* 您可以添加规则以允许对特定目的地或源在特定端口上的访问。
* 添加安全组规则时遵循最小授权原则。例如，要允许连接到 Linux 实例的端口 22，我们建议您添加一条规则，仅允许来自特定 IP 地址的访问，而不是允许所有 IP 地址（0.0.0.0/0）的访问。
* 确保每个安全组的规则简单明了。单个实例可以加入多个安全组，单个安全组可以有多个规则。如果大量规则应用于某个实例，管理复杂且可能引入不可预见的风险。
* 将具有不同用途的实例添加到不同的安全组，并分别维护应用于这些实例的安全组规则。例如，您可以将接受互联网访问的实例添加到一个安全组中。然后，在此安全组中，添加规则以仅允许入站访问用于提供外部服务的端口，如端口 80 和 443。同时，为了确保互联网可访问的实例不提供其他服务（如 MySQL 和 Redis），我们建议您在互联网不可访问的实例上部署内部服务，并将这些实例添加到另一个安全组。
* 不要修改生产环境中使用的安全组。对安全组的所有更改都会自动应用于该安全组内的实例。在更改安全组之前，您可以在测试环境中克隆、更改和调试该安全组，以确保更改不会中断相关实例之间的通信。
* 为安全组指定可识别的名称和描述，以便于搜索和管理。


---

# 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/virtual-machine/overview/security-group.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.
