• November 28, 2024

Curl Ip

How to use curl to get public IP address - LinuxConfig.org

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
Use cURL's

Use cURL’s “–resolve” option to pin a request to an IP address

When preparing to launch a website, or debugging problems with a site that’s already live, sometimes it can be helpful to bypass CDN and proxy layers when requesting content from the site by sending those web requests directly to a specific IP address without using the site’s public DNS records. This practice of “pinning” a web request directly to a server can be accomplished by changing your /etc/hosts file, which will cause requests for a specified domain name (e. g: “”) to be routed from your local machine to a specified IP address (e. g: 127. 0. 1) until the changes you’ve made to /etc/hosts are reverted.
However, what if you want to pin a single request to an IP address, without modifying your system’s configuration files? Happily, this sort of “ad-hoc” request-pinning is possible via command-line with cURL, which provides a special resolve option, formatted –resolve [DOMAIN]:[PORT]:[IP], that routes all web requests performed during the execution of a cURL command that match a given [DOMAIN] and [PORT] to a specified [IP] address. The values specified by this option (which can be invoked multiple times in a single command to route multiple domain/port combinations to various IP addresses) will apply to the initial request, and also to any redirects that cURL follows during the course of the command.
Examples:
The following curl command:
curl –resolve.. force cURL to use “127. 1” as the IP address when requesting “” over port 80 (HTTP).
The command above can be augmented to look like this:
curl –resolve –resolve.. will force cURL to use “127. 1” as the IP address for requests to “” over ports 80 (HTTP and 443 (HTTPS). This can be useful for sites that automatically redirect HTTP requests to HTTPS requests as a security measure.
Remember, –resolve can be specified multiple times (and for multiple domain/port combinations) for a single cURL command, allowing you to establish complex routing rules for requests that you know will be redirected multiple times across various domains and ports.
Related articles
Using an /etc/hosts file for custom domains during development
Verifying the validity of an SSL certificate
Basic rewrite rule examples
How to use GeoIP Headers
Using custom Vary headers to create variations in Varnish cache
How to find your IP address in Linux | Opensource.com

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.

Frequently Asked Questions about curl ip

Can you curl an IP address?

…will force cURL to use “127.0. 0.1” as the IP address when requesting “www.example.com ” over port 80 (HTTP). … 0.1″ as the IP address for requests to “www.example.com ” over ports 80 (HTTP and 443 (HTTPS). This can be useful for sites that automatically redirect HTTP requests to HTTPS requests as a security measure.Sep 29, 2021

How do I get my IP address to curl?

The following commands will get you the IP address list to find public IP addresses for your machine:curl ifconfig.me.curl -4/-6 icanhazip.com.curl ipinfo.io/ip.curl api.ipify.org.curl checkip.dyndns.org.dig +short myip.opendns.com @resolver1.opendns.com.host myip.opendns.com resolver1.opendns.com.curl ident.me.More items…•Feb 7, 2020

What is ifconfig me IP?

ifconfig.me is a web service that displays information about your connection, including IP address, hostname and User Agent string. Helpfully it provides a simplified interface that can be easily queried to get this information from the command line.Nov 8, 2011

Leave a Reply