Note: IPv4 only and IPv4+IPv6 setups are supported. IPv6 only WILL NOT work. You can still use this repo as a reference though.
- Shell: zsh, oh-my-zsh, tmux
- SSH
- Web server – nginx with automatic http to https redirect and A+ SSL
- Mail server – OpenSMTPD, Dovecot, Rspamd, Redis, RainLoop (+PHP, optional)
- Brute force protection: PF
- VPN: OpenIKED, WireGuard, Unbound, PF
You will have to set up some DNS records prior to running this script. Create the following DNS records:
*.{domain}. 300 IN A {ip}
{domain}. 300 IN A {ip}
www.{domain} 300 IN A {ip}
;; DNS records for mail (will be output after stage 5)
{domain}. 300 IN MX 0 mail.{domain}. ;; so that people know which server serves mail for {domain}
@ IN TXT "v=spf1 mx a:mail.{domain} -all"
Instead of using wildcard (*.{domain}.) you can just set up these domains explicitly: vpn.{domain}, mail.{domain}, www.vpn.{domain}, www.mail.{domain}, www.{domain}, {domain}
If you want to enable IPv6, then add this line to your /etc/hostname.*:
inet6 autoconf -temporary -soii
./setup.sh [stage] [--ssl-test]
# Stages: bootstrap shell nginx ssl mail pf vpn
# By default runs all stages
# --ssl-test flag is used for local development (see `Local Development` section)Stages and their dependencies are located in scripts/ directory. For dependencies, look for the doas pkg_add ... line in the beginning of the corresponding script.
Skip it if doas is already set up
Bootstrap does some basic configuration.
Currently it enables main user to do doas and enables slaacd for IPv6.
Sets up zsh, tmux.
Completely optional.
Depends on: doas Dependants: ssl, mail, vpn
- Creates nginx configuration and logs directories.
- Creates nginx configurations for domain.xxx and mail.domain.xxx
Depends on: doas, nginx Dependants: mail
- Gets certificates via certbot
- Switches nginx configuration to use only secure versions of domains
Depends on: doas, nginx, ssl
- Sets up smtpd, dovecot, rspamd, redis
- Creates a user account username@domainname
- There are scripts available to add, change password and to delete users
- Prints DNS records that you should set up
- Local mail is forwarded to vmail directories (to be able to fetch them via IMAP)
Optional: set up RainLoop web frontend
Optional, manual: set up a reverseDNS record at your VPS provider
Required if using VPS: port 25 is required to receive mail. If you're using VPS chances are it is blocked by default. You will have to contact your VPS provider to open port 25.
Sets up packet filter to block ips which spam your SSH, HTTP, HTTPS, IMAP, SMTP ports
Depends on: doas, nginx
Sets up OpenIKED IKEv2 and WireGuard VPN. Ideas taken from EdgeWalker script https://github.com/fazalmajid/edgewalker
By default, IKEv2 configuration is not set up. IKEv2 uses Preshared key authentication. WireGuard uses asymmetric key + Preshared Key authentication.
New VPN configurations for new clients can be created via a script (WireGuard only). Configurations are made available at a random endpoint at vpn.{{domain}}/
USER_NAME– the user which will be used for everything in the script. Defaults to current user.DOMAIN_NAME– the domain name to create websites for. Defaults to$(hostname | cut -d. -f2-)MAIL_DOMAIN– the domain name where mail server will be hosted. Defaults tomail.$DOMAIN_NAMEVPN_DOMAIN– the domain name where VPNs will be hosted (including their configurations). Defaults tovpn.$DOMAIN_NAME
Virtualization software like VMWare Fusion can help with testing the scripts. To do local development against a vm, do the following setup.
- Download and install the virtualization software of choice, an OpenBSD .iso and do a basic installation of OpenBSD on the VM.
When installing, create a user
testuser. - Once inside the VM, do the following initial setup:
- Configure networking so that the VM can communicate both with the Host and the outside world. In VMWare Fusion, this is done by selecting
Bridged Networkingoption. Be sure to set a static IP for your VM inside of your network for easier maintanence (e.g set/etc/hostname.em0toinet 192.168.0.111 255.255.255.0 192.168.0.255). - Edit
/etc/myname, set it totestserver.testserver.test - Edit
/etc/mygate, set it to your network's default gateway (usually192.168.0.101) - Edit
/etc/hosts, add the following entry:{{VM Static IP}} testserver.test mail.testserver.test vpn.testserver.test www.testserver.test www.mail.testserver.test www.vpn.testserver.test - Edit
/etc/resolv.conf:nameserver <network's gate from step 3> lookup file bind - Enable sshd and set up a connection to testuser.
pkg_add rsync.- Reboot the VM for good measure.
- Configure networking so that the VM can communicate both with the Host and the outside world. In VMWare Fusion, this is done by selecting
- Add the same entry to
/etc/hostson the Host as in (2.4) - Run
make rsync-vm. This will send this whole directory to the VM and do a replace in setup.sh that allows the VM to target the Host when requesting SSL certificates via Certbot. - Spin up Pebble (stub certificate server) by running
make pebbleon the Host machine. See test/pebble/ for more info. - SSH into the VM and run the script. You might want to test the stages one by one by running
./setup.sh <stage>. Note: when running stage SSL, be sure to pass--ssl-testflag to target local Pebble server.
Note! If you are using snapshots, the time will go terribly wrong on the VM. To fix it: rdate pool.ntp.org
Use make ssh-vm to do rdate and ssh to the VM in one go (requires doas)
- README.md – usage instructions, general information about the scripts
- Makefile – contains targets that ease development
- setup.sh – main file that launches the scripts corresponding to particular Stages (see Stages section)
- scripts/ – contains scripts for particular stages.
- env.d/ – contains environment variables and aux functions used by different scripts.
- mail/ - contains configuration templates for dovecot, smtpd et c. Also contains scripts that allow creating new users, deleting existing users and changing passwords.
- nginx/ – contains configuration templates for nginx and site templates
- vpn/ – contains configuration templates for IKEd, WireGuard.
- vpn/wg_create_user.sh – creates additional WireGuard users
- test/ - contains configuration files needed for local development and testing