

# 管理 VPC 的网络 ACL 关联
<a name="network-acl-associations"></a>

每个子网都与一个网络 ACL 关联。当您首次创建子网时，它会与 VPC 的默认网络 ACL 关联。您可以创建自定义网络 ACL 并将其与一个或多个子网关联，来替换之前的网络 ACL 关联。

**Topics**
+ [描述您的网络 ACL 关联](#describe-network-acl-association)
+ [更改与网络 ACL 关联的子网](#DisassociateNetworkACL)
+ [更改与子网关联的网络 ACL](#ChangeNetworkACL)

## 描述您的网络 ACL 关联
<a name="describe-network-acl-association"></a>

您可以描述与子网关联的网络 ACL，也可以描述与网络 ACL 关联的子网。

**要描述使用控制台与子网关联的网络 ACL**

1. 通过 [https://console.aws.amazon.com/vpc/](https://console.aws.amazon.com/vpc/) 打开 Amazon VPC 控制台。

1. 在导航窗格中，选择 **Subnets**（子网）。

1. 选择子网。

1. 选择**网络 ACL** 选项卡。

**要使用 AWS CLI 描述与子网关联的网络 ACL**  
使用以下 [describe-network-acls](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-network-acls.html) 命令列出与指定子网关联的网络 ACL。

```
aws ec2 describe-network-acls --filters Name=association.subnet-id,Values=subnet-0d2d1b81e0bc9c6d4 --query NetworkAcls[*].NetworkAclId
```

下面是示例输出。

```
[
    "acl-03701d1f82d8c3fd6"
]
```

**要使用控制台描述与网络 ACL 关联的子网**

1. 通过 [https://console.aws.amazon.com/vpc/](https://console.aws.amazon.com/vpc/) 打开 Amazon VPC 控制台。

1. 在导航窗格中，选择 **Network ACLs**（网络 ACL）。

1. 选择网络 ACL。

1. 选择**子网关联**选项卡。

**要使用 AWS CLI 描述与网络 ACL 关联的子网**  
使用以下 [describe-network-acls](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-network-acls.html) 命令列出与指定网络 ACL 关联的子网。

```
aws ec2 describe-network-acls --network-acl-ids acl-060415a18fcc9afde --query NetworkAcls[*].Associations[].SubnetId
```

下面是示例输出。

```
[
    "subnet-0d2d1b81e0bc9c6d4",
    "subnet-0e990c67809773b19",
    "subnet-0eb17d85f5dfd33b1",
    "subnet-0e01d500780bb7468"
]
```

## 更改与网络 ACL 关联的子网
<a name="DisassociateNetworkACL"></a>

您可以从子网取消自定义网络 ACL 的关联。在您将子网与自定义网络 ACL 取消关联后，我们会自动将其与 VPC 的默认网络 ACL 关联。这些更改在短时间内生效。

**要更改与网络 ACL 关联的子网**

1. 通过 [https://console.aws.amazon.com/vpc/](https://console.aws.amazon.com/vpc/) 打开 Amazon VPC 控制台。

1. 在导航窗格中，选择 **Network ACLs**（网络 ACL）。

1. 选择网络 ACL。

1. 选择**操作**和**编辑子网关联**。

1. 从**选定子网**中移除子网。

1. 选择**保存更改**。

## 更改与子网关联的网络 ACL
<a name="ChangeNetworkACL"></a>

您可以更改与某个子网关联的网络 ACL。例如，当您创建一个子网时，该子网会最初与 VPC 的默认网络 ACL 关联。如果创建自定义网络 ACL，则通过将网络 ACL 与一个或多个子网关联来应用网络 ACL 规则。

更改子网的网络 ACL 后，更改将在短时间内生效。

**要更改与子网关联的网络 ACL**

1. 通过 [https://console.aws.amazon.com/vpc/](https://console.aws.amazon.com/vpc/) 打开 Amazon VPC 控制台。

1. 在导航窗格中，选择 **Subnets**（子网）。

1. 选择子网。

1. 选择**操作**和**编辑网络 ACL 关联**。

1. 对于**网络 ACL ID**，选择要与子网关联的网络 ACL，并查看所选网络 ACL 的入站和出站规则。

1. 选择**保存**。

**要使用命令行替换网络 ACL 关联**
+ [replace-network-acl-association](https://docs.aws.amazon.com/cli/latest/reference/ec2/replace-network-acl-association.html) (AWS CLI)
+ [Set-EC2NetworkAclAssociation](https://docs.aws.amazon.com/powershell/latest/reference/items/Set-EC2NetworkAclAssociation.html) (AWS Tools for Windows PowerShell)