Get Ip of Heroku Dynos

Get IP of Heroku dynos

Get the list of dynos with the heroku ps -a <app> command.

You actually can ssh into individual dyno instances with heroku ps:exec -a <app> -d <dyno_instance> --ssh.

Get the individual dyno IP with the ip command e.g. ip addr | grep "global eth0" | awk '{ print $2 }'.

Get the router IP with curl 'https://api.ipify.org'. http://httpbin.org/ip is also good.

You could use expect to programmatically retrieve the IPs from every dyno by running the Heroku SSH command, waiting for the prompt, running the IP command(s), logging out, then repeating for each dyno instance.

Force changing the ip of the Heroku dyno

It turns out by restarting the app (deleting the dynos), the IP is changed, by default.

You can do this by using the Heroku API.

For a given Heroku Dyno *instance*, is the external IP address stable for the lifetime of that instance?

On a broad level, you should never expect IP addresses to be stable on Heroku by default. This applies to DNS targets, hence the requirements for CNAMEs everywhere, and outbound IPs.

Regarding the specific question, yes, a single specific Dyno instance will have the same outbound IP address, but that means it will only be stable for ~24 hours (+3 1/2 hours possibly, see /Dynos#restarting) at most. After web.1's daily cycle, the newly launched web.1 will have a new public IP address. web.1, web.2, web.3, web.#…, along with any/all other process groups' Dynos will likely never have the same public IP address at the same time.

There are means for stabilizing outbound IPs longer term, as is accomplished by various Proxy partner add-ons, or any other Proxy service you choose to use.

Get a finite list of IP addresses for my Heroku App?

No, Heroku will not give you even a range of IP addresses - they can, may and will move dynos between Amazon zones as needs require.

Your only option would be some sort of proxy node with a static IP that they talk to that securely communicates to your Heroku app - or consider if Heroku is the right fit for you here altogether.

Does Heroku change dyno IP during runtime?

Heroku Dynos are ephemeral application instances. They may come up/down at any time and be replaced by a new one, or have your application restarted.

So, Dynos may often change which will result in new IPs for your app servers. However, the IP is very unlikely to change while the dyno is up and running. Only to be replaced by a new dyno with a different IP.

How to get the IP address of the request to a Heroku app?

Checking Flask's documentation on filtering headers etc., I found that:

request.headers['X-Forwarded-For']

is where you'll get the client's real IP address.


From a deleted comment by OP, this article provides a safer solution.



Related Topics



Leave a reply



Submit