How to Run OpenBazaar Server behind a Dynamic IP Address


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.

Note: this workaround will NOT make your store accessible 100% of the time. If you need 100% uptime you have to buy a static IP address from your Internet service provider.

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.

Note: Make sure the hostname points to your RPi3 IP address!

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:

cd ~
wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar xf noip-duc-linux.tar.gz
cd noip-2.1.9-1
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.

sudo -s
cd /lib/systemd/system/
wget https://gist.githubusercontent.com/mariodian/8db20006b1465cae3266154603a799e6/raw/71ee9c345713cc4009f4af4ff3aeb00cdf56c768/noip2.service
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
exit

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:

cd ~/bin
wget https://gist.githubusercontent.com/mariodian/c43055509853bffb492b7b228a143764/raw/7dd6575ed47d5c4e7f870b7d5defcfe2d91b8a49/ipaddr-ob.sh
chmod u+x ipaddr-ob.sh

If it gives you a "No such file or directory" error create the bin folder first:

mkdir ~/bin

We have to make sure the script runs periodically. Open Crontab:

crontab -e

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:

crontab -l

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.

If you like my post, don't forget to share it with your followers.

You can also support me by donating some bitcoins. Thank you!

Subscribe to our newsletter for weekly thoughts and tutorials. You'll receive a FREE e-book as a bonus!

What do you think?
WE THOUGHT YOU'D LOVE THESE POSTS TOO

Are you tired of political parasites getting in your way of life?

If yes, let us help you out with our EXCLUSIVE newsletter.

SIGN UP NOW... IT'S FREE

Hide your financial assets with Bitcoin and other cryptocurrencies.

Make your communication private using open-source cryptographic tools.

Mitigate the risk of single point of failure in anything you do with decentralized technologies.

Are you intersted? Then become our subscriber, receive exclusive content straight to your inbox + claim your FREE e-book!

* required

JOIN THE #1 SOURCE ON BITCOIN AND DECENTRALIZATION.

Freedom Node is the edge every crypto enthusiast needs to get ahead in this industry. Click that sleek button to learn more about exactly​ what it is we offer.

Learn More

STAY INFORMED WITH OUR NEWSLETTER + GET FREE BONUS!

Your email address is safe with us. We promise!

* required