Skip to main content

Creating an IP Lookup with one line

Make a file called public-ip.sh

sudo nano public-ip.sh

Copy this:

#!/bin/bash
# dig command to lookup what the public ip address is

dig +short myip.opendns.com @resolver1.opendns.com

Make it executable:

sudo chmod +x public-ip.sh

Run the file and it will output your current public IP:

./public-ip.sh