How to know your public IP in Linux terminal

Source: Internet
Author: User
Tags bash script example curl

Public addresses are allocated by InterNIC and consist of class-based network IDs or CIDR-based address blocks (called CIDR blocks), and are guaranteed to be unique across the global Internet. When a public address is assigned, its route is recorded to a router in the Internet, so that traffic to the public address can be reached smoothly. Traffic to the target public address is reachable via the Internet. For example, when a CIDR block is assigned to an organization in the form of a network ID and a subnet mask, the corresponding [network ID, subnet mask] is also stored as a route in the router on the Internet. The destination is the IP packet of the address in the CIDR block that is directed to the corresponding location.

In this article I will cover several ways to view your public IP address in a Linux terminal. This does not make sense for ordinary users, but it can be useful if a Linux server (without a GUI or as a user who can only use basic tools) is logged in. In any case, getting a public IP from a Linux terminal is meaningful in every way, and might be useful someday.

Here are the two commands we use primarily, curl and wget. You can use it for a change.

Curl Plain Text Format output:
    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 format output:
    1. Curl Ipinfo.io/json

    2. Curl Ifconfig.me/all.json

    3. Curl Www.trackip.net/ip?json (a little ugly)

Curl XML Format output:
    1. Curl Ifconfig.me/all.xml

Curl gets all IP details (excavator)
    1. Curl Ifconfig.me/all

Use Dydns (useful when you use the Dydns service)
    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 "[[:d Igit:].] \+"

Use Wget instead of Curl
    1. wget Http://ipecho.net/plain-O-Q; Echo

    2. wget Http://observebox.com/ip-O-Q; Echo

Using the host and Dig commands

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

    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'm actually writing a script to record all the IP changes in my router every day and save it to a file. I found these very useful commands in the search process. Hopefully someday it will help others.

If you want to dive into the Linux system novice, you can also download a German Linux software center trial.
Free: Http://www.nfs-cloud.cn:81/appCenter/open/softcenter

How to know your public IP in Linux terminal

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.