Michal Čihař - Blog Archives for OpenWrt

Running Bitcoin node on Turris Omnia

For quite some I'm happy user of Turris Omnia router. The router has quite good hardware, so I've decided to try if I can run Bitcoin node on that and ElectrumX server.

To make the things easier to manage, I've decided to use LXC and run all these in separate container. First of all you need LXC on the router. This is the default setup, but in case you've removed it, you can add it back in the Updater settings.

Now we will create Debian container. There is basic information on using in Turris Documentation on how to create the container, in latter documentation I assume it is called debian.

It's also good idea to enable LXC autostart, to do so add your container to cat /etc/config/lxc-auto on :

config container
    option name debian

You might also want to edit lxc container configration to enable clean shutdown:

# Send SIGRTMIN+3 to shutdown systemd (37 on Turris Omnia)
lxc.haltsignal = SIGRTMIN+3

To make the system more recent, I've decided to use Debian Stretch (one of reasons was that ElectrumX needs Python 3.5.3 or newer). Which is anyway probably sane choice right now given that it's already frozen and will be soon stable. As Stretch is not available as a download option in Omnia, I've chosen to use Debian Jessie and upgrate it later:

$ lxc-attach  --name debian
$ sed -i s/jessie/stretch/ /etc/apt/sources.list
$ apt update
$ apt full-upgrade

Now you have up to date system and we can start installing dependencies. First thing to install is Bitcoin Core. Just follow the instructions on their website to do that. Now it's time to set it up and wait for downloading full blockchain:

$ adduser bitcoin
$ su - bitcoin
$ bitcoind -daemon

Depending on your connection speed, the download will take few hours. You can monitor the progress using bitcoin-cli, you're waiting for 450k blocks:

$ bitcoin-cli getinfo
{
  "version": 140000,
  "protocolversion": 70015,
  "walletversion": 130000,
  "balance": 0.00000000,
  "blocks": 301242,
  "timeoffset": -1,
  "connections": 8,
  "proxy": "",
  "difficulty": 8853416309.1278,
  "testnet": false,
  "keypoololdest": 1490267950,
  "keypoolsize": 100,
  "paytxfee": 0.00000000,
  "relayfee": 0.00001000,
  "errors": ""
}

Depending how much memory you have (mine has 2G) and what all you run on the router, you will have to tweak bitcoind configuration to consume less memory. This can be done by editing .bitcoin/bitcoin.conf, I've ended up with following settings:

par=1
dbcache=150
maxmempool=150

You can also create startup unit for Bitcoin daemon (place that as /etc/systemd/system/bitcoind.service):

[Unit]
Description=Bitcoind
After=network.target

[Service]
ExecStart=/opt/bitcoin/bin/bitcoind
User=bitcoin
TimeoutStopSec=30min
Restart=on-failure
RestartSec=30

[Install]
WantedBy=multi-user.target

Now we can enable services to start on container start:

systemctl enable bitcoind.service

Then I wanted to setup ElectrumX as well, but I've quickly realized that it uses way more memory that my router has, so there is no option to run it without using swap, what will probably make it quite slow (I haven't tried that).

New free software projects on Hosted Weblate

Hosted Weblate provides also free hosting for free software projects. I'm quite slow in processing the hosting requests, but when I do that, I process them in a batch and add several projects at once.

This time, the newly hosted projects include:

  • DoubleContact - offline contact manager
  • LanguageTool - style and grammar checker for 25+ languages
  • Ghini - botanic collection manager
  • Converse.js - XMPP chat client in your browser
  • Pulse - IT Infrastructure Management Software
  • Turris - high performance and open source router
  • Icinga Editor - GUI for generating Icinga configuration files

If you want to support this effort, please donate to Weblate, especially recurring donations are welcome to make this service alive. You can do them on Liberapay or Bountysource.

OpenWRT and resolving private ranges

For quite a long time, I have a problem, that DNS in my OpenWRT box does not resolv local range on wan interface. Today I have learned that it is doing it in order to protect me:

dnsmasq[15709]: possible DNS-rebind attack detected: jmnet.czf

But hey, my wan interface has 10.* address and I want to resolve 10.* domains there!

A little bit of googling revealed that this is caused by --stop-dns-rebind passed to dnsmasq. Okay, the easiest fix is to disable it. You need to change /etc/config/dhcp:

config 'dnsmasq'
        option 'rebind_protection' '0'

After reading source of /etc/init.d/dnsmasq I realized there is also way to whitelist some domains, what sounds like a slightly better idea. After fighting with syntax, I found the solution to be (again in /etc/config/dhcp):

config 'dnsmasq'
        list 'rebind_domain' '/czf/'

Next thing to explore is why is native IPv6 not working for me on the router though it should...

Temperature monitoring on OpenWrt

My OpenWrt box has for some time connected TM - RS232 sensor. However for some reason I did never find time to setup it. However as the node is already running lite version of munin, it was really easy to do so. All what was needed is to add another plugin into the /usr/sbin/munin-node script and add temp to list of plugins at top:

config_temp() {             
  echo "graph_title Temperature"
  echo "graph_args --base 1000 -l 0 -u 40"    
  echo "graph_vlabel room temperature"                                                                                        
  echo "graph_category other"                                                                                                                   
  echo "graph_info This graph shows the room temperature."
  echo "temp.label temperature"
  echo "temp.draw LINE2"                             
  echo "temp.info The current room temperature."
}                                                                    
fetch_temp() {                                        
  read RES < /dev/ttyUSB0                        
  echo "temp.value" $(echo $RES | tr -d C+)
}

PS: It looks like reading sometimes produces just bogus results, so here is improved version, which does some level of filtering:

read RES1 < /dev/ttyUSB0                       
read RES2 < /dev/ttyUSB0                 
read RES3 < /dev/ttyUSB0                 
if [ "x$RES1" = "x$RES2" ] ; then                  
    echo "temp.value" $(echo $RES1 | tr -d C+)                          
elif [ "x$RES1" = "x$RES3" ] ; then                                 
    echo "temp.value" $(echo $RES1 | tr -d C+)                 
elif [ "x$RES2" = "x$RES3" ] ; then                        
    echo "temp.value" $(echo $RES2 | tr -d C+)                                    
else                                                                       
    echo "temp.value" $(echo $RES2 | tr -d C+)                                                                                            
fi