4 ms·
> It does strike me as weird that there is seemingly no POSIX-compliant way to get your public Internet address, from my readings. There is no singular thing c
by Jasper_ 5y ago
> It does strike me as weird that there is seemingly no POSIX-compliant way to get your public Internet address, from my readings.
There is no singular thing called a "public Internet address". Imagine you're writing paper letters to someone. You write a letter, you put your own From address, you drop it in the slot. When the mailperson comes to collect the letter, they replace your mailing address with a special other codeword. And when they receive mail, they replace that codeword back with your original address. You would never know it was intercepted unless you asked around. There's no official protocol to ask for your codeword, it's just a trick the mail service does on your behalf.
Your home router does exactly this; it's known as "Network Address Translation", or NAT. It's not an official part of IPv4, and there's no protocol to ask what it is. Your computer thinks its local IP address (typically some variety of 192.168.0.1) is its real, public address, and your router does the swap behind your back.
- tialaramex 5y ago> There is no singular thing called a "public Internet address". There sort of is, it just doesn't help answer the question. Both types of addresses have blocks explicitly carved out which are not unicast addresses to be routed over the public Internet. If you have one of those addresses, such as 192.168.0.1, that definitely isn't your "public Internet address" because people can't route stuff to it.
- andrewmcwatters 5y agoThis is explicitly wrong. There absolutely is such a thing as a "public Internet" address, which is the exact terminology used by the IETF. NAT isn't a part of the Internet Protocol, but it is well-defined in other related RFCs.
- Jasper_ 5y agoYes, I know about what the IETF considers a "public Internet address", but it's sort of ill-defined for a lot of standard network topologies. NAT is a technique, not an explicit protocol. The RFCs simply cover the technique as it existed in practice.
- SilverRed 5y ago`ip a` will tell you your IP addresses. As far as I can tell, for IPv6 it actually does know it's public address since that is globally unique with no need for a public/private split.
- andrewmcwatters 5y agoThe issue is that ifconfig and ip do not recognize the Private-Use Networks under any flag and thusly query DHCP for the public address, nor does DHCP have such a query. (To my knowledge.)
- Symbiote 5y agoWhen the host has a private-use address, there's not necessarily a single public IP (through NAT etc). Packets from my computer will currently appear from two possible public addresses, depending if they've been routed through the work VPN. When the host has a non-private-use address, there might still be NAT, or there might be no Internet access. I have servers in 128...* without Internet access. The "public" address might differ depending on the destination or anything else. "ip ad" shows the address(es) the network interfaces has, nothing more.