在新启动的Amazon EC2实例的/ etc / hosts文件中自动添加条目 [英] Automatically add an entry in /etc/hosts file in newly launched amazon ec2 instance

查看:186
本文介绍了在新启动的Amazon EC2实例的/ etc / hosts文件中自动添加条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所做的事情:

$ vi /etc/hosts




  • 添加的IP地址主机名

  • 我想自动化此过程,就像我启动的每个新实例都应该在/ etc / hosts中都有一个条目

    I want to automate this process like every new instance I launch should have an entry in /etc/hosts

    推荐答案

    猜猜您需要添加

    在创建新的ec2实例时,将其放入用户数据

    Put this in user data when you create a new ec2 instance

    #!/usr/bin/env bash
    
    echo `ec2-metadata -o|cut -d: -f2` " " `ec2-metadata -h |cut -d: -f2` >> /etc/hosts
    

    这篇关于在新启动的Amazon EC2实例的/ etc / hosts文件中自动添加条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