Merge pull request #82 from buildplan/fix_ipv6_only

Fix ipv6 only
This commit is contained in:
buildplan 2025-11-25 16:31:15 +00:00 committed by GitHub
commit 5a917cb9e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 13 deletions

View File

@ -7,7 +7,7 @@
----- -----
**Version:** v0.78 **Version:** v0.78.1
**Last Updated:** 2025-11-25 **Last Updated:** 2025-11-25
@ -87,12 +87,12 @@ sha256sum du_setup.sh
Compare the output hash to the one below. They must match exactly. Compare the output hash to the one below. They must match exactly.
`dfc0bba134d1f34c9ccd28d06958a02347924e7a1505bdabfd5f92ca7198907d` `c43b738b6231ed02427d6c885a9f57d2fd56c4e992ab00ef6a89bd4938caef1a`
Or echo the hash to check, it should output: `du_setup.sh: OK` Or echo the hash to check, it should output: `du_setup.sh: OK`
```bash ```bash
echo dfc0bba134d1f34c9ccd28d06958a02347924e7a1505bdabfd5f92ca7198907d du_setup.sh | sha256sum --check echo c43b738b6231ed02427d6c885a9f57d2fd56c4e992ab00ef6a89bd4938caef1a du_setup.sh | sha256sum --check
``` ```
### 3. Run the Script ### 3. Run the Script

View File

