1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Determine ipv4 And ipv6 Public IP Addresses as a Unix TIL

This commit is contained in:
jbranchaud
2025-11-21 16:43:08 -06:00
parent 53a0b88eff
commit bae3527baf
2 changed files with 31 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1697 TILs and counting..._
_1698 TILs and counting..._
See some of the other learning resources I work on:
@@ -1617,6 +1617,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Curl With Cookies](unix/curl-with-cookies.md)
- [Curling For Headers](unix/curling-for-headers.md)
- [Curling With Basic Auth Credentials](unix/curling-with-basic-auth-credentials.md)
- [Determine ipv4 And ipv6 Public IP Addresses](unix/determine-ipv4-and-ipv6-public-ip-addresses.md)
- [Different Ways To Generate A v4 UUID](unix/different-ways-to-generate-a-v4-uuid.md)
- [Display All The Terminal Colors](unix/display-all-the-terminal-colors.md)
- [Display Free Disk Space](unix/display-free-disk-space.md)

View File

@@ -0,0 +1,29 @@
# Determine ipv4 And ipv6 Public IP Addresses
There are a number of ways to do this. The one that I've settled on is sending a
`curl` request to a public URL that was specifically set up to echo back the
public IP of the device making the request. There are many such URLs, but the
one that I tend to use is `ifconfig.io`.
When I run this as is, I get something like the following which you may
recognize as an _ipv6_ IP address.
```bash
$ curl ifconfig.io
2001:db8:3333:4444:5555:6666:7777:8888
```
This is because if ipv6 is available, like it is for me, `curl` is going to
prefer that.
Now, if I'm trying to track down specifically my ipv4 address, I can use the
`-4` flag (or `--ipv4`).
```bash
$ curl -4 ifconfig.io
73.23.45.157
```
Similarly, I could explicitly specify ipv6 with `-6` or `--ipv6`.
See `man curl` for more details.