Skip to content

Instantly share code, notes, and snippets.

@bmatthewshea
Last active April 3, 2024 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmatthewshea/ec18b2198c49e2b0422717de5ab1c9c8 to your computer and use it in GitHub Desktop.
Save bmatthewshea/ec18b2198c49e2b0422717de5ab1c9c8 to your computer and use it in GitHub Desktop.
Show public IP and other info from simple bash script or alias
Gateway:
192.168.1.1
Private:
192.168.1.101/24
Public:
199.199.199.199
#!/bin/bash
printf "Gateway:\n"; route | grep "^default" | cut -d " " -f 10
# Adjust network interface number (here I use interface #2 "2:" for lan address):
printf "Private:\n"; ip -o ad | grep "2:" | grep "inet " | cut -d " " -f 7
# You do not need dig/nslookup for this to work (no dnsutils packages needed):
printf "Public:\n"; host -t a myip.opendns.com | cut -d " " -f 4
# Instructions:
# Put this file in your path. (It does not need the ".bash" file extension.)
# Set permissions (example): `chmod 755 ~/scripts/myip`
# Run it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment