简体   繁体   English

使用新主机名的 EC2 盒 ssh

[英]EC2 box ssh using new hostname

I have an ec2 box, it is an ubuntu 18.04 OS.我有一个 ec2 盒子,它是一个 ubuntu 18.04 操作系统。 I can using "ssh -i {pemfile} ubuntu@{ip address}" also "ssh -i {pemfile} ubuntu@{ip-ipaddress.us-east-2.compute.internal}" from another EC2 box.我可以从另一个 EC2 盒子使用“ssh -i {pemfile} ubuntu@{ip address}”也可以使用“ssh -i {pemfile} ubuntu@{ip-ipaddress.us-east-2.compute.internal}”。 Now I wanted to change the hostname and use it in ssh.现在我想更改主机名并在 ssh 中使用它。 I followed some of linux and AWS articles AWS Article and changed /etc/hostname and /etc/hosts file.我关注了一些 linux 和 AWS 文章AWS 文章并更改了 /etc/hostname 和 /etc/hosts 文件。 Can not use route 53 DNS entry as per requirement.不能根据要求使用路由 53 DNS 条目。

/etc/hosts = 10.0.1.190 dev-host.example.trade
/etc/hostname = dev-host.example.trade

Getting below error "ssh -i {pemfile} ubuntu@dev-host.example.trade" ssh: Could not resolve hostname dev-host.example.trade: Name or service not known.出现以下错误“ssh -i {pemfile} ubuntu@dev-host.example.trade” ssh:无法解析主机名 dev-host.example.trade:名称或服务未知。

As you've made the changes on the server only these will only be resolvable on that host (otherwise anyone could use any domain).由于您在服务器上进行了更改,因此只有这些更改才能在该主机上解析(否则任何人都可以使用任何域)。

There are a few options you can take if you want to use a custom domain name.如果您想使用自定义域名,您可以选择几个选项。

The obvious one is you can use a domain you control, this will allow it to resolve across any hosts that are able to resolve your public DNS.显而易见的是,您可以使用您控制的域,这将允许它跨任何能够解析您的公共 DNS 的主机进行解析。 If you don't own a domain you can purchase one through a registrar (such as Route 53 ).如果您没有域名,则可以通过注册商(例如Route 53 )购买。

The second option is to look at using Route 53 private hosted zones .第二个选项是考虑使用Route 53 私有托管区域 By attaching to your VPC you can set DNS records that resolve within your VPC.通过附加到您的 VPC,您可以设置在您的 VPC 内解析的 DNS 记录。 If you want these records to resolve in a hybrid network you would need to look at adding a DNS resolver .如果您希望在混合网络中解析这些记录,您需要考虑添加DNS 解析器

The third option is to look at using a resource that can resolve the domain name, to do this you would either join a domain (using a service such as managed active directory or simple directory ), or you could setup an EC2 host to resolve DNS.第三种选择是考虑使用可以解析域名的资源,为此您可以加入域(使用托管活动目录简单目录等服务),或者您可以设置 EC2 主机来解析 DNS . This is an expensive solution and the most complex if you're using a hybrid architecture.如果您使用混合架构,这是一种昂贵的解决方案,也是最复杂的解决方案。

Take a look at the Centralized DNS management of hybrid cloud with Amazon Route 53 and AWS Transit Gateway post for more information about hybrid DNS查看使用 Amazon Route 53 和 AWS Transit Gateway 对混合云进行集中式 DNS 管理的帖子,了解有关混合 DNS 的更多信息

Your local machine knows nothing about changes you've made to the EC2 configuration.您的本地机器对您对 EC2 配置所做的更改一无所知。 Those changes are local to the EC2 instance.这些更改是 EC2 实例的本地更改。

One way to connect to your cloud instance via a DNS name like dev-host.example.trade is to associate an elastic IP to the EC2 instance.通过像dev-host.example.trade这样的 DNS 名称连接到您的云实例的一种方法是将弹性 IP关联到 EC2 实例。 Elastic IPs persist even if the instance is rebooted.即使实例重启,弹性 IP 仍然存在。

Next, create a new A-type DNS record at your DNS provider pointing to the newly issued IP address.接下来,在您的 DNS 提供商处创建一个新的 A 型 DNS 记录,指向新发布的 IP 地址。

You can now connect to the server with the DNS name.您现在可以使用 DNS 名称连接到服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM