Search code examples
oracle-cloud-infrastructure

Get Public IP from OCI Instance using OCI CLI


How do I get public IP from an OCI instance with OCI CLI?

There is a command from the docs - oci network public-ip get but this expects parameters like --private-ip-id and -public-ip-id which also cannot be fetched using OCI CLI.


Solution

  • You can use list-vnics

    oci compute instance list-vnics --instance-id <instance-ocid>
    

    to list the interfaces for the instance. The interface details is a list and each entry contains the field "public-ip". You can use the following CLI command with jq to get the public IP address:

    oci compute instance list-vnics --instance-id <instance-id> | jq -r '.data[]."public-ip"'