How to obtain public ip address from 'natted' host? ifconfig?

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?

ifconfig returns:

ens2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.18.12.9  netmask 255.255.255.254  broadcast 10.18.12.9
        inet6 fe80::dc2e:3cff:fe19:1005  prefixlen 64  scopeid 0x20<link>
        inet6 2001:bc8:1820:604::1  prefixlen 64  scopeid 0x0<global>
        ether de:2e:3c:19:10:05  txqueuelen 1000  (Ethernet)
        RX packets 132138967  bytes 312548834675 (312.5 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 48320968  bytes 42333018979 (42.3 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 7135698  bytes 2196946253 (2.1 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7135698  bytes 2196946253 (2.1 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Thank you
Boris

HI @baris35,

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.

1 Like

You may be able to see this by logging into your ubuntu 18.04 cloud server and typing (Ubuntu example, may not work for HPUX):

ubuntu# arp -an

The arp table will often show the public facing IP ADDRESS in the LAN segment directly connected to the NAT'ed router / device.

However, I am not sure what options your HP-UX version of arp supports. You may need to experiment to get the command right:

See also:

And of course, just in case:

2 Likes

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.

Thank you @Neo and @bendingrodriguez
Boris

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.