title: Ubuntu ssh: Could not resolve hostname myserver: Name or service not known
body: <p>I'm trying login from local machine to aws ubuntu server but I'm unable to login on aws ubuntu server with hostname.</p>
  
  <p>ssh -i key.pem ubuntu@myserver</p>
  
  <p>Getting below error:</p>
  
  <p>ssh: Could not resolve hostname myserver: Name or service not known</p>
  
  <p>I'm able to login with public IP of this server without any issue.</p>
  
  <p>for example:</p>
  
  <p>ssh -i key.pem ubuntu@1.2.3.4</p>
  
  <p>I have changed the hostname with below commands.</p>
  
  <p>1) sudo vim /etc/hosts</p>
  
  <p>2) 127.0.0.1 localhost myserver</p>
  
  <p>3) sudo hostnamectl set-hostname myserver</p>
  
  <p>used the below link to change hostname.</p>
  
  <p><a href="https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname/" rel="nofollow noreferrer">https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname/</a></p>
  
  <p>How can login on aws ubuntu server with hostname instead of IP address?</p>
  
  <p>Please help me.</p>