Check VPN connectivity from command line
If you're reading this banner, then this page contains affiliate links. Please see the disclosure for more information. And thanks!
I pay TorGuard (affiliate link) for VPN services. Mainly because sometimes I do some shady shit (that’s alliteration). No matter what I’m doing, it is often worthwhile to see how my web browsing traffic looks to the outside world. So here are some notes on how I can check that from a command line.
If you do not care to read (or about) all the words and explanations, feel free to skip to the SHORT VERSION
BACKGROUND
You might be surprised just how much information can be gleaned from just your IP address. I won’t go into the depths of that discussion, but for fun, open another browser or tab and visit: Whats My IP (their spelling, not mine… I’d put an apostrophe before that “s”)
That’s a lot of information based just on your IP and browser, right?!?!
But enough about WHY I might use a VPN sometimes. Let’s talk about how we can check to see if I’m connected to the internet through the VPN. More precisely, we want to see where an external site thinks my IP address is located.
01 From myself
This command will utilize information from DNS Leak Tests:
curl -ks https://www.dnsleaktest.com | grep flag | sed -e 's/.*from \(.*\),.*/\1/'
NOTE: there are a lot of ways to accomplish this from a lot of different sites, this is just what I use
02 From containers
Sometimes I want to see how my containers appear to originate from. So here is a command to execute this same command on all my running containers with a little bit of formatting for readability:
for I in $(docker ps --format '{{.Names}}'); do \
location=$(docker exec -it $I curl -ks https://www.dnsleaktest.com \
| grep flag | sed -e 's/.*from \(.*\),.*/\1/'); \
printf "%-15s%s\n" "$I:" "$location"; \
done
NOTE: I’ve formatted this a bit, but it is a single command that can be cut-and-pasted on a system that has docker containers running
NEXT STEPS
I’ve considered creating an Ansible playbook for this that I can schedule and run from AWX…but that might be overkill.
WHAT I LEARNED
- Linux is fun!
REFERENCES
SHORT VERSION
To avoid tl;dr enjoy this instead:
## 01 From myself
curl -ks https://www.dnsleaktest.com | grep flag | sed -e 's/.*from \(.*\),.*/\1/'
## 02 From containers
for I in $(docker ps --format '{{.Names}}'); do \
location=$(docker exec -it $I curl -ks https://www.dnsleaktest.com \
| grep flag | sed -e 's/.*from \(.*\),.*/\1/'); \
printf "%-15s%s\n" "$I:" "$location"; \
done