Finding Your Public IP Address

November 18, 2022 note-to-self

How to find IP of my router (public IP). There is no way to do it with ifconfig, etc. That will only show local network stuff, and the internal network apparently doesn't know what it's public IP address is. Which both does and doesn't make sense to me. I guess it's like a house not knowing it's address, and not really needing to.

If you have access to a desktop and browser, you can just google it. If you are trying from a command line, read on.

Three ways to find it

If you have nslookup

Complicated but nslookup is probably more common than curl, etc.

> nslookup myip.opendns.com resolver1.opendns.com

If you have curl

> curl ifconfig.me

If you have netcat

> nc ifconfig.me 80
  GET / HTTP/1.1
  Host: ifconfig.me
  (enter x 2)

Result:

HTTP/1.1 200 OK
date: Tue, 17 Dec 2024 14:29:37 GMT
content-type: text/plain
Content-Length: 11
access-control-allow-origin: *
via: 1.1 google

120.3.167.3
# ^^^ That last line is your IP address.
These posts are for my own understanding. Reader beware. Info may be wrong but it reflects my current understanding.