@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
# Debian and Ubuntu Server Hardening Interactive Script # Debian and Ubuntu Server Hardening Interactive Script
# Version: 0.78 | 2025-11-25 # Version: 0.78.1 | 2025-11-25
# Changelog: # Changelog:
# - v0.78.1: Collect config failure fixed on IPv6 only VPS.
# - v0.78: Script tries to handles different environments: Direct Public IP, NAT/Router and Local VM only # - v0.78: Script tries to handles different environments: Direct Public IP, NAT/Router and Local VM only
# The configure_ssh function provides context-aware instructions based on different environments. # The configure_ssh function provides context-aware instructions based on different environments.
# In setup_user handle if group exists but user doesn't - attach user to existing group. # In setup_user handle if group exists but user doesn't - attach user to existing group.
@ -89,7 +90,7 @@
set -euo pipefail set -euo pipefail
# --- Update Configuration --- # --- Update Configuration ---
CURRENT_VERSION="0.78" CURRENT_VERSION="0.78.1"
SCRIPT_URL="https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh" SCRIPT_URL="https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh"
CHECKSUM_URL="${SCRIPT_URL}.sha256" CHECKSUM_URL="${SCRIPT_URL}.sha256"
@ -244,7 +245,7 @@ print_header() {
printf '%s\n' "${CYAN}╔═════════════════════════════════════════════════════════════════╗${NC}" printf '%s\n' "${CYAN}╔═════════════════════════════════════════════════════════════════╗${NC}"
printf '%s\n' "${CYAN}║ ║${NC}" printf '%s\n' "${CYAN}║ ║${NC}"
printf '%s\n' "${CYAN}║ DEBIAN/UBUNTU SERVER SETUP AND HARDENING SCRIPT ║${NC}" printf '%s\n' "${CYAN}║ DEBIAN/UBUNTU SERVER SETUP AND HARDENING SCRIPT ║${NC}"
printf '%s\n' "${CYAN} v0.78 | 2025-11-25 ${NC}" printf '%s\n' "${CYAN}v0.78.1 | 2025-11-25 ║${NC}"
printf '%s\n' "${CYAN}║ ║${NC}" printf '%s\n' "${CYAN}║ ║${NC}"
printf '%s\n' "${CYAN}╚═════════════════════════════════════════════════════════════════╝${NC}" printf '%s\n' "${CYAN}╚═════════════════════════════════════════════════════════════════╝${NC}"
printf '\n' printf '\n'
@ -2835,9 +2836,14 @@ collect_config() {
done done
# --- IP Detection --- # --- IP Detection ---
print_info "Detecting network configuration..." print_info "Detecting network configuration..."
# 1. Get the Local LAN IP (the actual interface IP) # 1. Get the Local LAN IP (Explicit Check)
LOCAL_IP_V4=$(ip -4 route get 8.8.8.8 2>/dev/null | head -1 | awk '{print $7}') # This prevents crashing on IPv6-only servers
# 2. Get Public IPs with robust timeouts (prevents hanging on broken IPv6 routes) if ip -4 route get 8.8.8.8 >/dev/null 2>&1; then
LOCAL_IP_V4=$(ip -4 route get 8.8.8.8 | head -1 | awk '{print $7}')
else
LOCAL_IP_V4=""
fi
# 2. Get Public IPs with timeouts
SERVER_IP_V4=$(curl -4 -s --connect-timeout 4 --max-time 5 https://ifconfig.me 2>/dev/null || \ SERVER_IP_V4=$(curl -4 -s --connect-timeout 4 --max-time 5 https://ifconfig.me 2>/dev/null || \
curl -4 -s --connect-timeout 4 --max-time 5 https://ip.me 2>/dev/null || \ curl -4 -s --connect-timeout 4 --max-time 5 https://ip.me 2>/dev/null || \
curl -4 -s --connect-timeout 4 --max-time 5 https://icanhazip.com 2>/dev/null || \ curl -4 -s --connect-timeout 4 --max-time 5 https://icanhazip.com 2>/dev/null || \
@ -2847,6 +2853,7 @@ collect_config() {
curl -6 -s --connect-timeout 4 --max-time 5 https://ip.me 2>/dev/null || \ curl -6 -s --connect-timeout 4 --max-time 5 https://ip.me 2>/dev/null || \
curl -6 -s --connect-timeout 4 --max-time 5 https://icanhazip.com 2>/dev/null || \ curl -6 -s --connect-timeout 4 --max-time 5 https://icanhazip.com 2>/dev/null || \
echo "Not available") echo "Not available")
# --- Display Summary --- # --- Display Summary ---
printf '\n%s\n' "${YELLOW}Configuration Summary:${NC}" printf '\n%s\n' "${YELLOW}Configuration Summary:${NC}"
printf " %-22s %s\n" "Username:" "$USERNAME" printf " %-22s %s\n" "Username:" "$USERNAME"
@ -2859,17 +2866,17 @@ collect_config() {
# --- IP Display Logic --- # --- IP Display Logic ---
if [[ "$SERVER_IP_V4" != "Unknown" ]]; then if [[ "$SERVER_IP_V4" != "Unknown" ]]; then
if [[ "$SERVER_IP_V4" == "$LOCAL_IP_V4" ]]; then if [[ "$SERVER_IP_V4" == "$LOCAL_IP_V4" ]]; then
# 1: Direct Public IP (DigitalOcean, Vultr, etc.) # 1: Direct Public IP
printf " %-22s %s (Direct)\n" "Server IPv4:" "$SERVER_IP_V4" printf " %-22s %s (Direct)\n" "Server IPv4:" "$SERVER_IP_V4"
else else
# 2: NAT (AWS, Oracle, OR Local VM behind Router) # 2: NAT
printf " %-22s %s (Internet)\n" "Public IPv4:" "$SERVER_IP_V4" printf " %-22s %s (Internet)\n" "Public IPv4:" "$SERVER_IP_V4"
if [[ -n "$LOCAL_IP_V4" ]]; then if [[ -n "$LOCAL_IP_V4" ]]; then
printf " %-22s %s (Internal)\n" "Local IPv4:" "$LOCAL_IP_V4" printf " %-22s %s (Internal)\n" "Local IPv4:" "$LOCAL_IP_V4"
fi fi
fi fi
else else
# Fallback if public check failed entirely # Fallback if public check failed
if [[ -n "$LOCAL_IP_V4" ]]; then if [[ -n "$LOCAL_IP_V4" ]]; then
printf " %-22s %s (Local)\n" "Server IPv4:" "$LOCAL_IP_V4" printf " %-22s %s (Local)\n" "Server IPv4:" "$LOCAL_IP_V4"
fi fi

View File

@ -1 +1 @@
dfc0bba134d1f34c9ccd28d06958a02347924e7a1505bdabfd5f92ca7198907d du_setup.sh c43b738b6231ed02427d6c885a9f57d2fd56c4e992ab00ef6a89bd4938caef1a du_setup.sh