This is a guide on how to limit the upload and download bandwidth of Bitcoin Core. By the end of this tutorial, you will know how to set a fixed upload limit for Bitcoin Core so that it does not use too much bandwidth.
Preliminary Info About Bitcoin Core Bandwidth
As we know, the bitcoin network is composed of nodes which run separately on different people’s computers (and if you don’t know what a node is, you’re better of reading How to create a bitcoin node first). These nodes discover peers by downloading the peer lists of nodes they are connected to – all nodes are connected to 10 others at startup – and use a messaging protocol to talk to the other nodes.
In case you are wondering how these other nodes manage to discover peers when they aren’t even connected to any yet, is that inside the source code are the addresses of a handful of trusted nodes ran by Bitcoin Core developers. Your node connects to their nodes to discover their peers, connects to their nodes, and the cycle continues.
So your nodes are now connected, by now you notice Bitcoin Core using up a lot of your bandwidth. Maybe you are charged by the gigabyte you consume, or you are just worried that it will throttle your Netflix shows. So what can we do about this situation.
Well first of all, you can limit the upload amount of Bitcoin Core by editing its configuration file. There are three basic methods it can tweak to consume less bandwidth.
- Change the
maxuploadtarget
- Change the
maxconnections
- Set
listen=0
I will explain each of these steps in detail.
Option 1: Changing the maxuploadtarget
The maxuploadtarget
setting in Bitcoin Core adjusts the daily bandwidth that it is allowed to consume by sending data to other peers. The upload amount resets to zero every day, letting your node use the same amount of maximum bandwidth every day. The amount is specified in megabytes (MB). To adjust this setting you need to follow the following steps:
- Close Bitcoin Core. Do not go to step 2 until it has completely shut down.
- Locate your bitcoin.conf file. It is usually inside a folder such as
~/.bitcoin
or%HomeDrive%%HomePath%\AppData\Roaming\Bitcoin
. - Open the bitcoin.conf file and add the following line at the top:
maxuploadtarget=5000
Note: this sets the upload limit to 5000 megabytes (5 gigabytes). If you want to set a different limit, adjust the value inside the file.
- Save and close the file and start Bitcoin Core again.
Now you should see a dramatic reduction in bandwidth usage of Bitcoin Core.
Option 2: Changing the maxconnections
This particular method is less accurate than setting the maxuploadtarget
simply because connections do not use an equal amount of bandwidth. But if you do not like to limit the upload quota of your node, then you can use this method instead. Follow the same instructions as in Option 1, however this time, you are going to put this line in your bitcoin.conf:
maxconnections=25
This will limit the number of connections to your Bitcoin node. You are free to adjust this value to whatever you want, but personally, I have seen nodes having no more than 120 connections in total (inbound and outbound).
Option 3: Set listen=0
This option is not recommended because it completely disables uploading blocks and transactions to peers, which harms the network if too many nodes use his option. But if you want the maximum upload savings, put this line in your bitcoin.conf file and start the program again.
Linux Alternative: Throttle entire system with Wondershaper
This method should only be used if Bitcoin Core is the only process running on the system, as it limits the speed of your entire network connection. It is mainly useful to avoid surprise traffic bills on servers. For example, I see about 10GB of total network traffic from my node per day.
Wondershaper only works on Linux and can be downloaded from Github. After compiling it, you run it from the current directory like so:
sudo ./wondershaper -a wlp4s0 -u 4096 -d 8192
This will limit the WiFi adapter’s upload speed to 4MB and its download speed to 8MB. Use ip addr
to check the names of your network interfaces as they could be different from the ones in the example. Also note that Wondershaper must be ran as root, otherwise you might get a permissions error when it tries to change the network settings.
Linux Alternative: Throttle single app with tc
Maxlaumeister demonstrates how to use the tc program to control Bitcoin Core bandwidth and I will be quoting his guide here (not with quote blocks, because WordPress absolutely sucks at handling nested blocks).
- Make sure you have tc installed by typing
tc
at the command line. If you get “command not found”, install tc using your favorite package manager. If you’re on a Debian-based distribution, the easiest way to install tc is by usingapt-get
:
sudo apt-get update
sudo apt-get install iproute2
- Download the tc.sh script from the official Bitcoin Core repository using wget:
wget https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/qos/tc.sh
- Open the script in a text editor. Find the line that says
IF="eth0"
and changeeth0
to reflect the network interface that your internet connection runs through. To get a list of your computer’s network interfaces, useifconfig
on the command line. My computer is connected wirelessly throughwlan1
, so the IF line of my tc.sh looks like this:
IF="wlan1"
- LINKCEIL should reflect the limit of the network interface, and most likely does not need to be changed.
LINKCEIL="1gbit"
- Change LIMIT to be the maximum bandwidth you want Bitcoin Core to use (I chose 1mbit). If you don’t have any other Bitcoin Core nodes in your local network, you can delete the line that says LOCALNET. This line is there to make a bandwidth exception for port 8333 communications within your local network (i.e. not out to the internet).
LIMIT="1mbit"
Leave the rest of the commands in tc.sh alone unless you know what you’re doing. The final top section of my tc.sh ended up looking like this:
#network interface on which to limit traffic IF="wlan1" #limit of the network interface in question LINKCEIL="1gbit" #limit outbound Bitcoin protocol traffic to this rate LIMIT="1mbit"
- Exit your editor and make the script executable with the following command:
chmod +x ./tc.sh
Run the script as superuser: sudo ./tc.sh
. Your Bitcoin Core bandwidth will be throttled until you reboot your computer!
Optionally, you can set the script to run every time you start your computer. Instructions for running scripts on boot will vary depending on your Linux distribution. On Ubuntu, one of the ways to run a script on boot is by adding the script to your /etc/rc.local
file.
Again, the above steps are credit to Maxlaumiester for the original post.
Windows Alternative: throttle single app with NetBalancer
On the same page, Maxlaumiester demonstrates a way to throttle Bitcoin Core on Windows. Note that this uses a freemium app called NetBalancer that will throttle up to 3 apps for free. To throttle more, you have to but the full version of NetBalancer. The following is credit to him:
- Download and Install NetBalancer.
- Start Bitcoin Core if it isn’t already running.
- Run NetBalancer and you should see a GUI that looks similar to this:
- Find “bitcoin-qt.exe” in the list of running applications in the NetBalancer dialog and double-click it to change its bandwidth rules.
- Under “Upload Priority” choose “Limited”, and set the maximum amount of bandwidth for Bitcoin Core to use. Keep in mind that 1KB/s (Kilobyte per second, note the uppercase “B”) is 8 times as much as 1Kb/s (Kilobit per second, lowercase “b”). NetBalancer measures in Kilobytes (KB) by default, but your internet connection is likely measured in Megabits (Mb). So for example, if you want to limit Bitcoin Core’s bandwidth to 8Mb/s, you will need to enter 1000KB/s into NetBalancer.
- The “bitcoin-qt.exe” entry should show the new rule under the “Priority” column:
- You’re done! NetBalancer will now sit in the background and make sure Bitcoin Core doesn’t use more bandwidth than you want it to.
Once again, credit to Maxlaumiester for the tutorial for Windows.
Is here a way to throttle bandwidth on MacOS?
Yes, but it throttles the entire network connection’s traffic. Older versions of MacOS used to be able to do this using a system tool that is not bundled anymore. Because the tool is not bundled anymore, the MacOS versions in question are out-of-support, and the fact that nobody runs MacOS as a server anyway, I won’t describe this approach. But you are welcome to check out Maxlaumiester’s blog if you are truly interested in it.