Skip to content

Instantly share code, notes, and snippets.

@jwieder
Created September 25, 2021 15:25
Show Gist options
  • Save jwieder/9d1cbb0cf9e5f5423aaff63b80864c61 to your computer and use it in GitHub Desktop.
Save jwieder/9d1cbb0cf9e5f5423aaff63b80864c61 to your computer and use it in GitHub Desktop.
This is a very hacky bash script to help get a the publicly assigned hostname of an ec2 instance.
#!/bin/bash
### this is a very hacky bash script to help get a the publicly assigned hostname of an ec2 instance.
### it will only work with instances within us-east-1 because we arent checking region, amazonaws suffix, etc.
# Get my public IP
publicIP=$(curl -s whatismyip.akamai.com)
# Make up AWS EC2 host name with public DNS
publicName=ec2-${publicIP//./-}.us-east-1.compute.amazonaws.com
# Echo host name
echo ${publicName}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment