32

I am using an Amazon EC2 instance to serve a node.js app. I recently purchased a domain name through Google Domains and I want to use that domain name to access my node.js app.

The Google Domains console allows you to forward your domain traffic to another website. I set it to forward traffic to the public IP address of my EC2 instance. I can access my app just fine now, but when I type www.myDomainName.com into a web browser, the URL bar immediately changes and displays the digits of my EC2 IP address.

I would like the URL bar to display the name of my domain instead.

Note:
I have read a few SO questions related to this and can't figure it out. Some of them are a bit over my head. Many of them say to use an Amazon Elastic IP, but I don't understand why this is necessary if the public IP of my EC2 instance seems to work just fine. If the solution here is to use Amazon Elastic IP, I would really appreciate an explanation as to why that is necessary,

3 Answers 3

51

It sounds like you are using Google Domains to redirect to another site once the request has hit the Google servers. This is fine and dandy if you have another domain you are wanting to redirect to.

If you want it to stay under your domain name, but point to another location you need to actually change the DNS entries for your domain.

Go to Google Domain services and change your master(*) (A) record, as well as your WWW (A) record, to point at your public IP address. That way when a DNS request is sent for your domain it will just ask Amazons' servers what to do instead of using a redirect from Google.

Exact Steps:

  1. From the Google Domain Website, click the Middle Tab (enter image description here) to open DNS settings
  2. Fill out the form near the bottom of the page titled, Custom Resource Record
    • Name: In this scenario we want to use "@" or "www"
      • @ is the root record (or anything not specifically set)[all]
      • www is the record for when people type www.example.com
    • Type: There are two types; A refers to IPv4 address and AAAA refers to IPv6 address
      • You can set both of them separately, generally you want to use the A [IPv4]
    • TTL: Time to live, recommend leaving 1hr (this is an advanced attribute)
    • Data: The actual IP address you are wanting to point to (your website)
      • Example: 8.8.8.8 [Google Nameserver]
  3. Now that are the blanks are filled out, press the "Add" button
  4. Wait for the records to be updated publicly
    • This will take approx. 1hr (as long as you kept TTL at 1hr)
      • This step can take longer depends on Google's servers
    • Check your website www.example.com to confirm it has updated
7
  • I am trying to do this and just now purchased a domain. Could you spell the steps out for me? Commented Apr 14, 2016 at 16:42
  • The steps are spelled out in the last paragraph. Login to your Google Domains account and change the two A records (WWW and *) to point to the IP address of Amazon's Name-servers. Amazon's Service will handle the rest.
    – ZaxLofful
    Commented Jul 27, 2016 at 20:53
  • I did this and I get server IP address could not be found. I am using google's default domains name servers and configured the @ and www. Does not work for me :( Commented Aug 2, 2018 at 5:24
  • @JuanZamora: Make sure you are using the right IP address. These steps are part of the DNS standard and aren't going to change anytime soon. When a DNS request is forwarded the new server responds instead.
    – ZaxLofful
    Commented Aug 5, 2018 at 16:59
  • hey @ZaxLofful, so I was able to get it done: so this is what I did. I used the ElasticIP in my google custom resource records and configured the following entries: [@ A 1h 57.65.44.43] and [www CNAME 1h www.mywebsite.com.] the IP here is made up ;) Commented Aug 5, 2018 at 17:05
15

Addendum to Zax's Answer

While Zax's answer is fully accurate, it looks like it wasn't sufficient to help out the OP, and maybe not for others, too.

  1. When you go to Google Domains (at least as of March 2017), you'll see several different tabs. The middle tab, which looks like enter image description here is the tab to configure the DNS. Chose that tab.
  2. Near the bottom of the page on the DNS tab you'll see a section Custom resource records. Within that section, you can add more entries. An entry consists of:
    • Name: this is briefly described by Google, but in short, likely you'll either want to use @ or www, where the former means "root level" and the latter means "www subdomain".
      • For instance, if you registered imsocool.com, then @ points to imsocool.com whereas www points to www.imsocool.com.
    • Type: you'll probably either want A which is an IPv4 Address or you'll want AAAA, which is an IPv6 Address. (That's assuming you're trying to point to a website, not an e-mail server or whatever else.)
    • TTL: time-to-live, I don't think you'll need to worry about it much, so just use the 1h (one hour) default.
    • data: again, presuming you are pointing to a website, that will be the actual IP address. E.g., 54.49.66.128, or whatever your IPv4 (or v6) server address is.
  3. Once you've filled in all the blanks, simply hit the blue "Add" button.
  4. Wait a while for the DNS update to happen.
    • The most it should take is 1 hour, if that's what you had placed above. But it could potentially be much quicker.
    • Then check to see that all is working by visiting your site using the name, e.g., imsocool.com.
6
  • After doing this I lose the email forwarding which I setup in google domain registrar to forward emails to contact@imsocoolcom to [email protected] and I'm not clear where to add the MX record. I'm using Amazon lightsail wordpress instance and was able to setup the A record to load imsocool.com & www.imsocool.com but mails to [email protected] are not giving mail delivery failure. Can you please write about setting mail or keeping the email forwarding intact? Thanks.
    – Mr.Hunt
    Commented Sep 21, 2017 at 8:44
  • Sorry, @Mr.Hunt I did not need to work with e-mail. I could look through the docs and take a guess, but I don't have any first-hand experience. Commented Sep 21, 2017 at 19:14
  • 1
    It's ok, I solved the issue by setting up custom A records in google domain registrar. Now I'm using google domains nameserver & also retain the email forwarding.
    – Mr.Hunt
    Commented Oct 10, 2017 at 8:52
  • @MikeWilliamson when I follow thest directions, using my ec2's ipv4 address, I receive the message 'Record already in use'. Do you know what I'm doing wrong? Commented Nov 7, 2018 at 23:32
  • @yalpsideman Sorry, I don't know off hand. This is one of those things that I learn, then promptly forget because I won't need it again for a while. That being said, it sounds like you are trying to use a DNS name that you've probably already used before. I say that because I don't see how the data could be an IP address that you've already used. Sorry I cannot be more help. Commented Nov 9, 2018 at 0:27
3

In your google domain admin dashboard, select the dns configuration of your domain name.

Go to Custom resource records and set a new record with the subdomain you require: for the site webapp.example.com use webapp and select Type A. Leave blank the ttl field and add you public IP from the amazon EC2 instance. Then just browse the site webapp.example.com and it will retrieve the site on your EC2 under the domain name.

If you need to redirect the www.example.com domain then just add a record with www, also selecting the type A and adding your public IP from your EC2 instance.

1
  • 1
    Elastic IP should be used instead of public IP of EC2 instance, because public IP will change after instance restart, and Elastic IP won't. Commented Sep 12, 2020 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.