In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to view the public IP in the Linux terminal". In the daily operation, I believe that many people have doubts about how to view the public IP in the Linux terminal. The editor has consulted all kinds of materials and sorted out a simple and useful method of operation. I hope it will be helpful to answer the doubt of "how to view the public IP in the Linux terminal". Next, please follow the editor to study!
Let's first review the general command to view IP:
Ifconfig
Linux command to check the IP address-- ifconfig
The ifconfig command is used to view and change the address and parameters of a network interface
$ifconfig-a
Lo0: flags=849 mtu 8232
Inet 127.0.0.1 netmask ff000000
Hme0: flags=863 mtu 1500
Inet 211.101.149.11 netmask ffffff00 broadcast 211.101.149.255
Ether 8:0:20:a7:4d:21
The system displays the name of the network interface and the status of the interface (up or down)
Information such as IP address and mask of the interface
Take out the native IP address:
Ifconfig | grep Bcast | awk-F:'{print $2}'| awk-F "'{print $1}'
Take out the number of native IP addresses:
Ifconfig | grep Bcast | awk-F:'{print $2}'| awk-F "'{print $1}'| wc-l
How to know your public IP in Linux terminal
Public addresses are assigned by InterNIC and consist of class-based network ID or CIDR-based address blocks (called CIDR blocks) and ensure uniqueness in the global Internet. When the public address is assigned, its route will be recorded in the router in the Internet, so that the traffic accessing the public address can arrive smoothly. Traffic to the destination public address can be reached 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 in the router in the Internet as a route. IP packets that target the address in the CIDR block are directed to the corresponding location.
In this article I will show you several ways to view your public IP address in a Linux terminal. This doesn't make sense for the average user, but a Linux server can be useful when there is no GUI or when logging in as a user who can only use basic tools. In any case, getting a public IP from a Linux terminal makes sense in many ways, and you may need it one day.
Here are the two main commands we use, curl and wget. You can change it.
Output in Curl plain text format:
The code is as follows:
Curl icanhazip.com
Curl ifconfig.me
Curl curlmyip.com
Curl ip.appspot.com
Curl ipinfo.io/ip
Curl ipecho.net/plain
Curl www.trackip.net/i
Output in curl JSON format:
The code is as follows:
Curl ipinfo.io/json
Curl ifconfig.me/all.json
Curl www.trackip.net/ip?json
(a little ugly)
Output in curl XML format:
The code is as follows:
Curl ifconfig.me/all.xml
Curl gets all the IP details (excavator)
Curl ifconfig.me/all
Use DYDNS (useful when you use DYDNS services)
The code is as follows:
Curl-s' http://checkip.dyndns.org' | sed 's/.*Current IP Address:\ ([0-9\.] *). * /\ 1Uniple g'
Curl-s http://checkip.dyndns.org/ | grep-o "[[: digit:].]\ +"
Use Wget instead of Curl
The code is as follows:
Wget http://ipecho.net/plain-O-Q; echo
Wget http://observebox.com/ip-O-Q; echo
Use the host and dig commands
If so, you can also use the host and dig commands directly.
The code is as follows:
Host-t a dartsclink.com | sed 's/.*has address / /'
Dig + short myip.opendns.com @ resolver1.opendns.com
Example of bash script:
The code is as follows:
#! / bin/bash
PUBLIC_IP= `wget http://ipecho.net/plain-O-Q; echo`
Echo $PUBLIC_IP
At this point, the study on "how to view the public IP in the Linux terminal" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.