0

In linux , /etc/hosts stores ip aliases.

But I want to create a hostname without knowing its IP address. In Amazon RDS , it's endpoint is a long domain name such as : my-db.ooxxooxxooxxoo.ap-northeast-1.rds.amazonaws.com . It doesn't suggest connecting by IP (because it may change).

In such situation , how do I resolve a simple db string to this domain name ? WITHOUT any outer help , such as DNS CNAME or Route53 solution.

2

setup a local nameserver (eg dnsmasq) and insert the CNAME records you need into that.

dnsmasq.conf:

cname=alias,horrible-long-hostname.example.com

resolv.conf:

nameserver 127.0.0.1
  • CNAME stands for canonical name, aka an alternate name. So you could configure my-db.mydomain.com as a CNAME for my-db.ooxxooxxooxxoo.ap-northeast-1.rds.amazonaws.com, and no matter what IP address Amazon sets db.ooxxooxxooxxoo.ap-northeast-1.rds.amazonaws.com to, your CNAME alias will resolve to the same IP address. – simpleuser Sep 11 '17 at 19:24
  • Note that this only works for targets which are names from DHCP or /etc/hosts. – dustin.schultz Sep 4 '18 at 14:33
1

If all you are trying to do is simplify ssh'ing to that system, you can use an ssh config file. Create and edit ~/.ssh/config to contain:

Host db: Hostname my-db.ooxxooxxooxxoo.ap-northeast-1.rds.amazonaws.com

After that, a simple "ssh db" will lookup what's specified in your .ssh/config file and connect you.

  • This solutiuon also covers rsync and scp. – user313114 Jan 29 '15 at 5:17
  • no , I am not trying to do ssh. I want resolve to IP (used in JDBC connecting) – smallufo Jan 29 '15 at 5:33
  • You may be able to add: search ooxxooxxooxxoo.ap-northeast-1.rds.amazonaws.com to /etc/resolv.conf and then connect to my-db... – Liczyrzepa Jan 29 '15 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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