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



Revision #4
Created 3 April 2024 06:55:16 by Nate Nash
Updated 4 June 2025 23:32:00 by Nate Nash