How do I know your public IP address on a Linux terminal?

Source: Internet
Author: User
Tags bash script example

How do I know your public IP address on a Linux terminal?

A public address is assigned by InterNIC and consists of a class-based network ID or CIDR-based address block (referred to as a CIDR Block). It also guarantees its uniqueness on the global Internet. When a public address is assigned, its route will be recorded in a router on the Internet, so that the traffic to access the public address can reach smoothly. Traffic accessing the target public address can be reached through the Internet. For example, when a CIDR block is assigned to an organization in the form of a network ID and subnet mask, the corresponding [network ID, subnet Mask] is also stored as a route in a router on the Internet. The IP address of the target CIDR block is directed to the corresponding location.

In this article, I will introduce several methods to view your public IP addresses on Linux terminals. This is meaningless for common users, but it is useful for Linux servers (no GUI or users who can only use basic tools to log on. In any case, obtaining a public IP address from a Linux terminal is of great significance in various aspects and may be available one day.

The following two commands are used: curl and wget. You can use it again.

 

Curl output in plain text format:
  1. curl icanhazip.com
  2. curl ifconfig.me
  3. curl curlmyip.com
  4. curl ip.appspot.com
  5. curl ipinfo.io/ip
  6. curl ipecho.net/plain
  7. curl www.trackip.net/i

 

Curl JSON output:
  1. curl ipinfo.io/json
  2. curl ifconfig.me/all.json
  3. Curl www.trackip.net/ip? Json (a bit ugly)

 

Curl XML format output:
  1. curl ifconfig.me/all.xml

 

Curl to get all IP details (excavator)
  1. curl ifconfig.me/all

 

Use DYDNS (useful when you use DYDNS)
  1. curl -s 'http://checkip.dyndns.org'| sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
  2. curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"

 

Use Wget to replace Curl
  1. wget http://ipecho.net/plain -O - -q ; echo
  2. wget http://observebox.com/ip -O - -q ; echo

 

Use the host and dig commands

If yes, you can also directly use the host and dig commands.

  1. host -t a dartsclink.com | sed 's/.*has address //'
  2. dig +short myip.opendns.com @resolver1.opendns.com

 

Bash script example:
  1. #!/bin/bash
  2. PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
  3. echo $PUBLIC_IP

Easy to use.

I am actually writing a script to record all IP changes in my vro every day and save them to a file. I found these useful commands during the search process. I hope it can help others one day.

Via: How to get Public IP from Linux Terminal?

Translator: KevinSJ Proofreader: wxy

This article was originally translated by LCTT and launched with the Linux honor in China

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.