Get Public IP from OCI Instance using OCI CLI

Viewed 1942

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.

2 Answers

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"'

If you are trying to fetch public IP of an instance using OCI CLI, please see this document: oci-public-ip. If you are looking for an ephemeral/reserved public IP, see this document: Managing Public IPs

Related