Home > Operation and Maintenance > Linux Operation and Maintenance > 5 Commands to Get Public IP Using Linux Terminal

5 Commands to Get Public IP Using Linux Terminal

不言
Release: 2019-03-20 14:02:51
Original
3989 people have browsed it

Public IP is used for communication between computers over the Internet. Computers running with a public IP can be accessed from around the world using the Internet. So we can say it is the identity of the computer on the internet.

5 Commands to Get Public IP Using Linux Terminal

The question now is, how do we know our public intellectual property rights? For a computer with a GUI, you can easily get the IP using a web tool like this, but how do you get the public IP of a computer that only has terminal access.

Solution: You can find your system’s public IP with a Linux terminal using one of the following commands. These are also useful in shell scripts.

Use Linux commands to find the public IP

Command 1:

Use the dig command to find the public IP address. The dig command is a DNS lookup utility used on Linux systems to find public IP addresses by connecting to an OpenDNS server.

$ dig +short myip.opendns.com @resolver1.opendns.com
Copy after login

Command 2:

Use the wget command to obtain the public IP address, as shown in the example below.

$ wget http://ipecho.net/plain -O - -q ; echo
Copy after login

Commands 3, 4 and 5:

Use the curl command to get the public address.

$ curl ipecho.net/plain; echo
Copy after login
$ curl icanhazip.com
Copy after login
$ curl ifconfig.me
Copy after login

Get public IP in shell script

We can simply use the following command in shell script to get the public IP of the computer and store them in variables so that in any shell script Location usage.

#!/bin/bash

PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
echo $PUBLIC_IP
Copy after login

This article has ended here. For more other exciting content, you can pay attention to the Linux Tutorial Video column of the PHP Chinese website!

The above is the detailed content of 5 Commands to Get Public IP Using Linux Terminal. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template