Skip to content

This physical Ubuntu home server covers my family’s data backup needs in a local private network using Syncthing and custom Bash scripts for system monitoring, and network security policies configuration.

Notifications You must be signed in to change notification settings

ewardq/Linux-home-server

Repository files navigation

Ubuntu home server 🐧

This physical Ubuntu home server covers my family’s data backup needs in a local private network using Syncthing and custom Bash scripts for system monitoring, and network security policies configuration.

  • Sharing of local network files with Samba (Windows <--> Ubuntu <--> Fedora).
  • Reverse proxy setup for Syncthing using Nginx.
  • Virtual Private Network set up using WireGuard.
  • Server ”Wake on LAN” from main computer and smartphone.
  • Automated backups using Timeshift and server file logging using Cron jobs.

Python system snapshot utility package

This project also has a Python app that monitors your system/server that I use with my own. Output is written to a json file and stdout.

It creates snapshots of the state of the system each 30 seconds (configurable):

{"Tasks": {"total": 440, "running": 1, "sleeping": 354, "stopped": 1, "zombie": 0},
"%CPU": {"user": 14.4, "system": 2.2, "idle": 82.7},
"KiB Mem": {"total": 16280636, "free": 335140, "used": 11621308},
"KiB Swap": {"total": 16280636, "free": 335140, "used": 11621308},
"Timestamp": 1624400255}

Ansible automatic configuration

This Ansible playbook can be used to automatically setup what's shown on this repository. ansible_hs_playbook.yaml

For Wake-on-LAN it's necessary to replace the network_adapter variable for the actual network adapter name on the ansible playbook and it's also necessary to enable the feature on the BIOS as shown in section 4 of the setup on this repo. This section of the playbook only works on Ubuntu for now due to the fact that the network configuration file is different depending on the Linux distro.

SonarQube analysis

SonarQube analysis

Workflow output Coverage report
image image

Setup

#1. SSH access from home network

  • Home server should be accessible from the main computer.
ssh <user>@<ip>
Click here to see result screenshot

image


#2. Install Samba

  • Install Samba. sudo apt install samba

  • Make a shared folder. sudo mkdir /media/myfiles

  • Make main user owner of shared folder. sudo chown $USER: /media/myfiles

  • Create a user and password for shared folder. sudo smbpasswd -a <user>

  • Configure folder location in Samba config file at the end of the file. sudo nano /etc/samba/smb.conf

    • Image
  • Add shared folder on Windows

    • Click here to see result screenshot

      Image

  • Shared files ready to use!


#3. Network files backup

  • Selected files should be sent automatically to central hard drive each week.
    • Click here to see result screenshot

      Image

Image

  • Selected files should be sent to central hard drive when prompted.
    • Click here to see result screenshot

      Image


#4. Wake on LAN

  • Network adapter supports Wake-on-LAN
sudo ethtool <network_adapter>
  • Click here to see result screenshot

    image where:

    • g = Wake on LAN is enabled for Magic packets.
    • p = Wake on LAN is enabled for unicast packets.
  • Enable Wake-on-LAN

sudo ethtool <network_adapter> | grep "Wake-on"
sudo ethtool -s <network_adapter> wol g
  • Click here to see result screenshot

    Image where:

    • d = Disabled.
    • g = Wake on LAN is enabled for unicast packets.
  • Make configuration persistent. For Ubuntu, we have to configure the network adapter on the "netplan" folder:

sudo chmod u+w /etc/netplan/00-installer-config.yaml
nano /etc/netplan/00-installer-config.yaml
  • Click here to see result screenshot

    Image


#5. Network monitoring

  • The user should be able to see which devices are connected to the network.

    • To monitor the local network, you can use the built-in internet service provider tool. To access this tool, search in the back of your home router and search for the modem IP, user and password. Image

    • To monitor the local network on Windows, install WakeMeOnLan.

      • Click here to see result screenshot

        Image

    • To monitor the local network on the server side (Ubuntu), use ip addr to discover the server's network adapter

      • Click here to see result screenshot

        Image

    • npmap <ip>/<mask>

      • Click here to see result screenshot

        Image

  • The user should be able to blacklist selected users.

    • Use the network provider built-in tool.
      • Click here to see result screenshot

        Image


#6. Files backed up log and notification

  • System should keep track of files backed up.
    • [5.1] Create a script to log size, date of modification and number of files

    • #!/bin/bash
      echo "=======================" >> /media/shared_folder_backup.log
      ls -lh /media/myfiles/ >> /media/shared_folder_backup.log
    • [5.2] Change permissions to execute file

    • sudo chmod +x /custom_scripts/record_shared_files.sh
    • [5.3] Schedule task to execute each day

      1. Verify if the user has a crontab
       crontab -l

      Image

      1. Create or edit said user crontab
       crontab -e

      Image

      1. Schedule task to execute every hour
       crontab -e
      • Click here to see result screenshot

        Image

Click Here to see the result on the log file

Image


#7. Automated backup every day

  • Files should be backed up every day without user input.
    • To back up files daily, configure "Recovery" settings.
      • Click Here to see result screenshot

        image

About

This physical Ubuntu home server covers my family’s data backup needs in a local private network using Syncthing and custom Bash scripts for system monitoring, and network security policies configuration.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published