How to find your IP address in Linux | Opensource.com
We all use the Internet Protocol (IP) daily, whether we’re aware of it or not. For instance, any time you type a website name or a search term into your web browser, it looks up the IP address of that URL (or of a search engine) 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, 172. 16. x-172. 31. x, and 192. 168. 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. 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. 0. 5, and my phone is connected with 192. 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
curl -4/-6
dig +short
host
The following commands will get you the private IP address of your interfaces:
ifconfig -a
ip 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 seen
nmcli -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
Finding your IP address in the GNOME desktop
If you’re using Linux, you can find your IP address using some basic desktop utilities. First, go to your Activities screen and type Network (for a wired connection) or Wi-Fi (for wireless).
In the Networks settings window, click the Gear icon next to the network you’re on.
Your IP address is listed in the Network profile.
In this example screenshot, my IPv4 address is 10. 1. 2 and the gateway is 10. 1.
Public and private IP addresses
To understand the significance of public and private IP addresses, let’s have a look at a concept called NAT (Network Address Translation) and PAT (Port Address Translation).
Private addresses are used in Local Area Networks (LAN). They are bound to a specific network.
Public addresses are necessary for establishing external connectivity to other networks, most notably the “Worldwide Web” (www) of the Internet.
NAT is a translation of a private IP to a public one, and consists of three major types: static, dynamic, and PAT. In static NAT, one private IP is mapped to one public IP. A common example ru ydco is a firewall. In dynamic NAT, a private IP address is mapped to a public IP but from a pool of public IP addresses.
With a total of 2^32 IPv4 addresses, out of which approximately just 3. 7 billion are public addresses, there are literally more people and devices than there are IP addresses. And yet we haven’t run out of addresses. That’s because of a concept called PAT, which allows for a single public IP address to be translated from multiple (generally all) private IP addresses using port numbers. Here, instead of assigning a public address to each device, a single public address is allocated to the external side, and private addresses are assigned to each device within the internal network. PAT is most widely used in residential wireless routers, which we use to connect to the Internet.
Private Ipv4 addresses
Local addresses are only used within an internal network.
The range is 10. x, (x is a number from 0 to 255).
Used in Local Area Networks (LAN).
Not globally reachable, and cannot be searched globally.
Not unique: the same private IP can be used in two different networks.
Each router comes with a private IP address, which multiple devices can connect to. Users don’t need to pay extra to obtain a private address.
Some example private IP addresses: 10. 4, 172. 4. 5, 192. 9. 8
Public Ipv4 addresses
Public addresses are used to connect to external networks.
Ranges from 0. 0 to 255. 255. 255, except for private IP addresses and few unusable or reserved IPs.
Used in connecting to the Internet.
Globally reachable and can be searched. These are often used to determine geolocation.
Unique across all of the Internet.
A private address costs money because they are unique, limited, and accessible from the Internet. Each website has a domain name mapped to a public IP. For example, the public IP address for is 54. 204. 39. 132
Finding your way with IP
An IP address is the most direct route to a computer over a network. There are other systems, such as DNS and Avahi, to help route one computer to another, but when those are unavailable or undesired for any reason, the IP protocol is what you use. Now you understand why, and more importantly, how to find your own.
Editor’s note: This article was originally published in May 2018 and has been updated.
How to use curl to get public IP address – LinuxConfig.org
The curl command on Linux systems is commonly used to download and upload files to or from a remote server. Another interesting thing we can use it for is to determine the public IP address of our system.
To do this, we can use curl to query websites that are configured to do nothing more than return the IP address of whichever system is connecting to it. This is one of the quickest and easiest ways to get your public IP address on the Linux command line. Follow along with us below and we’ll show you a few examples.
In this tutorial you will learn:
How to install curl on major Linux distros
How to use curl to get public IP address
Using curl to get public IP address on the Linux command line
Software Requirements and Linux Command Line Conventions
Category
Requirements, Conventions or Software Version Used
System
Any Linux distro
Software
curl
Other
Privileged access to your Linux system as root or via the sudo command.
Conventions
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user
Install curl
Although curl is a common utility, it’s not included on every single Linux distro. Specifically, it may be missing from more desktop oriented distros. Just in case it’s not already installed, you can use the appropriate command below to install it through your system’s package manager.
To install curl on Ubuntu, Debian, and Linux Mint:
$ sudo apt install curl
To install curl on CentOS, Fedora, AlmaLinux, and Red Hat:
$ sudo dnf install curl
To install curl on Arch Linux and Manjaro:
$ sudo pacman -S curl
Use curl to get public IP address
There are many websites that have been configured to show someone’s public IP address. Use one or more of the following examples below to determine yours.
This site will also work with the -4 or -6 curl options, if you need to retrieve your IPv4 or IPv6 address specifically.
$ curl
OR
$ curl -4
$ curl -6
Of course, other sites also exist that can do the same thing, but these should be enough to cover your needs. In the future, some sites may stop working and new ones will fill their place, so keep in mind that any website on the list may not be permanent.
Closing Thoughts
In this guide, we saw how to retrieve the public IP address of a system by using curl on the Linux command line. This relies on third party public websites to show us our IP address, but it proves to be one of the quickest and easiest ways to see our public IP on the command line.
Comments and Discussions
4 Ways to Find Server Public IP Address in Linux Terminal
In computer networking, an IP (Internet Protocol) address is a numerical identifier assigned permanently or temporarily to every device connected to a network that uses the Internet Protocol for communication. Its two major functions are to identify a network or host on a network and also serve for location addressing.
Read Also: How to Set Static IP Address and Configure Network in Linux
There are currently two versions of IP addresses: IPv4 and IPv6, which can either be private (viewable within an internal network) or public (can be seen by other machines on the Internet).
Additionally, a host can be assigned a static or dynamic IP address depending on the network configurations. In this article, we will show you 4 ways to find your Linux machine or server public IP address from the terminal in Linux.
1. Using dig Utility
dig (domain information groper) is a simple command line utility for probing DNS name servers. To find your public IP addresses, use the resolver as in the command below:
$ dig +short
120. 88. 41. 175
2. Using host Utility
host command is an easy-to-use command line utility for carrying out DNS lookups. The command below will help to display your systems public IP address.
$ host | grep ” has” | awk ‘{print $4}’
Important: The next two methods employ third party websites to display your IP address on the command line as described below.
3. Using wget Command Line Downloader
wget is a powerful command line downloader that supports various protocols like HTTP, HTTPS, FTP and many more. You can use it with third party websites to view your public IP address as follows:
$ wget -qO- | xargs echo
$ wget -qO –
4. Using cURL Command Line Downloader
curl is a popular command line tool for uploading or downloading files from a server using any of the supported protocols (HTTP, HTTPS, FILE, FTP, FTPS and others). The following commands displays your public IP address.
$ curl
That’s It! You may find these following articles useful to read.
5 Linux Command Line Based Tools for Downloading Files and Browsing Websites
11 Ways to Find User Account Info and Login Details in Linux
7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)
That’s all! If you have any questions or other methods to share in relation to this topic, use the feedback form below to write back to us.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2) as a token of appreciation.
We are thankful for your never ending support.
Frequently Asked Questions about curl get ip
What is my IP from ifconfig?
Typically, ifconfig can only be used under a superuser account in your terminal. A list of all your network interfaces will appear. Following the heading of the interface whose IP address you’re searching for, you will see a “inet addr:” section containing your IP address.Sep 20, 2021
What is my IP in Linux?
You can determine the IP address or addresses of your Linux system by using the hostname , ifconfig , or ip commands. To display the IP addresses using the hostname command, use the -I option. In this example the IP address is 192.168. 122.236.
What is my IP from command line?
First, click on your Start Menu and type cmd in the search box and press enter. A black and white window will open where you will type ipconfig /all and press enter. There is a space between the command ipconfig and the switch of /all. Your ip address will be the IPv4 address.