Get IP of Heroku dynos
Asked Answered
H

2

16

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?

Hoang answered 13/9, 2017 at 0:13 Comment(2)
How can this be downvoted??? It's as explicit as could possibly be and it follows all of the guidelines here: stackoverflow.com/help/on-topicHoang
I agree, this is a valid question.Certes
H
18

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.

Hoang answered 13/9, 2017 at 2:46 Comment(1)
Using this I'm getting a private IP in the form of 172.17...Cohesive
C
6

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).

Certes answered 13/9, 2017 at 0:30 Comment(3)
They can certainly change over time, but at a given moment they must have an IP.Hoang
They might change at a faster rate than you can manage, but here is a way to expose their public/internet facing IP. Create a RequestBin from requestb.in and have the Dynos make request to it and refresh the page to see all requests made to that unique requestb.in/XXXXXX url .Certes
Or even make a GET request to https://httpbin.org/ip and it will return the Dynos public IP for you.Certes

© 2022 - 2024 — McMap. All rights reserved.