5 Commands to Get Public IP using Linux Terminal

Public IP are used for communication between computers over internet. A computer running with public ip is accessible all over world using internet. So we can say that it is the identity of computer on internet. Now the question is how do we know our public ip. Solution is here – use one of the following commands to find public ip of your system using Linux terminal. These are also useful to use in shell script.

Get Public IP using Linux Terminal

Command 1. Using wget

# wget http://ipecho.net/plain -O - -q ; echo

Command 2: Using curl

# curl ipecho.net/plain; echo

Command 3: Using wget

# wget http://observebox.com/ip -O - -q ; echo

Command 4: Using curl

# curl icanhazip.com

Command 5: Using curl

# curl ifconfig.me

Get Public IP in Shell Script

We can simply use following commands in our shell script get our computers public ip and store them in a variable to use anywhere in shell script.

#!/bin/bash

PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
echo $PUBLIC_IP
Next article[SSH] Đơn giản hoá việc sử dụng SSH trên Linux
Bạn đang theo dõi website "https://cuongquach.com/" nơi lưu trữ những kiến thức tổng hợp và chia sẻ cá nhân về Quản Trị Hệ Thống Dịch Vụ & Mạng, được xây dựng lại dưới nền tảng kinh nghiệm của bản thân mình, Quách Chí Cường. Hy vọng bạn sẽ thích nơi này !