[GH-ISSUE #5867] [Bug]: [Feature Request]: Allow manual IP override for Let's Encrypt IP SSL due to Asymmetric Routing #4074

Closed
opened 2026-10-31 20:36:57 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @iran100 on GitHub (Jul 9, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5867

Describe the bug

When trying to obtain a 6-day Let's Encrypt SSL certificate for the server IP (Option 20 -> Option 6), the script auto-detects an incorrect public IP. In certain Iranian ISPs (like MobinNet), asymmetric routing causes external IP API checkers to return an international transit/gateway node IP instead of the server's actual incoming public IP. This makes it impossible to successfully issue or use the SSL certificate.

How to reproduce the problem

  1. Run the x-ui management script via terminal.
  2. Choose option 20 (SSL Certificate Management).
  3. Choose option 6 (Get SSL for IP Address).
  4. Notice that the script automatically picks up an incorrect gateway/transit IP address rather than the local public IP.

Expected behavior

The script should either ask for confirmation before proceeding with the detected IP, or provide a fallback prompt allowing the user to manually enter/override their actual incoming public IP address.

Actual behavior

[INF] Server IP detected: 31.171.101.xxx (Returns transit IP instead of actual server IP)

Relevant logs


Screenshots

No response

3x-ui version

3.4.2

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

Debian 12

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @iran100 on GitHub (Jul 9, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5867 ### Describe the bug When trying to obtain a 6-day Let's Encrypt SSL certificate for the server IP (Option 20 -> Option 6), the script auto-detects an incorrect public IP. In certain Iranian ISPs (like MobinNet), asymmetric routing causes external IP API checkers to return an international transit/gateway node IP instead of the server's actual incoming public IP. This makes it impossible to successfully issue or use the SSL certificate. ### How to reproduce the problem 1. Run the `x-ui` management script via terminal. 2. Choose option 20 (SSL Certificate Management). 3. Choose option 6 (Get SSL for IP Address). 4. Notice that the script automatically picks up an incorrect gateway/transit IP address rather than the local public IP. ### Expected behavior The script should either ask for confirmation before proceeding with the detected IP, or provide a fallback prompt allowing the user to manually enter/override their actual incoming public IP address. ### Actual behavior [INF] Server IP detected: 31.171.101.xxx (Returns transit IP instead of actual server IP) ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.4.2 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system Debian 12 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:36:57 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jul 9, 2026):

Confirmed in source: the IP auto-detection in ssl_cert_issue_for_ip() (x-ui.sh, menu option 20 → 6) has no confirmation or override step when a provider returns a plausible-but-wrong address.

Root cause (x-ui.sh:1524-1563): the function queries a fixed list of external IP-echo services in order and uses the first one that returns HTTP 200 with an IPv4-looking body:

local URL_lists=(
    "https://api4.ipify.org"
    "https://ipv4.icanhazip.com"
    "https://v4.api.ipinfo.io/ip"
    "https://ipv4.myexternalip.com/raw"
    "https://4.ident.me"
    "https://check-host.net/ip"
)
local server_ip=""
for ip_address in "${URL_lists[@]}"; do
    local response=$(curl -s -w "\n%{http_code}" --max-time 3 "${ip_address}" 2> /dev/null)
    ...
    if [[ "${http_code}" == "200" && "${ip_result}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
        server_ip="${ip_result}"
        break
    fi
done

The manual read -rp "Please enter your server's public IPv4 address:" prompt (lines 1551-1561) only triggers if every provider fails outright and server_ip stays empty. If any provider returns a syntactically valid IPv4 address — even the wrong one, as you describe happening with asymmetric routing on your ISP routing outbound probe traffic through a different transit/gateway node than the one inbound HTTP-01 validation would use — the script logs Server IP detected: ... (line 1563, matching your log exactly) and proceeds straight to certificate issuance with no chance to confirm or override.

This is the same class of gap reported in #3910 (there triggered by ALL_PROXY rather than asymmetric routing). That issue was closed after the reporter described a local patch adding a confirm/override prompt, but that change was never merged: I checked both the current main branch and the v3.4.2 tag you're running, and ssl_cert_issue_for_ip() is identical in both — no such prompt exists in either.

Workaround until this is addressed: bypass the script's auto-detection by issuing the certificate yourself with your real incoming IP, then wire it into the panel:

~/.acme.sh/acme.sh --set-default-ca --server letsencrypt --force
~/.acme.sh/acme.sh --issue -d <your-real-public-ip> --standalone \
    --server letsencrypt --certificate-profile shortlived --days 6 \
    --httpport 80 --force
mkdir -p /root/cert/ip
~/.acme.sh/acme.sh --installcert --force -d <your-real-public-ip> \
    --key-file /root/cert/ip/privkey.pem \
    --fullchain-file /root/cert/ip/fullchain.pem \
    --reloadcmd "systemctl restart x-ui 2>/dev/null || rc-service x-ui restart 2>/dev/null"
x-ui cert -webCert /root/cert/ip/fullchain.pem -webCertKey /root/cert/ip/privkey.pem

This mirrors what option 6 runs internally (same --server letsencrypt --certificate-profile shortlived --days 6 flags), just with an IP you supply instead of the auto-detected one. x-ui cert -webCert/-webCertKey is the documented CLI flag for pointing the panel at an existing certificate (main.go, setting/cert subcommands).

@MHSanaei — requesting your input: add a confirm/override prompt right after LOGI "Server IP detected: ${server_ip}" (x-ui.sh:1563) in ssl_cert_issue_for_ip(), similar in spirit to the manual-entry prompt already used a few lines above for the total-detection-failure case.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4921403412 --> @github-actions[bot] commented on GitHub (Jul 9, 2026): Confirmed in source: the IP auto-detection in `ssl_cert_issue_for_ip()` (`x-ui.sh`, menu option 20 → 6) has no confirmation or override step when a provider returns a plausible-but-wrong address. **Root cause** (`x-ui.sh:1524-1563`): the function queries a fixed list of external IP-echo services in order and uses the first one that returns HTTP 200 with an IPv4-looking body: ```bash local URL_lists=( "https://api4.ipify.org" "https://ipv4.icanhazip.com" "https://v4.api.ipinfo.io/ip" "https://ipv4.myexternalip.com/raw" "https://4.ident.me" "https://check-host.net/ip" ) local server_ip="" for ip_address in "${URL_lists[@]}"; do local response=$(curl -s -w "\n%{http_code}" --max-time 3 "${ip_address}" 2> /dev/null) ... if [[ "${http_code}" == "200" && "${ip_result}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then server_ip="${ip_result}" break fi done ``` The manual `read -rp "Please enter your server's public IPv4 address:"` prompt (lines 1551-1561) only triggers if **every** provider fails outright and `server_ip` stays empty. If any provider returns *a* syntactically valid IPv4 address — even the wrong one, as you describe happening with asymmetric routing on your ISP routing outbound probe traffic through a different transit/gateway node than the one inbound HTTP-01 validation would use — the script logs `Server IP detected: ...` (line 1563, matching your log exactly) and proceeds straight to certificate issuance with no chance to confirm or override. This is the same class of gap reported in #3910 (there triggered by `ALL_PROXY` rather than asymmetric routing). That issue was closed after the reporter described a local patch adding a confirm/override prompt, but that change was never merged: I checked both the current `main` branch and the `v3.4.2` tag you're running, and `ssl_cert_issue_for_ip()` is identical in both — no such prompt exists in either. **Workaround until this is addressed:** bypass the script's auto-detection by issuing the certificate yourself with your real incoming IP, then wire it into the panel: ```bash ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt --force ~/.acme.sh/acme.sh --issue -d <your-real-public-ip> --standalone \ --server letsencrypt --certificate-profile shortlived --days 6 \ --httpport 80 --force mkdir -p /root/cert/ip ~/.acme.sh/acme.sh --installcert --force -d <your-real-public-ip> \ --key-file /root/cert/ip/privkey.pem \ --fullchain-file /root/cert/ip/fullchain.pem \ --reloadcmd "systemctl restart x-ui 2>/dev/null || rc-service x-ui restart 2>/dev/null" x-ui cert -webCert /root/cert/ip/fullchain.pem -webCertKey /root/cert/ip/privkey.pem ``` This mirrors what option 6 runs internally (same `--server letsencrypt --certificate-profile shortlived --days 6` flags), just with an IP you supply instead of the auto-detected one. `x-ui cert -webCert`/`-webCertKey` is the documented CLI flag for pointing the panel at an existing certificate (`main.go`, `setting`/`cert` subcommands). @MHSanaei — requesting your input: add a confirm/override prompt right after `LOGI "Server IP detected: ${server_ip}"` (`x-ui.sh:1563`) in `ssl_cert_issue_for_ip()`, similar in spirit to the manual-entry prompt already used a few lines above for the total-detection-failure case. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@MHSanaei commented on GitHub (Jul 9, 2026):

@claude make a pr and add a confirm public ipv4

<!-- gh-comment-id:4923170746 --> @MHSanaei commented on GitHub (Jul 9, 2026): @claude make a pr and add a confirm public ipv4
Author
Owner

@github-actions[bot] commented on GitHub (Jul 9, 2026):

Claude finished @MHSanaei's task in 5m 46s —— View job • claude/issue-5867-20260709-0833 • Create PR ➔


Tasks

  • Read the issue and prior automated comment to understand root cause
  • Read x-ui.sh ssl_cert_issue_for_ip() to confirm exact lines
  • Add a confirm/override prompt for the auto-detected public IPv4
  • Verify script structure
  • Commit, push, and provide PR link

Summary

Added a confirmation step to ssl_cert_issue_for_ip() in x-ui.sh (menu option 20 → 6), right after the existing LOGI "Server IP detected: ${server_ip}" line the automated triage comment pointed to.

Behavior change:

  • The auto-detection loop over the URL_lists providers now also sets a new ip_auto_detected flag when it succeeds.
  • If the IP was auto-detected (not manually typed in because every provider failed), the script now asks: Is <ip> the correct incoming public IPv4 address for this server? [Default y], using the same confirm() helper already used elsewhere in the script (e.g. the "Do you want to proceed?" prompt a few lines above).
  • Pressing Enter/y keeps existing behavior (proceeds with the detected IP) — no change for the common case where detection is correct.
  • Answering n clears server_ip and reuses the existing manual-entry validation loop (same IPv4 regex check used in the all-providers-failed path) so the user can type in their real incoming public IP — directly addressing the asymmetric-routing case from MobinNet where probe traffic exits through a different transit/gateway node than inbound HTTP-01 validation would use.

This is a minimal, self-contained change to the one function; no other files needed updates (no Go/frontend/i18n/OpenAPI surface is touched since this is a pure bash install-script change).

Note on verification: this sandbox's tool permissions require approval for any direct shell-interpreter invocation (bash -n, sh -n, shellcheck, even python3 for scratch checks all returned "requires approval" with no way for me to grant it), so I could not run an automated syntax check. I instead manually re-read the full function line-by-line to confirm every if/fi, while/done, and for/done pair is balanced and indentation is consistent with the surrounding code (diff is a clean, additive 21-line insertion — see commit 9d1e3f03). If you'd like automated verification, adding Bash(bash -n:*) or Bash(shellcheck:*) to --allowedTools would let a future run confirm it directly; otherwise a quick local bash -n x-ui.sh before merging is recommended.

<!-- gh-comment-id:4923173169 --> @github-actions[bot] commented on GitHub (Jul 9, 2026): **Claude finished @MHSanaei's task in 5m 46s** —— [View job](https://github.com/MHSanaei/3x-ui/actions/runs/29005130129) • [`claude/issue-5867-20260709-0833`](https://github.com/MHSanaei/3x-ui/tree/claude/issue-5867-20260709-0833) • [Create PR ➔](https://github.com/MHSanaei/3x-ui/compare/main...claude/issue-5867-20260709-0833?quick_pull=1&title=fix%3A%20confirm%20auto-detected%20public%20IPv4%20before%20issuing%20IP%20certificate&body=Summary%0A%0A-%20ssl_cert_issue_for_ip()%20in%20x-ui.sh%20(menu%20option%2020%2C%20then%20option%206)%20now%20asks%20the%20user%20to%20confirm%20the%20auto-detected%20public%20IPv4%20address%20before%20issuing%20a%20Let's%20Encrypt%20certificate%20for%20it.%0A-%20If%20declined%2C%20the%20user%20can%20manually%20enter%20the%20correct%20incoming%20public%20IPv4%20address%20instead%20of%20the%20auto-detected%20one.%0A-%20This%20addresses%20networks%20with%20asymmetric%20routing%2C%20proxies%2C%20or%20multi-WAN%20setups%20where%20external%20IP-echo%20services%20return%20a%20transit%20or%20gateway%20address%20instead%20of%20the%20server's%20actual%20incoming%20public%20IP%2C%20which%20previously%20caused%20certificate%20issuance%20to%20silently%20proceed%20with%20the%20wrong%20address.%0A%0ATest%20plan%0A-%20Manually%20run%20x-ui%2C%20choose%20option%2020%20then%20option%206%2C%20and%20confirm%20the%20new%20prompt%20appears%20after%20the%20Server%20IP%20detected%20message%2C%20with%20y%20as%20the%20default%20proceeding%20as%20before%20and%20n%20allowing%20manual%20entry%20of%20a%20different%20IPv4.%0A-%20Syntax%20could%20not%20be%20fully%20verified%20in%20this%20sandboxed%20session%20because%20invoking%20bash%20or%20shellcheck%20requires%20tool%20approval%20unavailable%20here%3B%20please%20run%20bash%20-n%20x-ui.sh%20locally%20before%20merging.%0A%0AFixes%20%235867%0A%0AGenerated%20with%20%5BClaude%20Code%5D(https%3A%2F%2Fclaude.ai%2Fcode)) --- ### Tasks - [x] Read the issue and prior automated comment to understand root cause - [x] Read `x-ui.sh` `ssl_cert_issue_for_ip()` to confirm exact lines - [x] Add a confirm/override prompt for the auto-detected public IPv4 - [x] Verify script structure - [x] Commit, push, and provide PR link ### Summary Added a confirmation step to `ssl_cert_issue_for_ip()` in `x-ui.sh` (menu option 20 → 6), right after the existing `LOGI "Server IP detected: ${server_ip}"` line the automated triage comment pointed to. Behavior change: - The auto-detection loop over the `URL_lists` providers now also sets a new `ip_auto_detected` flag when it succeeds. - If the IP was auto-detected (not manually typed in because every provider failed), the script now asks: `Is <ip> the correct incoming public IPv4 address for this server? [Default y]`, using the same `confirm()` helper already used elsewhere in the script (e.g. the "Do you want to proceed?" prompt a few lines above). - Pressing Enter/`y` keeps existing behavior (proceeds with the detected IP) — no change for the common case where detection is correct. - Answering `n` clears `server_ip` and reuses the existing manual-entry validation loop (same IPv4 regex check used in the all-providers-failed path) so the user can type in their real incoming public IP — directly addressing the asymmetric-routing case from MobinNet where probe traffic exits through a different transit/gateway node than inbound HTTP-01 validation would use. This is a minimal, self-contained change to the one function; no other files needed updates (no Go/frontend/i18n/OpenAPI surface is touched since this is a pure bash install-script change). **Note on verification:** this sandbox's tool permissions require approval for any direct shell-interpreter invocation (`bash -n`, `sh -n`, `shellcheck`, even `python3` for scratch checks all returned "requires approval" with no way for me to grant it), so I could not run an automated syntax check. I instead manually re-read the full function line-by-line to confirm every `if`/`fi`, `while`/`done`, and `for`/`done` pair is balanced and indentation is consistent with the surrounding code (diff is a clean, additive 21-line insertion — see commit `9d1e3f03`). If you'd like automated verification, adding `Bash(bash -n:*)` or `Bash(shellcheck:*)` to `--allowedTools` would let a future run confirm it directly; otherwise a quick local `bash -n x-ui.sh` before merging is recommended.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4074
No description provided.