简体   繁体   中英

EC2 box ssh using new hostname

I have an ec2 box, it is an ubuntu 18.04 OS. 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. Now I wanted to change the hostname and use it in ssh. I followed some of linux and AWS articles AWS Article and changed /etc/hostname and /etc/hosts file. Can not use route 53 DNS entry as per requirement.

/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.

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. If you don't own a domain you can purchase one through a registrar (such as Route 53 ).

The second option is to look at using Route 53 private hosted zones . By attaching to your VPC you can set DNS records that resolve within your VPC. If you want these records to resolve in a hybrid network you would need to look at adding a DNS resolver .

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. 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

Your local machine knows nothing about changes you've made to the EC2 configuration. Those changes are local to the EC2 instance.

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. Elastic IPs persist even if the instance is rebooted.

Next, create a new A-type DNS record at your DNS provider pointing to the newly issued IP address.

You can now connect to the server with the DNS name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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