当前位置 博文首页 > yunweigo的博客:阿里云添加动态IP到安全组

    yunweigo的博客:阿里云添加动态IP到安全组

    作者:[db:作者] 时间:2021-07-15 12:38

    下载阿里云的CLI

    https://github.com/aliyun/aliyun-cli/releases
    wget https://github.com/aliyun/aliyun-cli/releases/download/v3.0.73/aliyun-cli-linux-3.0.73-amd64.tgz
    tar zxvf aliyun-cli-linux-3.0.73-amd64.tgz
    sudo cp aliyun /usr/local/bin
    

    配置Aliyun管理界面添加accesskey API调用 添加ECS管理员权限。

    aliyun configure --mode AK --profile akProfile
    Configuring profile 'akProfile' in 'AK' authenticate mode...
    Access Key Id []: xxxxxx     # 填写对应的keyID
    Access Key Secret []: xxxxx  # 填写对应的密钥ID
    Default Region Id []: cn-beijing
    Default Output Format [json]: json (Only support json)
    Default Language [zh|en] en: zh
    Saving profile[akProfile] ...Done.
    Configure Done!!!
    ..............888888888888888888888 ........=8888888888888888888D=..............
    ...........88888888888888888888888 ..........D8888888888888888888888I...........
    .........,8888888888888ZI: ...........................=Z88D8888888888D..........
    .........+88888888 ..........................................88888888D..........
    .........+88888888 .......Welcome to use Alibaba Cloud.......O8888888D..........
    .........+88888888 ............. ************* ..............O8888888D..........
    .........+88888888 .... Command Line Interface(Reloaded) ....O8888888D..........
    .........+88888888...........................................88888888D..........
    ..........D888888888888DO+. ..........................?ND888888888888D..........
    ...........O8888888888888888888888...........D8888888888888888888888=...........
    ............ .:D8888888888888888888.........78888888888888888888O ..............
    

    添加脚本

    new_ip=`curl -L ip.tool.lu | head -1 |awk -F ": " '{print $2}'|sed 's/\r//g'`
    ####
    #  --SecurityGroupId 安全组ID
    #  --Description 描述
    #  --IpProtocol=传输层协议  支持 tcp、udp、icmp、gre、all:支持所有协议
    #  --PortRange=22/22 目的端安全组开放的传输层协议相关的端口范围
    #  --SourceCidIp=源端IPv4 CIDR地址段。支持CIDR格式和IPv4格式的IP地址范围
    #  --Priority 安全组优先级 默认为1
    aliyun ecs AuthorizeSecurityGroup --SecurityGroupId=sg-2zee***** --Description="动态IP添加" --IpProtocol=tcp --PortRange=22/22 --SourceCidrIp=$new_ip
    

    添加计划任务, 根据实际情况调整。

    cs