Add staticIP config and fix 127.0.0.1 (#3419)

* Add staticIP config and fix 127.0.0.1

Add possibility of a staticIP config in Raspiblitz.conf to override globalIP and publicIP detection.

Skip dyndns in case of static ip usage

if curl fails accidentaly it could result in the wrong IP. Only prefer if publicIP is empty.

* add FAQ entry

Co-authored-by: rootzoll <christian@geektank.de>
This commit is contained in:
ChuckNorrison 2022-12-10 14:53:29 +01:00 committed by GitHub
parent d7d1c40866
commit 1f0416bbbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 21 deletions

4
FAQ.md
View File

@ -501,6 +501,10 @@ Yellow is OK. The RaspiBlitz can detect that it can reach a service on the port
For details on how to set port forwarding on your router model see: https://portforward.com
### How can I set a fixed IP?
Add an entry called `staticIP` in `raspiblitz.conf` to prevent external IP detection and force a fixed IP for your node.
### How do I fix a displayed Error in my Config?
When the LCD display is telling you to do a config check:

View File

@ -47,6 +47,7 @@ fi
# FUNCTION updating dyndomain (if update URL is set)
updateDynDNS()
{
if [ "${staticIP}" == "" ]; then
if [ ${#dynUpdateUrl} -gt 0 ]; then
echo "# calling: ${dynUpdateUrl}"
echo "# to update domain: ${dynDomain}"
@ -54,6 +55,9 @@ updateDynDNS()
else
echo "# dynUpdateUrl not set - not updating"
fi
else
echo "# staticIP is set - not updating"
fi
}
# UPDATE

View File

@ -167,9 +167,17 @@ fi
# check for internet connection
if [ ${runGlobal} -eq 1 ]; then
###########################################
# Static IP
# the static IP to override globalIP and publicIP detection
if [ "${staticIP}" != "" ]; then
echo "## static IP found: ${staticIP}"
fi
###########################################
# Global IP
# the public IP that can be detected from outside
if [ "${staticIP}" == "" ]; then
globalIP=""
echo "# getting public IP from third party service"
if [ "${ipv6}" == "on" ]; then
@ -179,7 +187,10 @@ if [ ${runGlobal} -eq 1 ]; then
fi
echo "## curl returned: ${globalIP}"
echo "## curl exit code: ${?}"
else
globalIP=${staticIP}
echo "## staticIP as globalIP: ${staticIP}"
fi
# sanity check on IP data
# see https://github.com/rootzoll/raspiblitz/issues/371#issuecomment-472416349
@ -198,15 +209,25 @@ if [ ${runGlobal} -eq 1 ]; then
if [ ${#globalIP} -eq 0 ]; then
if [ "${ipv6}" == "on" ]; then
globalIP="::1"
else
if [ "${staticIP}" == "" ]; then
# only if publicIP is empty, dont prefer 127.0.0.1
if [ "${publicIP}" != "" ]; then
globalIP="${publicIP}"
else
globalIP="127.0.0.1"
fi
else
globalIP="${staticIP}"
fi
fi
fi
##########################################
# Public IP
# the public that is maybe set by raspiblitz config file (overriding aut-detection)
# the public that is maybe set by raspiblitz config file (overriding auto-detection)
if [ "${publicIP}" == "" ]; then
if [ "${staticIP}" == "" ]; then
# if publicIP is not set by config ... use detected global IP
if [ "${ipv6}" == "on" ]; then
# use ipv6 with square brackets so that it can be used in http addresses like a IPv4
@ -214,6 +235,10 @@ if [ ${runGlobal} -eq 1 ]; then
else
publicIP="${globalIP}"
fi
else
# if a static IP was set, use it as public IP
publicIP="${staticIP}"
fi
fi
##########################################