云命令Cloud Shell中预装了一个复制ECS安全组的脚本。您可以通过运行该脚本快速创建一个新的安全组。
背景信息
安全组是一种虚拟防火墙,具备状态检测和数据包过滤功能,用于在云端划分安全域。您可以通过配置安全组规则,允许或禁止安全组内的ECS实例对公网或私网的访问。
操作步骤
- 在浏览器中输入https://shell.aliyun.com进入Cloud Shell页面。
- 执行以下命令,复制脚本。
git clone https://code.aliyun.com/labs/tutorial-ecs-copy-security-group.git - 执行以下命令进入tutorial-ecs-copy-security-group目录。
cd tutorial-ecs-copy-security-group - 执行以下命令复制安全组。
sh CloneSecurityGroup.sh - 根据提示完成以下操作,创建一个和源安全组规相同的安全组:
- 输入源安全组的所属地域,例如cn-hangzhou。您可以直接按Enter键查看地域信息。
- 输入源安全组的ID。
您可以直接按Enter键查看指定地域下所有的安全组。
1. Please enter RegionID where the source SecurityGroup is located, or press "Enter" for more Region information. Please type RegionID to continue: cn-hangzhou 2. Please enter source SecurityGroupId or press "Enter" to get SecurityGroupId. Please type SecurityGroupId to continue: SecurityGroupId | SecurityGroupName | Description ---------------- | ---------------- | ----------- sg-bp1a3uv8ri*** | *** | *** sg-bp1190o50*** | secu*** | *** sg-bp11j9xpp*** | secu*** | *** sg-bp168k8dw*** | sg-b*** | System created security group. sg-bp16tmhcb*** | sg-b*** | System created security group. sg-bp17cfy7s*** | sg-b*** | System created security group. sg-bp13pwxi9*** | VPC1 | *** sg-bp1lum4k0*** | wugo*** | *** sg-bp1ddqy41*** | wugo*** | *** sg-bp1hbr8zp*** | xian | test Please type SecurityGroupId to continue: sg-bp1a3uv8rrypq3e9bsfh - 输入目标新创建的安全组的所属地域,例如cn-shanghai。您可以直接按Enter键查看地域信息。
- 输入目标新创建的安全组的所属VPC ID。您可以直接按Enter键查看目标地域下的VPC信息。
3. Please type the target RegionID or press "Enter" to clone SecurityGroup in the same region. Please type RegionID to continue: cn-shanghai 4. Please type the target VpcId or press "Enter" to get VpcId. Please type VpcId to continue: VpcId | VpcName | Description ------ | ------- | ----------- vpc-uf614ufd xxx | doctest-1 | vpc-uf6mb30e xxx | miniapp_vpc_test | vpc-uf604yqd xxx | miniapp_vpc_prod | vpc-uf6o8d1d xxx | xxx | vpc-uf6p2u19 xxx | xxx | vpc-uf6qpogy xxx | | vpc-uf62xei9 xxx | CL-xxx | vpc-uf6nr5ji xxx | cl-HaVip | vpc-uf6oxj71 xxx | | vpc-uf66v509 xxx | drntest | Please type VpcId to continue: vpc-uf614ufdj13n8 - 输入要创建的安全组名称和描述。您可以按Enter键略过名称和描述,直接创建安全组。
5. Please type the target SecurityGroupName or press "Enter" to skip. Please type SecurityGroupName to continue: ingressTraffic 6. Please type the target Description or press "Enter" to skip. Please type Description to continue: copyfromsg-bp1a3uv8rrypq3e9bsfh Cloning the specified security group, please wait a moment - Congratulations! You successfully cloned a SecurityGroup: sg-uf61a39n0ss2xt3eczxo
执行结果
安全组创建成功后,系统会返回安全组ID。您可以执行以下命令查看创建的安全组规则详情。aliyun ecs DescribeSecurityGroupAttribute --RegionId cn-shanghai --SecurityGroupId sg-adf13******
其中:
- RegionId是已创建的安全组的所属地域。
- SecurityGroupId是已创建的安全组ID。
该文章对您有帮助吗?