4

Need to find the IP address of the host machine[virtual machine] hosting the Cloud Foundry application after it is deployed.

Is there anyway to find the IP address? please let me know.

The IP address is needed to debug a connection time out problem for a database connection from application hosted on IBM Bluemix platform to Compose database.

DeejUK
  • 12,891
  • 19
  • 89
  • 169
Mustansir Ali
  • 305
  • 1
  • 2
  • 9

2 Answers2

16

The IP address can be found using the Cloud Foundry CLI command given below.

CF_TRACE=true cf app <APP_NAME>

The application details that you get will have information as given below :-

{"0":{"state":"RUNNING","stats":{"name":"xxxxxx","uris":["xxxxx.ng.bluemix.net"],"host":"198.23.123.244","port":62461,"xxxxx":484527,"mem_quota":1073741824,"disk_quota":1073741824,"fds_quota":16384,"usage":{"time":"2016-10-27 06:09:24 +0000","cpu":0.34868865754162753,"mem":951832576,"disk":255479808}}}}

The "host" value is the IP which hosts customer's app.

BUT PLEASE NOTE THAT THE IP WILL BE CHANGED IF YOU RESTAGE THE APPLICATION OR APP INSTANCES ARE MOVED TO OTHER HOSTS

For example :

CF_TRACE=true cf app mustanshop

The command results contains following text

{"0":{"state":"RUNNING","stats":{"name":"mustanshop","uris":["mustanshop.mybluemix.net","erterte.testmmmm.com"],"host":"23.246.199.124","port":64220,"uptime":123233,"mem_quota":268435456,"disk_quota":1073741824,"fds_quota":16384,"usage":{"time":"2016-10-27 11:43:41 +0000","cpu":0.002698186246587801,"mem":183988224,"disk":210558976}}}}

Host IP for application mustanshop.mybluemix.net = 23.246.199.124

ALSO NOTE THAT THIS IP IS INTERNAL IP ASSIGNED TO THE VM HOSTING THE APP AND IS NOT ACCESSIBLE FROM OUTSIDE. SO THIS IP CANNOT BE USED TO REACH THE APPLICATION OR USED FOR ANY TYPE OF ROUTING CONFIGURATION TO THE APPLICATION.

Mustansir Ali
  • 305
  • 1
  • 2
  • 9
  • 2
    Works in shell only, for Windows 10 - **[Git BASH](https://gitforwindows.org/) worked**. How every the IP Address listed for the CF Application is _local to the network not the global one_. – Abhijeet Mar 12 '18 at 06:09
  • The URI array has mybluemix.net, which is the IBM Cloud domain. Instead of using CF_TRACE=true, use IBMCLOUD_TRACE=true. Upgrade to the latest CLI before using (the old command was BLUEMIX_TRACE). – Van Staub Nov 27 '18 at 21:26
0

A scripted approach can use CF API routes:

/v2/apps?q=name:

/v2/apps/:guid/stats

Get the metadata from the first route. Then get the host property from the second route, which is the IP address.

export APP_NAME=<your-app-name>
export APP_URL=$(cf curl /v2/apps?q=name:$APP_NAME | grep \"url\" | awk '{ print $2 }' | cut -c2-46)
export APP_HOST=$(cf curl $APP_URL/stats | grep host | awk '{ print $2}' | cut -c 2-)
echo ${APP_HOST/%??/}
Van Staub
  • 81
  • 3