OpenBazaar devs chose to design the node discovery in a way which prevents from nodes behind dynamic IP addresses to function correctly.
The list of nodes is stored in DHT (Distributed Hash Table) as a list of IP addresses. This works fine if you have a static IP that never changes.
However, it makes your OpenBazaar server unreachable on dynamic IP address change - because DHT is only updated when the node is (re)started.
This issue could be fixed if DHT stored hostnames instead (when applicable), or simply by updating the table more often.
But developers won't be addressing this issue in the current release, so I had to come up with a fix myself.
I'll be using my Raspberry Pi 3 running Raspbian Linux for the purpose of this tutorial.
It may or may not work with other Linux distributions.
Set up Dynamic DNS Hostname
Dynamic DNS (DynDNS) is a method of automatically updating DNS records.
Using a DynDNS hostname we can always access our machine regardless of its IP address.
Create an account at NoIP.com and choose your hostname and domain name.
You can view and edit your active hostnames here.
You don't have to change anything as long as you set up the hostname from the same network.
Update the DynDNS Records Automatically
Every time our dynamic IP address changes we need to update our DNS record.
NoIP.com provides a Dynamic Update Client (DUC) that will do it automatically for us.
Before you proceed with the installation connect to your Raspberry Pi 3 via SSH first:
ssh pi@<your IP addres>
Set Up Dynamic Update Client
There aren't any binaries for Linux that I know, so we'll have to install DUC from source:
tar xf noip-duc-linux.tar.gz
sudo make install
After the installation is done, you will be prompted to sign in to your existing account.
Then, run the following command to create the default config file:
sudo /usr/local/bin/noip2 -C
You will be prompted to sign in again. Follow the instructions.
Start DUC Automatically
In order for DUC to start automatically after a system restart, we have to install it as a startup service.
I've written a simple Systemd script that will take care of it.
chmod 664 noip2.service
Feel free to edit the script according to your environment. You don't have to change anything if you followed my RPi3 installation procedure, though.
Enable the service:
systemctl enable noip2.service
If it doesn't output any error start the service and exit the root environment:
service noip2 start
The hostname should be updated automatically now.
Connect to OB Server via Hostname
Open your OpenBazaar Client and log in to your server.
Click on your profile picture in the top-right corner, open Settings and go to Advanced tab. Find Server Settings and click Change.
In the Server Configurations window click New and enter your new hostname and login credentials to your server.
Click Save Changes and you should be connected to your OpenBazaar server via a hostname instead of IP.
Restart OB Server on IP Address Change
Every time our IP address changes we need to restart the server so it notifies the network of the change.
I wrote a little script for it:
chmod u+x ipaddr-ob.sh
If it gives you a "No such file or directory" error create the bin folder first:
We have to make sure the script runs periodically. Open Crontab:
add the following line:
*/5 * * * * sh /home/pi/bin/ipaddr-ob.sh >/dev/null 2>&1
and hit Ctrl+x followed by typing
Y and hitting the Enter to save the change.
Make sure the record was added to crontab:
If your store has lots of traffic and sales you want to make it as reachable as possible.
In that case, I'd recommend you run the above script every minute instead:
*/1 * * * * sh /home/pi/bin/ipaddr-ob.sh >/dev/null 2>&1
That's all! Hope you find this fix useful.
Please let me know in the comments below how this workaround works for you. Also feel free to contact me if you run into any issues.
Please let us know what you think in the comments section below.