Last active
April 11, 2024 12:02
-
-
Save tommyv1987/a5fb30f5966e9d7bfbce58d88a85c0c1 to your computer and use it in GitHub Desktop.
A diagnostic of network configurations and connectivity issues for Gateway operators including IPv4/IPv6 forwarding status, firewall rules inspection, routing table examination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "---------------------------------------" | |
echo | |
echo "checking IPv4 forwarding status..." | |
cat /proc/sys/net/ipv4/ip_forward | |
echo "---------------------------------------" | |
echo | |
echo "checking IPv6 forwarding status..." | |
cat /proc/sys/net/ipv6/conf/all/forwarding | |
echo "---------------------------------------" | |
echo | |
echo "checking UFW firewall Status..." | |
if command -v ufw >/dev/null; then | |
ufw status verbose | |
else | |
echo "UFW command not found. ufw may not be installed or configured." | |
fi | |
echo "---------------------------------------" | |
echo | |
network_device=$(ip route show default | awk '/default/ {print $5}') | |
if [ -z "${network_device}" ]; then | |
echo "error: default network device not found." | |
exit 1 | |
fi | |
echo "network Device: $network_device" | |
echo "---------------------------------------" | |
echo | |
echo "inspecting IPv4 firewall rules..." | |
iptables -L FORWARD -v -n | awk -v dev="$network_device" '/^Chain FORWARD/ || /nymtun0/ && dev || dev && /nymtun0/ || /ufw-reject-forward/' | |
echo "---------------------------------------" | |
echo | |
echo "inspecting IPv6 firewall rules..." | |
ip6tables -L FORWARD -v -n | awk -v dev="$network_device" '/^Chain FORWARD/ || /nymtun0/ && dev || dev && /nymtun0/ || /ufw6-reject-forward/' | |
echo "---------------------------------------" | |
echo | |
echo "examining IPv4 routing table..." | |
ip route | |
echo "---------------------------------------" | |
echo | |
echo "examining IPv6 routing table..." | |
ip -6 route | |
echo "---------------------------------------" | |
echo | |
echo "checking IPv4 connectivity (example: google.com)..." | |
ping -c 4 google.com | |
echo "---------------------------------------" | |
echo | |
echo "checking IPv6 connectivity (example: google.com)..." | |
ping6 -c 4 google.com | |
echo "---------------------------------------" | |
echo | |
echo "checking internet and mixnet connectivity (IPv4) via nymtun0..." | |
echo "if a joke is returned there's connectivity through ipv4 and the nymtun, are you ready?" | |
sleep 2 | |
# lets make this fun..... | |
curl -s -H "Accept: application/json" --interface $(ip addr show nymtun0 | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1) https://icanhazdadjoke.com/ | jq -c .joke | |
echo "---------------------------------------" | |
echo | |
echo "checking Internet and mixnet connectivity (IPv6) via nymtun0..." | |
echo "if a joke is returned, there's connectivity through IPv6 and the nymtun. are you ready?" | |
sleep 2 | |
ipv6_address=$(ip addr show nymtun0 | grep 'inet6 ' | awk '{print $2}' | cut -d'/' -f1 | grep -v '^fe80:') | |
if [ -z "$ipv6_address" ]; then | |
echo | |
echo "no globally routable IPv6 address found on nymtun0." | |
echo "please ensure IPv6 is enabled on your VPS or configure your security groups/firewall settings appropriately." | |
echo "unfortunately there's no joke fo you :( and you can't route ipv6 traffic through your gateway to the internet" | |
else | |
joke=$(curl -s -H "Accept: application/json" --interface "$ipv6_address" https://icanhazdadjoke.com/ | jq -c .joke) | |
if [ -z "$joke" ] || [ "$joke" = "null" ]; then | |
echo "failed to fetch a joke. there might be an issue with the Internet connectivity or the joke service." | |
else | |
echo "joke fetched successfully:" | |
echo "$joke" | |
fi | |
fi | |
echo "machine check complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Returns information like: