Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Methods to detect public IP address in bash

As part of an installation script, I want to make an "educated guess" about the machines public IP address. It should be as robust as possible, working on a variety of hosts and platforms. Here is an example:

https://gist.github.com/4669037

This script uses 3 methods and then defaults to the value of /etc/hostname. I have only tested this on Ubuntu so far. Will this be likely to work on other distributions? And are there additional methods that I could add?

like image 732
Jeroen Ooms Avatar asked Jan 29 '13 23:01

Jeroen Ooms


People also ask

How do I find my IP address in bash?

To find out the IP address of Linux/UNIX/*BSD/macOS and Unixish system, you need to use the command called ifconfig on Unix and the ip command or hostname command on Linux. These commands used to configure the kernel-resident network interfaces and display IP address such as 10.8. 0.1 or 192.168. 2.254.

How do I find my public IP address in Terminal?

You can also see your public IP address in the Terminal: just type curl ifconfig.me and your public IP will pop up.

How do I find my public IP address in Unix?

Type the following dig (domain information groper) command on a Linux, OS X, or Unix-like operating systems to see your own public IP address assigned by the ISP: $ dig +short myip.opendns.com @resolver1.opendns.com.

How to find my public IP address from command line on Linux?

Bash command for showing the public IP address of Linux and Unix systems. We can use the host command or dig command as follows to display the public IP address of your Linux or Unix system: host myip.opendns.com resolver1.opendns.com. OR. dig +short myip.opendns.com @resolver1.opendns.com. How To Find My Public IP Address From Command Line On ...

How to find or get IP address in Bash shell?

Bash Shell Command to Find or Get IP address. If no arguments are given to ifconfig command, it displays the status of the currently active interfaces. It shows an Ethernet IP address, Mac address, subnet mask, and other information. Type the following /sbin/ipconfig command to display IP address and releated networking information:

What does the IP command display?

The ip command display information about ip address, manipulate routing, network devices, interfaces, tunnels and much more. The following ip command will show all ip address assigned to your system:

How do I find the IP address of an IP address?

It is recommend that you use the ip command under Linux based systems. The following command will show all ip address: # ip addr show. To see information about eth0 ip address, enter: # ip addr show eth0. Sample outputs:


1 Answers

curl ipinfo.io/ip 

Or

wget -q -O - ipinfo.io/ip 

Or

lynx -source ipinfo.io/ip 

get public ip address

like image 181
Zombo Avatar answered Oct 23 '22 12:10

Zombo