The Homeserver saga - Part 1

3 minute read Modified:

Turning a laptop into a homeserver with Nextcloud & collabora in docker
Table of Contents

It is a hot summer and my brain is to overcooked to program anything… Suddenly a bright light appears of nowhere and screams at me:

“You are a privacy slut! All your files are stored on Google Photos and OneDrive. You are using Gmail and Instagram. DO SOMETHING!”.

So I did. I quickly deleted instagram and went from gmail to mailbox.org. But before I could delete all my files from those cloud services I needed an alternative. I needed a homeserver, so I thought the next best thing to do was to turn a laptop I had laying around into my personal server. Of course a laptop uses way more energy than needed, so wake on lan seemed to be a good option back then. I installed ubuntu server on my laptop and activated ssh.

Step 1: Disable sleep when lid is closed

To turn the screen off but stop the laptop from hibernation when closing the lid, we need to to the following commands:

$ sudo su
$ echo 'HandleLidSwitch=ignore' | tee --append /etc/systemd/logind.conf
$ echo 'HandleLidSwitchDocked=ignore' | tee --append /etc/systemd/logind.conf
$ sudo service systemd-logind restart

Step 2: Install ethtool on the laptop and configure firewall

$ sudo apt-get install ethtool

Run ifconfig to check your network interface. You lan interface should be eth0.

Then test if your laptop supports wake on lan by running

$ sudo ethtool eth0

If a g is present in the output, it means that your laptop supports wol. So go ahead and enable wol by typing

$ sudo ethtool -s eth0 wol g

Get the mac address of the interface and write it down.

$ netstat -ei

To stop the firewall from blocking wol packages type

$ sudo ufw allow ssh
$ sudo ufw allow 9
$ sudo ufw enable

Step 3: Enable etherwake and port-forwarding on router

I have an openWrt router, which is an open source linux router. As it runs linux, i can make the machine my slave. I recommend you to get an openWrt router as well. GL.inet has some very affordable and powerful routers.

Install the web-interface for etherwake

$ opkg install luci-app-wol

Configure /etc/config/etherwake and set interface to eth1, respectively the lan interface, no wan:

config 'etherwake' 'setup'
	option 'pathes' '/usr/bin/etherwake /usr/bin/ether-wake'
	option 'sudo' 'off'
	option 'interface' ''
	option 'broadcast' 'off'

Create a config for your laptop with the mac address that you wrote down earlier.

config 'target'
	option 'name' 'popeye'
	option 'mac' '00:22:33:44:55:66'

Test with

/etc/init.d/etherwake start popeye

Enable port forwarding on router

Edit the firewall config at /etc/config/firewall and enable ssh and wol:

config redirect
        option name 'ssh'
        option src 'wan'
        option proto 'tcpudp'
        option src_dport '53734'
        option dest_ip '192.168.8.158'
        option dest_port '22'
        option target 'DNAT'
        option dest 'lan'

config redirect
        option name 'wol'
        option src 'wan'
        option proto 'tcp udp'
        option src_dport '35122'
        option dest_ip '192.168.8.158'
        option dest_port '7'

Choose a src_port that is higher than 10000 and NOT in this List, for security reasons.

Step 4: Install & run docker images

Install docker on your system and pull the docker-compose setup.

Setup some subdomains leading towards your routers ip and ports (or include a duckDNS / dynDNS docker container in the docker-compose file).

Next change the passwords and subdomains in the db.env and docker-compose.yml file. Run docker-compose up -d. Profit.

Useful docker commands

Start Docker containers sudo docker-compose up -d

Show All containers sudo docker ps -a

Kill all Docker Containers: sudo docker kill $(docker ps -q)

Remove all Docker containers sudo docker rm $(docker ps -a -q)

Remove all docker images docker rmi $(docker images -q)

Delete Volumes docker system prune --all --volumes