How to Get Your Public IP Address with Curl and ifconfig.me

Posted: | Last updated: | 1 minute read

Inception: In this blog, we are going to learn obtaining your Public IP Address through CLI.

The curl 'ifconfig.me' command is a simple way to obtain your public IP address from the command line using the curl utility. It sends a request to the 'ifconfig.me' web service, which returns your public IP address as plain text.

The curl command is a versatile tool that allows you to transfer data to and from a server. It is installed on most Unix-based systems and is also available for Windows.

Here is a breakdown of each component of the command:

  • curl: invokes the curl utility
  • ifconfig.me: specifies the web service to be used to obtain the IP address

To use the 'curl ifconfig.me' command, simply open a terminal or command prompt and type the command. The output will be your public IP address.

The 'curl ifconfig.me' command can be useful in a variety of situations, such as when you need to remotely access a device on your home network or when you are troubleshooting network issues. It can also be used in scripts or automated tasks that require your public IP address.

In addition to 'ifconfig.me', there are many other web services that provide similar functionality, such as 'ipinfo.io' and 'icanhazip.com'. However, it is important to note that these web services may have different terms of service and data retention policies. It is recommended to review the terms and privacy policies of the web service before using it.

Example:

$ curl ifconfig.me

Output:

vagrant@ubuntu-bionic:~$ curl ifconfig.me
124.123.106.196

For additional information use curl ifconfig.me/all

$ curl ifconfig.me/all

The output will show the public IP Address, user agent and the port you are connected.

ip_addr: 124.123.106.196
remote_host: unavailable
user_agent: curl/7.58.0
port: 18982
language:
referer:
connection:
keep_alive:
method: GET
encoding:
mime: */*
charset:
via: 1.1 google
forwarded: 124.123.106.199, 216.239.34.21
Conclusion: Overall, the `'curl ifconfig.me'` command is a simple and convenient way to obtain your public IP address from the command line. It can be used in a variety of situations and is a useful tool for anyone working with networks and the internet.