Mostrando entradas con la etiqueta bash shell. Mostrar todas las entradas
Mostrando entradas con la etiqueta bash shell. Mostrar todas las entradas

martes, 1 de septiembre de 2015

How To Find My Public IP Address From Command Line On a Linux

How do I find out my public IP address on the Linux and OS X Unix command line to use with my own bash shell script without using third party web site? Is there command-line option which will show my dynamic IP address on a Ubuntu or Fedora Linux?

There are many ways to find out your public IP address or wan (Wide Area Network) IP on a Linux or Unix-like operating systems such as FreeBSD, OpenBSD, NetBSD, Apple OS X, and others.
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
Estimated completion time1m

Explain IP addresses

An IP is short for Internet Protocol. It is used to identify computers or mobile devices on the Internet. Each device connected to the Internet has an IP address. IP address can be used to personalize information.

Use dig command for determining my public IP address:

  1. Open the Terminal application.
  2. 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:
  3. dig +short myip.opendns.com @resolver1.opendns.com
  4. Or dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
  5. You should see your IP address on screen. This is the fastest way to find out your IP address without using 3rd party site.
Sample outputs:
Fig.01: Use dig command to find your IP address
Fig.01: Use dig command to find your IP address

You can try host command to see the same information:
host myip.opendns.com resolver1.opendns.com
You can also use the Google server to get the same info using dig command:
 
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
 

How do I store my IP address in a shell variable?

The syntax is:
 
myip="$(dig +short myip.opendns.com @resolver1.opendns.com)"
echo "My WAN/Public IP address: ${myip}"
 
Sample outputs:
My WAN/Public IP address: 74.86.144.194

Finding Public/WAN IP address on a router

A few ADSL/Cable router allows you to login to your router using telnet or ssh:
telnet your-router-ip-here
ssh user@your-router-ip-here
telnet 192.168.0.254
ssh admin@192.168.1.254
[admin@dd-wrt ~]#  ifconfig eth1 | grep 'inet addr:' 
[admin@dd-wrt ~]#  ip addr show nas01

Use 3rd party web-sites to get your IP

Please note that I do not recommend following curl/wget method due to security reasons. You have been warned:
 
curl ifconfig.me
curl icanhazip.com
curl ipecho.net/plain
curl ifconfig.co
 

Not a fan of CLI?

Use your own web-browser. Visit the following urls to see your WAN IP:

Linux / UNIX Command To Find Out Who Owns a Domain Name

How do I find out who owns a Internet domain name and its ip address?

The WHOIS system is used by domains and ip address on the Internet. It is used by system administrators to obtain contact information for IP address assignments or domain name administrators. Use whois command as follows:
$ whois domain-name
$ whois -h whois.example.com domain.com
$ whois google.com

Sample outputs:
Registrant:
        Dns Admin
        Google Inc.
        Please contact contact-admin@google.com 1600 Amphitheatre Parkway
         Mountain View CA 94043
        US
        dns-admin@google.com +1.6502530000 Fax: +1.6506188571
    Domain Name: google.com
        Registrar Name: Markmonitor.com
        Registrar Whois: whois.markmonitor.com
        Registrar Homepage: http://www.markmonitor.com
    Administrative Contact:
        DNS Admin
        Google Inc.
        1600 Amphitheatre Parkway
         Mountain View CA 94043
        US
        dns-admin@google.com +1.6506234000 Fax: +1.6506188571
    Technical Contact, Zone Contact:
        DNS Admin
        Google Inc.
        2400 E. Bayshore Pkwy
         Mountain View CA 94043
        US
        dns-admin@google.com +1.6503300100 Fax: +1.6506181499
    Created on..............: 1997-09-15.
    Expires on..............: 2011-09-13.
    Record last updated on..: 2010-03-30.
Find out IP address and its owner:
$ host -t a google.com
Sample outputs:
google.com has address 209.85.231.104
Now, get ip address information:
$ whois 209.85.231.104
Sample outputs:
NetRange:       209.85.128.0 - 209.85.255.255
 CIDR:           209.85.128.0/17
 OriginAS:
 NetName:        GOOGLE
 NetHandle:      NET-209-85-128-0-1
 Parent:         NET-209-0-0-0-0
 NetType:        Direct Allocation
 NameServer:     NS2.GOOGLE.COM
 NameServer:     NS3.GOOGLE.COM
 NameServer:     NS4.GOOGLE.COM
 NameServer:     NS1.GOOGLE.COM
 RegDate:        2006-01-13
 Updated:        2006-06-01
 Ref:            http://whois.arin.net/rest/net/NET-209-85-128-0-1OrgName:        Google Inc.
 OrgId:          GOGL
 Address:        1600 Amphitheatre Parkway
 City:           Mountain View
 StateProv:      CA
 PostalCode:     94043
 Country:        US
 RegDate:        2000-03-30
 Updated:        2009-08-07
 Ref:            http://whois.arin.net/rest/org/GOGL
OrgTechHandle: ZG39-ARIN OrgTechName: Google Inc OrgTechPhone: +1-650-253-0000 OrgTechEmail: arin-contact@google.com OrgTechRef: http://whois.arin.net/rest/poc/ZG39-ARIN
# # ARIN WHOIS data and services are subject to the Terms of Use # available at: https://www.arin.net/whois_tou.html #