Where and Who Am I? OCI Instance Metadata Service

By | December 9, 2018

When you are running your instances on OCI, you sometimes would like to know inside the instance where it really it. Well this is possible by using OCI Metadata service. 

The Metadata service listen on and will report back information about the Instance, like OCID, Displayname, Shape, Region, etc. Including any custom Metadata that was supplied when creating the Instance will also be reported back on.

From the Linux CLI inside your instance, you can for example run:

Shape=$(curl -s
echo "$Shape"

DC=$(curl -s
echo "$DC"

If you are running a webserver (with PHP enabled), here is an example web page that queries the information and displays it.

   <title>OCI - Webserver</title>
 <img src="https://dka575ofm4ao0.cloudfront.net/pages-transactional_logos/retina/41865/Z9Ik6huVSQC0sSJf8To4"><br>
 Welcome to the OCI Webserver!<br>

$json = file_get_contents("");
$obj = json_decode($json);
$displayName = $obj->displayName;
$shape = $obj->shape;
$ad = $obj->availabilityDomain;
$region = $obj->region;
$faultDomain = $obj->faultDomain;
$internal_ip = $_SERVER['SERVER_ADDR'];
$external_ip = exec('curl http://ipecho.net/plain; echo');

print ("<p><b>My info</b><br>");
print ("<table border = 1>");
print ("<tr><td>My Public IP</td><td>$external_ip</td></tr>");
print ("<tr><td>My Private IP</td><td>$internal_ip</td></tr>");
print ("<tr><td>Instance</td><td>$displayName</td></tr>");
print ("<tr><td>Shape</td><td>$shape</td></tr>");
print ("<tr><td>Region</td><td>$region</td></tr>");
print ("<tr><td>Availability Domain</td><td>$ad</td></tr>");
print ("<tr><td>Fault Domain</td><td>$faultDomain</tr></tr>");
print ("</table>");


More information about the Metadata service can be found here:


One thought on “Where and Who Am I? OCI Instance Metadata Service

  1. Pingback: AutoScaling Hands-On (Parte 2) – Post 4 – Vinicius DBA

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.