Join the 85,000 open source advocates who receive our giveaway alerts and article roundups.
How to find your IP address in Linux
How to find your IP address in Linux
Every website has a unique, public IP address that can be reached by anyone and from anywhere.
Internet Protocol (IP) needs no introduction—we all use it daily. Even if you don't use it directly, when you type website-name.com on your web browser, it looks up the IP address of that URL and then loads the website.
Let's divide IP addresses into two categories: private and public. Private IP addresses are the ones your WiFi box (and company intranet) provide. They are in the range of 10.x.x.x, 172.16.x.x-172.31.x.x, and 192.168.x.x, where x=0 to 255. Public IP addresses, as the name suggests, are "public" and you can reach them from anywhere in the world. Every website has a unique IP address that can be reached by anyone and from anywhere; that is considered a public IP address.
Furthermore, there are two types of IP addresses: IPv4 and IPv6.IPv4 addresses have the format x.x.x.x, where x=0 to 255. There are 2^32 (approximately 4 billion) possible IPv4 addresses.
IPv6 addresses have a more complex format using hex numbers. The total number of bits is 128, which means there are 2^128—340 undecillion!—possible IPv6 addresses. IPv6 was introduced to tackle the foreseeable exhaustion of IPv4 addresses in the near future.
As a network engineer, I recommend not sharing your machine’s public IP address with anyone. Your WiFi router has a public IP, which is the WAN (wide-area network) IP address, and it will be the same for any device connected to that WiFi. All the devices connected to the same WiFi have private IP addresses locally identified by the range provided above. For example, my laptop is connected with the IP address 192.168.0.5, and my phone is connected with 192.168.0.8. These are private IP addresses, but both would have the same public IP address.
The following commands will get you the IP address list to find public IP addresses for your machine:
curl ifconfig.mecurl -4/-6 icanhazip.comcurl ipinfo.io/ipcurl api.ipify.orgcurl checkip.dyndns.orgdig +short myip.opendns.com @resolver1.opendns.comhost myip.opendns.com resolver1.opendns.comcurl ident.mecurl bot.whatismyipaddress.comcurl ipecho.net/plain
The following commands will get you the private IP address of your interfaces:
ifconfig -aip addr (ip a)hostname -I | awk '{print $1}'ip route get 1.2.3.4 | awk '{print $7}'(Fedora) Wifi-Settings→ click the setting icon next to the Wifi name that you are connected to → Ipv4 and Ipv6 both can be seennmcli -p device show
Note: Some utilities need to be installed on your system based on the Linux distro you are using. Also, some of the noted commands use a third-party website to get the IP



9 Comments
Excellent
Thanks :)
Hello!
interesting "how to".
I have translated to spanish for my blog:
https://victorhckinthefreeworld.com/2018/05/18/saber-cual-es-tu-direccio...
Thanks for share!
Happy hacking!
That's great! Thanks for translation and sharing, appreciate it :D
BTW I foud a "bug"
In private IP address commands the number 3 has a wrong character:
‘{print $1}’
^ should be ' '
've phun!
Thanks for finding this out, I overlooked the minor editing errors :)
1. ifconfig.me should be corrected to
1. curl ifconfig.me
Thanks Igor, it will be changed :))
Also, please try 'ip -br -c a' :)