1

Command for determining my public IP?

According to "Michael K" who answered the question my computer won't know the public Ipv4 address but it somehow knows the public ipv6 address. Why is that so? executing the command ìp a shows my public ipv6 address.

3 Answers3

3

The following commands will get you the public IP addresses for your machine:

curl ifconfig.me

curl ifconfig.me/ip

curl ifconfig.me/all

akshahi17
  • 84
  • 1
  • 6
1

I will try to describe this the best I can.

It really all depends on what supplies IPs to your host. For most home users they use a router that has a built-in DHCP server thus allowing more than one system online through using 1 IP address. You can setup a computer as a router too. If you have only 1 computer you could bypass the router all together and hook up your system directly to your broadband modem. IPv4 vs IPv6 are two completely different ways of doing IP addresses.

A decent read https://www.thousandeyes.com/learning/techtorials/ipv4-vs-ipv6

IPv4 is a 32-bit way of addressing and is limited as to how many unique IP addresses there are total (just over 4 billion). Where IPv6 is 128-bit allowing 340000....0000 (37 zeros after the 34, it's a big number) where you can have your own unique IPv6 public IP for every single device in your house connected to your router, even your router would have its own public IP.

So, to keep allowing for IPv4 addressing, they have created it so that a public IP on IPv4 to a single location uses 1 IP, then NAT takes over with the DHCP allowing you to create more IPs behind the public IPv4 allowing you to have more and more systems using the same public IP.

Terrance
  • 41,612
  • 7
  • 124
  • 183
  • Thank you for your detailed explanation and the "decent read" recommendation. I understand it now much better! Greetings. – Ethan Brown Mar 25 '21 at 23:17
1

IPv4 has a limited number of available addresses. So folks use a blinky-box-router so their entire network shares a single one of those limited public IPv4 addresses.

Honestly, that's a hack. However, it's a hack that we are all familiar with and take rather for granted.

When connecting using IPv4, that router is in the way.

IPv6 has a much greater number of available addresses, so every item on your local network has it's own public IP addresses...which is (oversimplifying) the same as it's LAN IP address. There's no longer an important difference, and there's no need for that hack anymore. The same blinky-box functions as a mere switch instead of a router.

When connecting using IPv6, that router is not in the way anymore.

user535733
  • 62,253
  • It should be noted that IPv6 is slightly more complicated than just that. First, you always have link-local IPv6 address, which is valid only inside the subnet. In addition to that, you may have a global address, which usually is also your public address, as you wrote. Both these addresses live simultaneously on your network interface, unlike private and public address in IPv4 network with NAT router, where inside LAN you have only a private address, and the public address is de facto the address of the router, not of any computer inside LAN. – raj Mar 25 '21 at 19:06
  • @raj, indeed -- it's oversimplified for a simple question. Minor edit to highlight the oversimplification. – user535733 Mar 25 '21 at 19:08
  • Thx everyone for your help. I understand it better now! – Ethan Brown Mar 25 '21 at 23:19