this post was submitted on 21 Jul 2023
37 points (95.1% liked)

Linux

8104 readers
44 users here now

Welcome to c/linux!

Welcome to our thriving Linux community! Whether you're a seasoned Linux enthusiast or just starting your journey, we're excited to have you here. Explore, learn, and collaborate with like-minded individuals who share a passion for open-source software and the endless possibilities it offers. Together, let's dive into the world of Linux and embrace the power of freedom, customization, and innovation. Enjoy your stay and feel free to join the vibrant discussions that await you!

Rules:

  1. Stay on topic: Posts and discussions should be related to Linux, open source software, and related technologies.

  2. Be respectful: Treat fellow community members with respect and courtesy.

  3. Quality over quantity: Share informative and thought-provoking content.

  4. No spam or self-promotion: Avoid excessive self-promotion or spamming.

  5. No NSFW adult content

  6. Follow general lemmy guidelines.

founded 1 year ago
MODERATORS
 

cross-posted from: https://gekinzuku.com/post/98403

While it's easy to get an IP address from popular websites such as whatismyip.com, it's not often friendly to a context where you might need to get your IP address for command line tools.

In order to grab your IP address via the command line, there's a page on a site called ipinfo.io/ip which only contains body content corresponding to your IP address. The easiest way to fetch that data is with the curl command (should be available on both Windows and Linux).

curl ipinfo.io/ip

It may also be beneficial to add this to your .bashrc or .aliasrc on Linux systems with something like

alias myip="curl ipinfo.io/ip"

Now you have an easy way to grab your IP address from the command line!

top 16 comments
sorted by: hot top controversial new old
[–] [email protected] 7 points 1 year ago* (last edited 1 year ago)
curl --silent https://myipv4.p1.opendns.com/get_my_ip | jq --raw-output '.ip'
curl --silent https://eth0.me
curl --silent https://ifconfig.me/ip
curl --silent https://ipecho.net/plain
curl --silent https://ipinfo.io/ip
dig @resolver4.opendns.com myip.opendns.com +short

That last one is generally much faster than the rest.

Also, you can add -w '\n' to curl commands to make it add a newline.

[–] tla 5 points 1 year ago
[–] [email protected] 4 points 1 year ago

I like to be sworn at in json:

curl myip.wtf/json

[–] [email protected] 4 points 1 year ago* (last edited 1 year ago)

curl ifconfig.io works too

[–] [email protected] 3 points 1 year ago (1 children)

You can also use curl "https://eth0.me"

[–] [email protected] 2 points 1 year ago (1 children)

Nice! That's a good short one as well, and I wasn't aware of it before.

[–] [email protected] 2 points 1 year ago

I accidentally found it while I was looking for something completely unrelated and it just stuck in my mind. 😹

[–] [email protected] 3 points 1 year ago (1 children)
% curl ipinfo.io/ip
curl: (7) Failed to connect to ipinfo.io port 80 after 25 ms: Connection refused
% curl https://ipinfo.io/ip
curl: (7) Failed to connect to ipinfo.io port 443 after 29 ms: Connection refused

They suck and apparently block curl (and lynx and elinks) from dynamic IP, it works in Firefox or on a server with static IP.

Another one is ifconfig.me/ip so

curl https://ifconfig.me/ip

that works.

[–] [email protected] 2 points 1 year ago

Oh I had no clue they block curl from a dynamic IP. That's a good alternative to have!

[–] xebix 3 points 1 year ago
[–] [email protected] 2 points 1 year ago

Another one: curlmyip.net

[–] JoeClu 2 points 1 year ago (1 children)

Is 'ifconfig -all' no longer a thing?

[–] [email protected] 2 points 1 year ago (1 children)

If you're connected to the internet via a local network such as a router or modem, ifconfig will give your local IP address, not your public IP address. Instead, the methods in this post and comments all discuss ways to get your public IP address. It usually requires contacting an external server that you trust and asking them "which IP address did I just contact you with?"

[–] JoeClu 2 points 1 year ago

Thank you for being kind in explaining that to me.

[–] GustavoM 1 points 1 year ago

ip -c -br a master race

load more comments
view more: next ›