23

I got the same answer everywhere on the internet regarding my question of how to get the IP address of an RDS instance in AWS, but I don't know what dig is, and how to use it.

How to allocate IP address in VPC to RDS instance?

Please help me find the IP address of my RDS instance in AWS?

8 Answers 8

24

It won't display the ip address on the configuration page for the RDS instance because RDS IP's are dynamic in nature. You can dig for them if you need them but you would be better server using the DNS endpoint for the instance. This remains static and can be found on the details tab of the RDS instance within AWS.

2
  • 2
    And the navigation is select instance & show Details->Connect->Endpoint Mar 30, 2018 at 5:20
  • 1
    In my case, I have to deal with some custom DNS (that I don't really understand), and the person who manages that DNS wanted to know the IP of the RDS instance. So yes, my apps use the endpoint, but I still needed to know how to determine the current IP.
    – osullic
    Jan 14, 2020 at 13:10
11

Use this:

SELECT inet_server_addr();
3
  • this is the answer! great. Allowed me to use dblink to move a table between 2 Postgres instances, where using the endpoint name resulted in an error ERROR: could not establish a connection
    – Theo F
    Sep 4, 2020 at 12:41
  • 1
    where to use this?
    – foobar
    Feb 17, 2021 at 10:15
  • it shows me 172.31.46.141 - I think it's 'Internal' IP
    – GML-VS
    Jan 15 at 10:58
10

The IP address of your AWS instance will be the IP address of the RDS instance.

If your hostname of your AWS instance is blah.blah.amazonaws.com then you can use the dig command (on Linux machines) or ping command on both Windows and Linux to find out the IP address of the host:

ping blah.blah.amazonaws.com

This will give you back the IP address of the host (something like this):

c:\ping www.google.com

Pinging www.google.com [216.58.210.100] with 32 bytes of data:
Reply from 216.58.210.100: bytes=32 time=14ms TTL=58
Reply from 216.58.210.100: bytes=32 time=15ms TTL=58
Reply from 216.58.210.100: bytes=32 time=14ms TTL=58

So the IP address of www.google.com is 216.58.210.100. dig will give you more output but the IP address is also in there. But sometimes the actual IP address of your AWS instance is actually in the hostname itself. For example:

ip-12-34-56-78.us-west-2.compute.internal

The IP address 12.34.56.78 is already in the name (depending on your instance). You can find the hostname in the AWS Console/Dashboard.

2
  • @Vivek How can we know the ip address then ? Dec 7, 2016 at 6:49
  • on RDS detail page it should display you IP or hostname.
    – vivex
    Dec 7, 2016 at 9:10
4

On AWS Management Console - Location : AWS Management Console -> EC2 -> Network & Security, Network interfaces

  • You can see all of IP addresses and its resource's details on description tab together.
3
  • The question is about RDS, not a database running in EC-2
    – Steve Gon
    Jun 9, 2022 at 2:52
  • 3
    Yes the question is about RDS. But the RDS instance will use IP address(es) in its configured subnets, and the network interfaces and IP addresses of them are indeed visible in the Network Interfaces screen of the EC2 web console. The tricky part is, if you have more than one RDS instance in the same region and VPC, telling which interfaces and IPs belong to which RDS instance. If you have only one RDS instance in the region and VPC, that makes it easy. Jan 13, 2023 at 15:15
  • Thanks for that answer! In my case DNS resolution didn't work, therefore this was the only solution. Apr 3, 2023 at 17:47
4

Simple method to find RDS ip address: Open command prompt from local machine and ping your RDS Endpoint. You will see the reply from destination host ip address. That is your RDS ip address! Regardless if it is public accessible or not.

2
  • 1
    I would like to add with this approach, once you get ip after doing ping to your DB endpoint, copy that ip and search for that ip at Network Interface to get it's private ip.
    – GeetT
    Jul 27, 2021 at 19:01
  • Is it possible to get the range of IPs? Because Ping will display only 1 IP and it could be changedif we have RDS with DHCP
    – GML-VS
    Jan 15 at 11:00
2

The answer given by Paolo Bolla is good, but only works for Postgresql.

For Microsoft SQL Server, please use:

SELECT 
  local_net_address = ConnectionProperty('local_net_address')
, local_tcp_port = ConnectionProperty('local_tcp_port') 
1

You can also use Nslookup <<RDS SQL Server>> command to figure out the IP address as suggested in this AWS blog post.

1

dig is command-line utility that finds an IP address a domain name leads to.

You can simply install it using :

apt-get update && apt-get install dnsutils -y

Then to find an IP of RDS instance (with endpoint xxx.yyy.us-east-1.rds.amazonaws.com), run the following command :

dig xxx.yyy.us-east-1.rds.amazonaws.com

In the output of dig, you will be able to find IP address in ANSWER SECTION :

;; ANSWER SECTION:
xxx.yyy.us-east-1.rds.amazonaws.com. 5 IN A 172.30.1.253

As you can see RDS instance endpoint, resolved to A type of DNS record with Private IP address

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.