For Ubuntu you can use ufw.
Remark: UFW is a firewall! If you enable it in the default mode which is "deny all", all new connections on all ports will be denied while existing connections stay open (like your current ssh connection). Make sure to "ufw allow" all ports that you need before you enable ufw. Sometimes you forget a port, but if you are sshing into your server, always allow ssh before you do anything stupid. You can than open ports at a later stage through ssh.
Here it goes:
sudo -s
apt-get update
apt-get install ufw
#deny incoming from subnets
ufw deny from 5.9.115.0/24
ufw deny from 46.105.210.0/24
ufw deny from 2001:41d0:a:605c::/48
#deny outgoing to subnets
ufw deny out from any to 5.9.115.0/24
ufw deny out from any to 46.105.210.0/24
ufw deny out from any to 2001:41d0:a:605c::/48
#these are optional
ufw allow 22 #whatever port you are using for ssh
ufw allow 80 #if you have webserver running
ufw allow 443 #if you have a secure (https) web server running
#allow bitcoin
ufw allow 8333
#start ufw
ufw enable
#go back to normal user level
exit
The order is important. If you allow 8333 and deny incoming from ip ranges later, only the first rule applies.
Hope this does the trick. If I forgot something pleae tell me.