Hello,
I am running ubuntu 18.04 cloud server
When I run ifconfig in terminal, it does not show public ip.
Is there anything possible to show public ip with just ifconfig command only?
your machine is not directly 'connected to the internet', so no public ip is displayed, but only the local/internal ip 10.18.12.9. The machine is behind at least one router/firewall that does NAT, see e.g. Network address translation - Wikipedia.
To find out which public/external address your home/office/company uses to access the internet, you could use e.g. public services that simply return the ip address whose request they receive, like
$ curl api.ipify.org
Update This only applies to IPv4, IPv6 does not require NAT. So your address 2001:bc8:1820:604::1 is more or less public.
The short answer to this question @baris35 is "No".
You cannot use ifconfig to view the public IP ADDRESS of a "natted" host.
However, you can find this information in the arp table of the natted host on most unix-like operating systems, as I posted above.
Here is an example from a host connected (natted) behind a public router:
macos$ arp -an
? (192.168.2.1) at 0:c0:ca:xx:55:f7 on en0 ifscope [ethernet]
? (192.168.2.150) at 48:e9:f1:xx:76:9b on en0 ifscope [ethernet]
? (192.168.2.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]
? (2XX.0.0.251) at 1:0:5e:xx:0:fb on en0 ifscope permanent [ethernet]
? (2XX.255.255.250) at 1:0:5e:7f:xx:fa on en0 ifscope permanent [ethernet]
You can see that the arp table on the directly connected LAN segment generally provides the public IP address on the gateway router.