Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get IP of Heroku dynos

I have a Heroku app making some API calls to an external service. There are some issues and the service wants to know what IPs are making the calls.

A lot of the basic tools like ifconfig, traceroute, netstat, etc don't exist on the machines. Looks like they are running a very barebones version of Ubuntu 14.04.5.

I was able to use heroku ps:exec -a <myapp> to SSH into my app and use ip addr but there are some problems:

1) It appears that this only allows me to SSH into the web.1 dyno (and I am making my API calls through rest.1, rest.2, etc.) 2) These calls go through a router on Heroku's side.

How can I get the IPs of all dyno instances and/or the router?

like image 648
s g Avatar asked Sep 13 '17 00:09

s g


People also ask

How do I find my Heroku Dyno IP address?

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.

How do I check my Heroku dynos?

You can view the amount of free dyno hours remaining by using the CLI. You can do this by running heroku ps on one of your free apps. Alternatively, you can also view this on Dashboard's billing page, which is refreshed daily to display the updated amount.

Does Heroku have dynamic IP?

Because Heroku IPs are dynamic, it can be difficult to integrate Heroku applications with services that allowlist a fixed IP range, including certain APIs and services that operate behind a corporate firewall. Fixie acts as a proxy for outbound traffic, tunneling your requests through a known IP address.

Does Heroku change IP?

QuotaGuard Static IP's routes your Heroku traffic through a pair of static IP addresses that never change.


2 Answers

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.

like image 139
s g Avatar answered Sep 23 '22 04:09

s g


According to the docs, Heroku Dynos can be any IP from an AWS Region. Having a dedicated/static IP for your Dynos is part of their enterprise offering.

However, you can have a dedicated/static IP by adding an add-on (e.g. Fixie, Proximo or one of these add-ons)

Also, you can have the Dynos make a GET request to https://httpbin.org/ip and it will respond with the Dynos public IP (more ideas in the comments section below).

like image 44
mostafazh Avatar answered Sep 22 '22 04:09

mostafazh