[{"content":"In this series I look at what you can self-host on a VPS and how to do it, in a technical and hands-on way. The server, the assumptions and the roadmap are in the first part: 0 Planning and Architecture.\nHow to read this series Parts with a decimal number (like 2.1) continue their parent topic. The Requirements box at the top of each part shows which parts should be done first.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/","section":"Self Hosting","summary":"In this series I look at what you can self-host on a VPS and how to do it, in a technical and hands-on way. The server, the assumptions and the roadmap are in the first part: 0 Planning and Architecture.\nHow to read this series Parts with a decimal number (like 2.1) continue their parent topic. The Requirements box at the top of each part shows which parts should be done first.\n","title":"Self Hosting","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/syncthing/","section":"Tags","summary":"","title":"syncthing","type":"tags"},{"content":" Requirements 1 Post-Install Configuration (the EPEL repository), 5 Firewalld Configuration and 7.2 Putting Services Behind the VPN must be done. Assumptions\nThe Syncthing web UI is reached at sync.xenonly.com, only over the VPN. A and AAAA records exist for this domain. Devices connect to the server at xenonly.com:22000. Syncthing runs as a separate syncthing system user whose home directory is /srv/syncthing. Server commands are run on the server with root rights (sudo). The device pairing steps are done in the Syncthing UI on the clients. What It Is # Syncthing is an open-source tool that syncs files directly between devices. There is no central cloud service; each device has its own identity (Device ID) and shares files only with the devices we pair it with, over an encrypted connection.\nThe Syncthing we install on the server will be a shared peer of our devices that is always on. Even if the computer and the phone are not on at the same time, changes will reach the other devices through the server.\nDecisions Before Installing # Native installation: Unlike the other applications, we\u0026rsquo;ll install Syncthing directly on the server with the package from the EPEL repository, not with Docker. The package follows the current version and is updated together with the system with dnf upgrade. The systemd service that comes with the package also comes with sandbox settings (read-only system directories, limited privileges and so on).\nA separate user: The sync port will be open to the internet, so we\u0026rsquo;ll run Syncthing as a separate syncthing system user, not as our own user. So if there is ever a hole in Syncthing, an attacker can reach only this user\u0026rsquo;s files; they can\u0026rsquo;t reach our own home directory (for example the keys in ~/.ssh).\nPorts:\nPort Used for Access 22000/tcp Sync (TCP) Public 22000/udp Sync (QUIC) Public 127.0.0.1:8384 Web UI Only through NGINX, with the VPN The sync port will be public: So the full tunnel doesn\u0026rsquo;t have to stay on all the time on the phone (the same reason as in 9 Vaultwarden Setup). Syncthing connections use TLS where both sides check each other\u0026rsquo;s certificate; the server talks only to devices whose Device ID we added.\nThe web UI only over the VPN: By default the Syncthing UI listens only on 127.0.0.1:8384. We\u0026rsquo;ll serve the UI through NGINX with the vpn-only template.\nNote The local discovery port (21027/udp) is used to find devices on the same local network. The server is a VPS and we have no other devices on its local network, so we don\u0026rsquo;t open this port.\nInstallation # Let\u0026rsquo;s install the package:\nbash sudo dnf install syncthing Let\u0026rsquo;s create a system user for Syncthing with /srv/syncthing as its home directory:\nbash sudo useradd --system --create-home --home-dir /srv/syncthing --shell /usr/sbin/nologin syncthing --system: A user for running a service, not for logging in. --home-dir /srv/syncthing: Syncthing\u0026rsquo;s configuration (/srv/syncthing/.local/state/syncthing) and the synced folders will be in this directory. --shell /usr/sbin/nologin: You can\u0026rsquo;t log in with this user. Note On Rocky Linux, home directories are created with 700 permissions by default (you can check with ls -ld /home/*). So the syncthing user can\u0026rsquo;t read the home directories of the other users.\nThe syncthing@.service that comes with the package is a service template that runs as the user given as a parameter. Let\u0026rsquo;s enable and start the service for the syncthing user:\nbash sudo systemctl enable --now syncthing@syncthing sudo systemctl status syncthing@syncthing On the first run Syncthing creates its own keys and configuration. Let\u0026rsquo;s check:\nbash sudo ls /srv/syncthing/.local/state/syncthing # cert.pem, config.xml, key.pem ... sudo ss -tulpn | grep syncthing Port 22000 should show up for TCP and UDP on all addresses (*:22000), and port 8384 only on 127.0.0.1.\nNote The service logs are in journald: sudo journalctl -u syncthing@syncthing\nFirewalld # Let\u0026rsquo;s open the sync port in the public zone and in the VPN zone:\nbash sudo firewall-cmd --permanent --zone=public --add-port=22000/tcp --add-port=22000/udp sudo firewall-cmd --permanent --zone=vpn --add-port=22000/tcp --add-port=22000/udp sudo firewall-cmd --reload Note Why we open it in the VPN zone too: when the full tunnel is connected, the devices\u0026rsquo; traffic to the server\u0026rsquo;s public IP also comes in through wg0 and is checked against the rules of the VPN zone (see 7 WireGuard Setup).\nCertificate and NGINX Reverse Proxy # Let\u0026rsquo;s get the certificate:\nbash sudo certbot certonly --webroot -w /opt/www/well_known -d sync.xenonly.com Let\u0026rsquo;s create /etc/nginx/vhost.d/vhost_sync.xenonly.com.conf like this:\n/etc/nginx/vhost.d/vhost_sync.xenonly.com.confnginx server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name sync.xenonly.com; ssl_certificate /etc/letsencrypt/live/sync.xenonly.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/sync.xenonly.com/privkey.pem; include /etc/nginx/templates/vpn-only.tmpl; location / { proxy_pass http://127.0.0.1:8384; proxy_set_header Host localhost; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 600s; proxy_send_timeout 600s; } } We don\u0026rsquo;t use proxy.tmpl: While the UI is bound to 127.0.0.1, Syncthing requires the Host header of incoming requests to be localhost (against DNS rebinding attacks). proxy.tmpl sends the Host header as sync.xenonly.com, so the UI would give a \u0026ldquo;Host check error\u0026rdquo;. That\u0026rsquo;s why we set the headers one by one here and send the Host header as localhost. proxy_read_timeout 600s: The UI follows changes with requests that stay open for a long time (long polling); the default 60 second timeout cuts these requests. Let\u0026rsquo;s test the NGINX configuration and reload it:\nbash sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx Note To reach it with a split tunnel, add the entry 10.8.0.1 sync.xenonly.com to the hosts file on your personal computer (see 7.3 Possible Problems).\nFirst Configuration # While connected to the VPN, let\u0026rsquo;s go to https://sync.xenonly.com.\nIn Actions → Settings → GUI, let\u0026rsquo;s fill in GUI Authentication User and GUI Authentication Password and save. Even though the UI is behind the VPN, we don\u0026rsquo;t leave it without a password. We don\u0026rsquo;t turn on the Use HTTPS for GUI option on the same page. In the same window, on the Connections tab, let\u0026rsquo;s turn off Enable Local Discovery; there are no other devices of ours on the server\u0026rsquo;s local network. If we won\u0026rsquo;t use the Default Folder that comes by default, we can remove it with the folder\u0026rsquo;s Edit → Remove option. Don\u0026rsquo;t turn on Use HTTPS for GUI HTTPS is provided by NGINX. If this option is on, Syncthing redirects the HTTP requests from NGINX to the address in the Host header. NGINX sends this header as localhost, so the browser goes to https://localhost/ and the UI can\u0026rsquo;t be reached. If the option was turned on by mistake, we can\u0026rsquo;t reach the UI, so let\u0026rsquo;s turn it off in the configuration file on the server:\nbash sudo systemctl stop syncthing@syncthing sudo sed -i \u0026#39;/\u0026lt;gui /s/tls=\u0026#34;true\u0026#34;/tls=\u0026#34;false\u0026#34;/\u0026#39; /srv/syncthing/.local/state/syncthing/config.xml sudo systemctl start syncthing@syncthing Syncthing keeps the configuration in memory and overwrites the file when a change is saved, so we edit the file while the service is stopped.\nNote The server\u0026rsquo;s device name is its hostname (mail.xenonly.com) by default. You can change it in Actions → Settings → General → Device Name.\nPairing Devices # Syncthing must be installed on each device. The steps below are repeated for each device.\nIn the server\u0026rsquo;s UI, let\u0026rsquo;s copy the server\u0026rsquo;s Device ID with Actions → Show ID. In the Syncthing UI on the device, let\u0026rsquo;s enter the server\u0026rsquo;s Device ID with Add Remote Device. On the Advanced tab, let\u0026rsquo;s write tcp://xenonly.com:22000, dynamic in the Addresses field. Within a few seconds, a notice shows up in the server\u0026rsquo;s UI saying that the device wants to connect; let\u0026rsquo;s accept it with Add Device. Note dynamic lets Syncthing find the server again through global discovery if the server\u0026rsquo;s address changes. tcp://xenonly.com:22000 connects directly, without needing discovery.\nSharing a Folder # In the UI on the device, let\u0026rsquo;s tick the server on the Edit → Sharing tab of the folder we want to share. In the server\u0026rsquo;s UI, let\u0026rsquo;s click Add on the notice saying the folder is being shared. By default the Folder Path is under the syncthing user\u0026rsquo;s home directory (/srv/syncthing/\u0026lt;FOLDER\u0026gt;); let\u0026rsquo;s leave it like that. When the same folder is shared with the server on the other devices too, changes reach all devices through the server. Warning Syncthing is not a backup tool; a file deleted on one device is deleted from the other devices too. If Edit → File Versioning → Staggered File Versioning is turned on for the folders on the server, old versions of deleted and changed files are kept on the server in the .stversions directory for a while.\nReaching the Synced Files with Our Own User (Optional) # Only the syncthing user can read the /srv/syncthing directory. If we want to read the synced files on the server with our own user, without sudo, let\u0026rsquo;s add our user to the syncthing group and give the group read access:\nbash sudo usermod -aG syncthing \u0026#34;$USER\u0026#34; sudo chmod 750 /srv/syncthing sudo chmod 700 /srv/syncthing/.local chmod 750 /srv/syncthing: Members of the syncthing group can enter the directory and read the files; other users can\u0026rsquo;t enter it. chmod 700 /srv/syncthing/.local: Syncthing\u0026rsquo;s keys and configuration are in this directory. Nobody, group members included, should be able to read it. Note For the group membership to take effect, you need to log out and log in again. With this setting we can read the files but not change them; changes to the files should be made from the devices, through Syncthing.\nCheck # From our personal computer, while not connected to the VPN:\nbash nc -zv -w 5 xenonly.com 22000 # should connect curl -sI https://sync.xenonly.com | head -1 # HTTP/2 403 On the server:\nbash curl -s http://127.0.0.1:8384/rest/noauth/health # {\u0026#34;status\u0026#34;: \u0026#34;OK\u0026#34;} In the server\u0026rsquo;s UI, the paired devices should show as Connected and the folders as Up to Date.\nBackup and Updates # /srv/syncthing/.local/state/syncthing: The server\u0026rsquo;s identity (cert.pem, key.pem) and configuration are here. If these files are lost, the server starts with a new Device ID and all devices need to be paired again. The synced folders: A copy of the files is already on the other devices too, but Syncthing is not a backup tool, so important folders should be backed up separately. The Syncthing package is updated together with the system with sudo dnf upgrade. After the update, let\u0026rsquo;s restart the service so the new version runs:\nbash sudo systemctl restart syncthing@syncthing ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/syncthing/","section":"Self Hosting","summary":" Requirements 1 Post-Install Configuration (the EPEL repository), 5 Firewalld Configuration and 7.2 Putting Services Behind the VPN must be done. Assumptions\nThe Syncthing web UI is reached at sync.xenonly.com, only over the VPN. A and AAAA records exist for this domain. Devices connect to the server at xenonly.com:22000. Syncthing runs as a separate syncthing system user whose home directory is /srv/syncthing. Server commands are run on the server with root rights (sudo). The device pairing steps are done in the Syncthing UI on the clients. ","title":"Syncthing Setup","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/","section":"Tags","summary":"","title":"Tags","type":"tags"},{"content":"I\u0026rsquo;m actively interested in technology. Here I take notes on what I do and document it. Writing helps me understand and research each topic better, and I share what I did and how to do it with whoever reads it.\n","date":"21 November 2026","externalUrl":null,"permalink":"/","section":"Talha Tabak","summary":"I’m actively interested in technology. Here I take notes on what I do and document it. Writing helps me understand and research each topic better, and I share what I did and how to do it with whoever reads it.\n","title":"Talha Tabak","type":"page"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/docker/","section":"Tags","summary":"","title":"docker","type":"tags"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/memos/","section":"Tags","summary":"","title":"memos","type":"tags"},{"content":" Requirements 4.1 A Ready Template for Docker Containers and 7.2 Putting Services Behind the VPN must be done. Assumptions\nMemos is reached at memos.xenonly.com. A and AAAA records exist for this domain. The Memos container uses port 127.0.0.1:8001. Commands are run on the server with root rights (sudo). What It Is # Memos is a light note app that you use in the browser and can host yourself.\nInstallation # We\u0026rsquo;ll install it with Docker Compose.\nbash sudo mkdir /opt/docker/memos Let\u0026rsquo;s create /opt/docker/memos/compose.yaml like this:\n/opt/docker/memos/compose.yamlyaml services: memos: image: neosmemo/memos:stable container_name: memos restart: unless-stopped ports: - \u0026#34;127.0.0.1:8001:5230\u0026#34; volumes: - ./data:/var/opt/memos environment: MEMOS_PORT: 5230 MEMOS_DRIVER: sqlite MEMOS_INSTANCE_URL: \u0026#34;https://memos.xenonly.com\u0026#34; MEMOS_TRUSTED_PROXIES: \u0026#34;172.20.0.0/16\u0026#34; Let\u0026rsquo;s start the container:\nbash cd /opt/docker/memos sudo docker compose up -d Certificate and NGINX Reverse Proxy # Let\u0026rsquo;s get the certificate:\nbash sudo certbot certonly --webroot -w /opt/www/well_known -d memos.xenonly.com Let\u0026rsquo;s create /etc/nginx/vhost.d/vhost_memos.xenonly.com.conf like this:\n/etc/nginx/vhost.d/vhost_memos.xenonly.com.confnginx server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name memos.xenonly.com; ssl_certificate /etc/letsencrypt/live/memos.xenonly.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/memos.xenonly.com/privkey.pem; client_max_body_size 40m; # Until the first account is created, remove afterwards include /etc/nginx/templates/vpn-only.tmpl; location / { proxy_pass http://127.0.0.1:8001; include /etc/nginx/templates/proxy.tmpl; } } Note client_max_body_size 40m: For files attached to notes. The 12m limit iRedMail sets is too small.\nNote vpn-only.tmpl: In Memos, the first user who signs up becomes the admin. On a public address, if someone else creates the first account, they become the admin. So until the first account is created, Memos will be reachable only over the VPN.\nLet\u0026rsquo;s test the NGINX configuration and reload it:\nbash sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx First Account and Closing Sign-Ups # Let\u0026rsquo;s connect to the VPN with the full tunnel and create our own account at https://memos.xenonly.com. With the admin account, let\u0026rsquo;s close new user sign-ups by turning on Settings → System → Disallow user registration. Let\u0026rsquo;s delete the include /etc/nginx/templates/vpn-only.tmpl; line in the virtual host and reload NGINX with sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx. Note With a split tunnel, the domain resolves to the server\u0026rsquo;s public IP, so the request doesn\u0026rsquo;t go through the VPN and gets a 403 (see 7.3 Possible Problems).\nCheck # bash curl -sI https://memos.xenonly.com | head -1 # HTTP/2 200 Backup and Updates # All of Memos\u0026rsquo; data (the SQLite database and the uploaded files) is in the /opt/docker/memos/data directory; it is the only place that needs a backup.\nTo update:\nbash cd /opt/docker/memos \u0026amp;\u0026amp; sudo docker compose pull \u0026amp;\u0026amp; sudo docker compose up -d ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/memos/","section":"Self Hosting","summary":" Requirements 4.1 A Ready Template for Docker Containers and 7.2 Putting Services Behind the VPN must be done. Assumptions\nMemos is reached at memos.xenonly.com. A and AAAA records exist for this domain. The Memos container uses port 127.0.0.1:8001. Commands are run on the server with root rights (sudo). ","title":"Usememos Setup","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/mariadb/","section":"Tags","summary":"","title":"mariadb","type":"tags"},{"content":" Requirements The MariaDB container from 10 WordPress Setup must be set up and the db network created. 4.1 A Ready Template for Docker Containers must be done (proxy.tmpl and websocket.conf). Assumptions\nThe old server runs WordPress with MariaDB as the database. The example site is example.com, and the site directory on the old server is /var/www/example. Our user on the new server can connect to the old server over SSH (its SSH key is allowed on the old server). The moved site uses port 8031 (pick a free port from the 8030–8049 range set aside for WordPress). The server each command runs on is written before it. On the new server, commands that need root rights are written with sudo. We\u0026rsquo;ll move WordPress sites running on an old server to the new server, fitting them into the setup from 10 WordPress Setup.\nWhat We Need # We\u0026rsquo;ll take two things from the old server:\nDatabase dump: The .sql file of the site\u0026rsquo;s database. Posts, pages, users, comments and all the settings are in it. Site files: The whole WordPress directory. wp-config.php, wp-content (themes, plugins, uploaded images) and .htaccess, if there is one, are in this directory. On the new server the files will be laid out like this:\n/opt/docker/wp-example/ ├── compose.yaml ├── php.ini ├── example.sql ← database dump, deleted after the import └── html/ ← all files of the old site, /var/www/html in the container Warning We keep the dump file outside the html directory. html is the site\u0026rsquo;s root directory; any file put in it can be downloaded from the internet. The dump has user details and password hashes in it.\nSteps # Taking the database dump and the site files from the old server Creating a database and a user for the site in MariaDB and importing the dump Editing wp-config.php for the new setup and starting the container Testing the site before changing DNS Pointing DNS to the new server and setting up the certificate and NGINX Preparation # On the old server, let\u0026rsquo;s get the site\u0026rsquo;s database details, the table prefix and the site address, if it is fixed, from wp-config.php:\nbash grep -E \u0026#34;DB_(NAME|USER|HOST|CHARSET)|table_prefix|WP_(HOME|SITEURL)\u0026#34; /var/www/example/wp-config.php Let\u0026rsquo;s look at the PHP and MariaDB versions:\nbash php -v mariadb --version Note We\u0026rsquo;ll use PHP 8.4 in the container. If the old server uses PHP 7.x, old themes and plugins may give errors. In that case you can use the php8.3-apache image for a while (it is supported until December 2027), but the real fix is to update the plugins.\nWarning No new content (posts, comments, orders) should be created on the old site during the move. Anything added after the dump won\u0026rsquo;t reach the new server.\nTaking the Data from the Old Server # On the old server, let\u0026rsquo;s take the database dump:\nbash ( umask 077 mariadb-dump --single-transaction --default-character-set=utf8mb4 -u \u0026lt;OLD_USER\u0026gt; -p \u0026lt;OLD_DB\u0026gt; \u0026gt; ~/example.sql ) umask 077: So the dump file is created readable only by us. It runs in the subshell inside the parentheses, so it doesn\u0026rsquo;t affect the rest of the session. --single-transaction: Takes a consistent dump while the site is running, without locking the tables. We don\u0026rsquo;t use --databases: This option adds CREATE DATABASE and USE lines with the old database\u0026rsquo;s name to the dump. On import, the tables would go to a new database with the old name instead of wp_example. Note On MariaDB versions older than 10.4, the command is called mysqldump.\nOn the new server, let\u0026rsquo;s create the site directory and pull the files.\nThe new server\u0026rsquo;s SSH is reachable only over the VPN, so the old server can\u0026rsquo;t connect to the new server. That\u0026rsquo;s why we connect from the new server to the old one and pull the data:\nbash sudo mkdir -p /opt/docker/wp-example/html sudo chown -R \u0026#34;$USER\u0026#34;: /opt/docker/wp-example cd /opt/docker/wp-example rsync -a --info=progress2 \u0026lt;USER\u0026gt;@\u0026lt;OLD_SERVER\u0026gt;:/var/www/example/ html/ scp \u0026lt;USER\u0026gt;@\u0026lt;OLD_SERVER\u0026gt;:example.sql . Note To pull the files with our normal user\u0026rsquo;s SSH key, we give the directory to our own user for a while. We\u0026rsquo;ll fix the ownership below.\nrsync must be installed on the old server too. The / at the end of the source directory matters; it copies the contents of the directory into html, not the directory itself. \u0026lt;USER\u0026gt; must be able to read all the site files. If it can\u0026rsquo;t, and you have sudo rights on the old server, you can add --rsync-path=\u0026quot;sudo rsync\u0026quot; to the rsync command. If the old server\u0026rsquo;s SSH port is different, use rsync -e 'ssh -p \u0026lt;PORT\u0026gt;' and scp -P \u0026lt;PORT\u0026gt;. If a cache plugin is used, there is no need to move the cache directory: --exclude 'wp-content/cache/' Database and User # On the new server, let\u0026rsquo;s create a database password for the site:\nbash openssl rand -hex 24 Note We\u0026rsquo;ll use the password from the output wherever \u0026lt;DB_PASSWORD\u0026gt; is written below.\nLet\u0026rsquo;s connect to MariaDB:\nbash sudo docker exec -it mariadb sh -c \u0026#39;exec mariadb -uroot -p\u0026#34;$MARIADB_ROOT_PASSWORD\u0026#34;\u0026#39; and create the site\u0026rsquo;s database and user:\nsql CREATE DATABASE wp_example CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER \u0026#39;wp_example\u0026#39;@\u0026#39;%\u0026#39; IDENTIFIED BY \u0026#39;\u0026lt;DB_PASSWORD\u0026gt;\u0026#39;; GRANT ALL PRIVILEGES ON wp_example.* TO \u0026#39;wp_example\u0026#39;@\u0026#39;%\u0026#39;; exit Note The tables in the dump are created with their own character set and collation; the database default only applies to tables created later.\nImporting the Database # bash cd /opt/docker/wp-example sudo docker exec -i mariadb sh -c \u0026#39;exec mariadb -uroot -p\u0026#34;$MARIADB_ROOT_PASSWORD\u0026#34; wp_example\u0026#39; \u0026lt; example.sql Note We use -i instead of -it. We redirect the dump file to the container\u0026rsquo;s input, so no terminal (-t) should be opened.\nLet\u0026rsquo;s check that the tables are there:\nbash sudo docker exec -it mariadb sh -c \u0026#39;exec mariadb -uroot -p\u0026#34;$MARIADB_ROOT_PASSWORD\u0026#34; -e \u0026#34;SHOW TABLES\u0026#34; wp_example\u0026#39; The tables should be listed with the old site\u0026rsquo;s table prefix (wp_ or a different prefix).\nFiles and wp-config.php # Let\u0026rsquo;s fix the ownership of the files:\nbash sudo chown -R 33:33 /opt/docker/wp-example/html sudo chown root:root /opt/docker/wp-example Note In the container, Apache runs as the www-data user (UID 33). For things like updating plugins and uploading images, it must own the files. We also give the site directory back to root.\nLet\u0026rsquo;s open /opt/docker/wp-example/html/wp-config.php and change the database details for the new setup:\n/opt/docker/wp-example/html/wp-config.phpphp define( \u0026#39;DB_NAME\u0026#39;, \u0026#39;wp_example\u0026#39; ); define( \u0026#39;DB_USER\u0026#39;, \u0026#39;wp_example\u0026#39; ); define( \u0026#39;DB_PASSWORD\u0026#39;, \u0026#39;\u0026lt;DB_PASSWORD\u0026gt;\u0026#39; ); define( \u0026#39;DB_HOST\u0026#39;, \u0026#39;mariadb\u0026#39; ); Note We don\u0026rsquo;t touch the $table_prefix value; the tables in the dump were created with this prefix.\nIn the same file, let\u0026rsquo;s add the lines below above the line /* That's all, stop editing! */:\n/opt/docker/wp-example/html/wp-config.phpphp if ( isset( $_SERVER[\u0026#39;HTTP_X_FORWARDED_PROTO\u0026#39;] ) \u0026amp;\u0026amp; strpos( $_SERVER[\u0026#39;HTTP_X_FORWARDED_PROTO\u0026#39;], \u0026#39;https\u0026#39; ) !== false ) { $_SERVER[\u0026#39;HTTPS\u0026#39;] = \u0026#39;on\u0026#39;; } Important In a new installation, the wp-config.php the image creates already has this. The moved site has its own wp-config.php, so the image doesn\u0026rsquo;t touch it, and we need to add it by hand. Without it, WordPress thinks the request from NGINX is HTTP and keeps redirecting to HTTPS; the browser shows a \u0026ldquo;too many redirects\u0026rdquo; error.\nSome plugins (cache, security and WAF plugins) write the old server\u0026rsquo;s directory path into files. Let\u0026rsquo;s find the files that contain the old path:\nbash sudo grep -rlF \u0026#39;/var/www/example\u0026#39; /opt/docker/wp-example/html --include=\u0026#39;*.php\u0026#39; --include=\u0026#39;.htaccess\u0026#39; --include=\u0026#39;.user.ini\u0026#39; Note Inside the container the new path is /var/www/html. Fix the path in the files you find, or reset the settings of that plugin.\nLet\u0026rsquo;s check whether .htaccess has lines that run PHP in a different way:\nbash sudo grep -nE \u0026#39;AddHandler|SetHandler\u0026#39; /opt/docker/wp-example/html/.htaccess Warning AddHandler / SetHandler lines specific to the old server or hosting panel stop PHP from running in the Apache in the container. Then the .php files may be served as plain text instead of being run, and the passwords in wp-config.php get exposed. If there are such lines, delete them.\nNote If the old server used PHP-FPM, the PHP settings in the .user.ini file are not read in the container. Move the needed settings to the php.ini file.\nPHP Settings and Compose # Let\u0026rsquo;s create the file /opt/docker/wp-example/php.ini with the content below:\n/opt/docker/wp-example/php.iniini upload_max_filesize = 64M post_max_size = 64M memory_limit = 256M max_execution_time = 300 Let\u0026rsquo;s create /opt/docker/wp-example/compose.yaml like this:\n/opt/docker/wp-example/compose.yamlyaml services: wordpress: image: wordpress:php8.4-apache container_name: wp-example restart: unless-stopped ports: - \u0026#34;127.0.0.1:8031:80\u0026#34; volumes: - ./html:/var/www/html - ./php.ini:/usr/local/etc/php/conf.d/custom.ini:ro networks: - default - db networks: db: external: true Note The difference from a new installation is that there is no environment section. The database details are in wp-config.php, and there is no need for a .env file either.\nNote The html directory is not empty, so the image doesn\u0026rsquo;t copy WordPress and doesn\u0026rsquo;t touch the existing wp-config.php.\nLet\u0026rsquo;s start the container:\nbash sudo docker compose up -d sudo docker logs wp-example 2\u0026gt;\u0026amp;1 | tail -5 Testing Before Changing DNS # While DNS still points to the old server, we can test the site from inside the server. Let\u0026rsquo;s send a request straight to the container, sending the headers NGINX would send ourselves:\nbash curl -sI -H \u0026#39;Host: example.com\u0026#39; -H \u0026#39;X-Forwarded-Proto: https\u0026#39; http://127.0.0.1:8031/ curl -s -H \u0026#39;Host: example.com\u0026#39; -H \u0026#39;X-Forwarded-Proto: https\u0026#39; http://127.0.0.1:8031/ | grep -io \u0026#39;\u0026lt;title\u0026gt;.*\u0026lt;/title\u0026gt;\u0026#39; If you get HTTP/1.1 200 OK and the site\u0026rsquo;s title, the database connection and wp-config.php are correct. If you get Error establishing a database connection or a 500 error, check the database details in wp-config.php and the output of sudo docker logs wp-example. If you keep getting a 301 to https://example.com/, the HTTPS lines were not added to wp-config.php. If the site address is set with www (https://www.example.com), use www.example.com in the Host header; otherwise a redirect to the www address is normal. DNS, Certificate and NGINX # We get the certificate with the webroot method, so Let\u0026rsquo;s Encrypt must reach the new server when it checks the domain. That\u0026rsquo;s why we change DNS first.\nIn DNS, let\u0026rsquo;s change the A and AAAA records of example.com and www.example.com to the new server\u0026rsquo;s addresses. When dig +short example.com returns the new IP address, let\u0026rsquo;s get the certificate:\nbash sudo certbot certonly --webroot -w /opt/www/well_known -d example.com -d www.example.com Tip If the TTL of the DNS record is high, the change can take a long time to spread. Lowering the TTL to a small value (for example 300) a day before the move makes this shorter.\nLet\u0026rsquo;s create /etc/nginx/vhost.d/vhost_example.com.conf like this:\n/etc/nginx/vhost.d/vhost_example.com.confnginx server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name example.com www.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; client_max_body_size 64m; location = /xmlrpc.php { deny all; } location / { proxy_pass http://127.0.0.1:8031; include /etc/nginx/templates/proxy.tmpl; } } Note The site is already installed, so there is no setup wizard step and no vpn-only line. The lines are explained in the Certificate and NGINX Reverse Proxy section of 10 WordPress Setup.\nLet\u0026rsquo;s test the NGINX configuration and reload it:\nbash sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx Note Until the DNS change has spread, some visitors keep going to the old server; let\u0026rsquo;s not shut down the old site for a few days.\nIf the Domain or Address Changed # If the site ran with http:// on the old server, or if the domain changed, we need to change the addresses in the database.\nWe don\u0026rsquo;t use sed on the dump file for this. WordPress stores some settings serialized, so together with the character count of the text. When sed changes the length of the address, this data breaks. WP-CLI fixes the character counts while it replaces.\nbash sudo docker run --rm --user 33:33 --volumes-from wp-example --network container:wp-example \\ wordpress:cli wp search-replace \u0026#39;http://eski.com\u0026#39; \u0026#39;https://example.com\u0026#39; --all-tables --skip-columns=guid --dry-run --dry-run: Shows how many records would change, without changing anything. If the result makes sense, run it again without --dry-run. --volumes-from and --network container:: The WP-CLI container uses the site\u0026rsquo;s files and network; it connects to MariaDB with the details in wp-config.php. --user 33:33: The WP-CLI image is based on Alpine, and its default user has a different UID (82). It should reach the files with the same user as the site container. --skip-columns=guid: The guid of the posts is used as a permanent ID; we don\u0026rsquo;t change it, so RSS readers don\u0026rsquo;t think the old posts are new. Note If WP_HOME or WP_SITEURL is defined in wp-config.php (the grep output in the Preparation section), the site address comes from these lines, not from the database; update them too.\nLet\u0026rsquo;s check the site address:\nbash sudo docker run --rm --user 33:33 --volumes-from wp-example --network container:wp-example \\ wordpress:cli wp option get siteurl Note On sites installed from scratch, like in 10 WordPress Setup, wp-config.php reads the database details from the environment variables. On those sites, give WP-CLI the same variables (-e WORDPRESS_DB_HOST=mariadb -e WORDPRESS_DB_NAME=... -e WORDPRESS_DB_USER=... -e WORDPRESS_DB_PASSWORD=...).\nFinal Checks # Do the home page, the post pages and the images open? If the post pages give 404: Settings → Permalinks → Save Changes. WordPress writes the .htaccess file again. If the old server used NGINX, there is no .htaccess file and this step is needed. On the Settings → General page, the WordPress Address and Site Address must be https://example.com. The Tools → Site Health page should show no critical problems. If there is a cache plugin, let\u0026rsquo;s clear the cache. Do the contact form and password reset mails go out? If not, look at the Sending Mail section of 10 WordPress Setup. If an SMTP plugin on the old site is set up for the old mail server, update its settings. Let\u0026rsquo;s delete the dump files; they have user details and password hashes in them.\nOn the new server:\nbash sudo rm /opt/docker/wp-example/example.sql On the old server:\nbash rm ~/example.sql ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/wordpress-migration/","section":"Self Hosting","summary":" Requirements The MariaDB container from 10 WordPress Setup must be set up and the db network created. 4.1 A Ready Template for Docker Containers must be done (proxy.tmpl and websocket.conf). Assumptions\nThe old server runs WordPress with MariaDB as the database. The example site is example.com, and the site directory on the old server is /var/www/example. Our user on the new server can connect to the old server over SSH (its SSH key is allowed on the old server). The moved site uses port 8031 (pick a free port from the 8030–8049 range set aside for WordPress). The server each command runs on is written before it. On the new server, commands that need root rights are written with sudo. ","title":"Moving an Old WordPress Site into This Setup","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/wordpress/","section":"Tags","summary":"","title":"wordpress","type":"tags"},{"content":" Requirements 3 NGINX Configuration, 4 Docker Setup and 4.1 A Ready Template for Docker Containers must be done. For the sites to send mail, 2 Mail Server Setup must be done. To finish the setup wizard behind the VPN, 7.2 Putting Services Behind the VPN must be done. Assumptions\nThe example site is example.com, and the site\u0026rsquo;s short name is example. The short name is used in directory, container and database names; for each site, replace every example with the site\u0026rsquo;s name. A and AAAA records exist for example.com and www.example.com. The port range 8030–8049 is set aside for WordPress sites; the first site uses port 8030. Commands are run on the server with root rights (sudo). We\u0026rsquo;ll install the WordPress sites with Docker. Each site will run in its own container, and all sites will use one shared MariaDB container.\nArchitecture # ┌→ 127.0.0.1:8030 → wp-example ──┐ Internet → NGINX:443 ─┤ ├─ db network (internal) → mariadb └→ 127.0.0.1:8031 → wp-other ────┘ Each site runs in its own container with the official wordpress image (Apache + PHP). All sites use a single MariaDB container. Each site has its own database and its own user that has rights only on that database. MariaDB is on an internal Docker network named db. Only the WordPress containers are on this network; MariaDB can\u0026rsquo;t be reached from the host or from the internet, and MariaDB can\u0026rsquo;t reach the internet either. The site files are on the host, in the /opt/docker/wp-\u0026lt;site\u0026gt;/html directory. Like the other services, the WordPress containers open ports only on 127.0.0.1 and are served to the outside with NGINX. Note Why a single MariaDB: a separate MariaDB container for each site means spending RAM for each of them. At this scale one MariaDB is enough; we keep the sites apart by giving each site its own database user.\nNote The shared db network also connects the WordPress containers to each other; a compromised site can reach the other sites directly on port 80, skipping NGINX. The sites are already open to the internet, so this gives no extra access; the only difference is that the restrictions in NGINX (vpn-only, Fail2Ban) are skipped. If you want full separation, you can create a separate internal network for each site and connect MariaDB to all of them.\nNote We don\u0026rsquo;t use the MariaDB on the host (the one iRedMail installed). The mail server\u0026rsquo;s database and the websites\u0026rsquo; databases should stay apart.\nMariaDB Container # This part is done once, for all sites.\nLet\u0026rsquo;s create the directory, generate a random root password and write it to the .env file:\nbash sudo mkdir -p /opt/docker/mariadb cd /opt/docker/mariadb sudo sh -c \u0026#39;umask 077; echo \u0026#34;MARIADB_ROOT_PASSWORD=$(openssl rand -hex 24)\u0026#34; \u0026gt; .env\u0026#39; Note cd and redirection (\u0026gt;) are done by the shell itself, so written as sudo cd or sudo echo ... \u0026gt; .env they don\u0026rsquo;t run with root rights. That\u0026rsquo;s why we create the file in a single root shell with sudo sh -c; umask 077 makes sure only root can read the file.\nLet\u0026rsquo;s create /opt/docker/mariadb/compose.yaml like this:\n/opt/docker/mariadb/compose.yamlyaml services: mariadb: image: mariadb:11.4 container_name: mariadb restart: unless-stopped environment: MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD} MARIADB_AUTO_UPGRADE: \u0026#34;1\u0026#34; MARIADB_ROOT_HOST: localhost volumes: - ./data:/var/lib/mysql networks: - db networks: db: name: db internal: true Why each line is there:\nNo ports: Only the containers on the db network will reach MariaDB; we don\u0026rsquo;t open a port on the host. ${MARIADB_ROOT_PASSWORD}: Docker Compose reads this value from the .env file in the same directory; the password doesn\u0026rsquo;t sit in the open in the compose file. MARIADB_AUTO_UPGRADE: \u0026quot;1\u0026quot;: When the image is updated, the database files are upgraded to the new version automatically. MARIADB_ROOT_HOST: localhost: We don\u0026rsquo;t need root access over the network, so we stop the root@'%' user from being created. Root access will be possible only from inside the container. name: db: We fix the network\u0026rsquo;s name. Compose normally puts the project name in front of the network name (mariadb_db); from the WordPress compose files we\u0026rsquo;ll connect to this network with the name db. internal: true: The containers on this network can\u0026rsquo;t reach the internet. MariaDB doesn\u0026rsquo;t need the internet, and the WordPress containers will reach the internet through their own networks. Let\u0026rsquo;s start the service:\nbash sudo docker compose up -d sudo docker logs mariadb 2\u0026gt;\u0026amp;1 | tail -3 If the output shows ready for connections, MariaDB is ready.\nNote MARIADB_ROOT_PASSWORD is used only on the first run, while the data directory is empty. Changing the password in the .env file later doesn\u0026rsquo;t change the root password. To change it, first change it in MariaDB with ALTER USER, then in the .env file.\nTo connect to MariaDB as root:\nbash sudo docker exec -it mariadb sh -c \u0026#39;exec mariadb -uroot -p\u0026#34;$MARIADB_ROOT_PASSWORD\u0026#34;\u0026#39; Note The password is read from the MARIADB_ROOT_PASSWORD variable inside the container, so we don\u0026rsquo;t need to type it. The single quotes matter; the variable must be expanded inside the container, not on the host.\nSetting Up a New Site # This part is repeated for every new site. For the first site I\u0026rsquo;ll use port 8030.\nDatabase and User # Let\u0026rsquo;s create a database password for the site:\nbash openssl rand -hex 24 Note We\u0026rsquo;ll use the password from the output wherever \u0026lt;DB_PASSWORD\u0026gt; is written below.\nLet\u0026rsquo;s connect to MariaDB:\nbash sudo docker exec -it mariadb sh -c \u0026#39;exec mariadb -uroot -p\u0026#34;$MARIADB_ROOT_PASSWORD\u0026#34;\u0026#39; and create the site\u0026rsquo;s database and user:\nsql CREATE DATABASE wp_example CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER \u0026#39;wp_example\u0026#39;@\u0026#39;%\u0026#39; IDENTIFIED BY \u0026#39;\u0026lt;DB_PASSWORD\u0026gt;\u0026#39;; GRANT ALL PRIVILEGES ON wp_example.* TO \u0026#39;wp_example\u0026#39;@\u0026#39;%\u0026#39;; exit Note '%' means it can connect from any address. MariaDB can be reached only from the db network, so this is not a problem.\nNote The user has rights only on its own database. Even if one site is compromised, the databases of the other sites can\u0026rsquo;t be reached.\nSite Directory # bash sudo mkdir -p /opt/docker/wp-example cd /opt/docker/wp-example Let\u0026rsquo;s create the file /opt/docker/wp-example/.env with the content below:\n/opt/docker/wp-example/.envini DB_PASSWORD=\u0026lt;DB_PASSWORD\u0026gt; bash sudo chmod 600 .env PHP Settings # In the image\u0026rsquo;s default PHP settings the upload limit is 2 MB. This limit causes problems when uploading themes, plugins or large images; let\u0026rsquo;s add our own settings.\nLet\u0026rsquo;s create the file /opt/docker/wp-example/php.ini with the content below:\n/opt/docker/wp-example/php.iniini upload_max_filesize = 64M post_max_size = 64M memory_limit = 256M max_execution_time = 300 Compose # Let\u0026rsquo;s create /opt/docker/wp-example/compose.yaml like this:\n/opt/docker/wp-example/compose.yamlyaml services: wordpress: image: wordpress:php8.4-apache container_name: wp-example restart: unless-stopped ports: - \u0026#34;127.0.0.1:8030:80\u0026#34; environment: WORDPRESS_DB_HOST: mariadb WORDPRESS_DB_NAME: wp_example WORDPRESS_DB_USER: wp_example WORDPRESS_DB_PASSWORD: ${DB_PASSWORD} volumes: - ./html:/var/www/html - ./php.ini:/usr/local/etc/php/conf.d/custom.ini:ro networks: - default - db networks: db: external: true Why each line is there:\nwordpress:php8.4-apache: The image only provides PHP and Apache. We pin the PHP version so it doesn\u0026rsquo;t change before we check that the plugins work with it. WORDPRESS_DB_HOST: mariadb: The name of the MariaDB container; it resolves by this name on the db network. ./html:/var/www/html: The WordPress files (core, themes, plugins, uploads) are kept on the host. If the directory is empty, the image copies WordPress here on the first run. ./php.ini: Our own PHP settings. With :ro the container can only read this file. networks: default, db: Through the default network it reaches the internet (updates, plugins) and publishes its port; through the db network it reaches MariaDB. external: true: The db network is not created in this compose file; we connect to the network that MariaDB\u0026rsquo;s compose file created. So the MariaDB container must be set up first. Let\u0026rsquo;s start the container:\nbash sudo docker compose up -d sudo ls html sudo docker logs wp-example 2\u0026gt;\u0026amp;1 | tail -5 The html directory should now have files like wp-admin, wp-content and wp-config.php.\nNote The image creates wp-config.php from its own template. It reads the database details from the environment variables and generates the security keys (salts) at random. The same template looks at the X-Forwarded-Proto header coming from NGINX to understand that it runs behind HTTPS; no extra setting is needed.\nNote Apache\u0026rsquo;s remoteip module is on in the image; the logs and WordPress show the visitor\u0026rsquo;s real IP address (X-Forwarded-For).\nNote If the WordPress container comes up before MariaDB when the server restarts, it may show \u0026ldquo;Error establishing a database connection\u0026rdquo; for a few seconds; it fixes itself once MariaDB is up.\nCertificate and NGINX Reverse Proxy # Let\u0026rsquo;s get the certificate:\nbash sudo certbot certonly --webroot -w /opt/www/well_known -d example.com -d www.example.com Let\u0026rsquo;s create /etc/nginx/vhost.d/vhost_example.com.conf like this:\n/etc/nginx/vhost.d/vhost_example.com.confnginx server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name example.com www.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; client_max_body_size 64m; # Until the setup wizard is finished, remove afterwards include /etc/nginx/templates/vpn-only.tmpl; location = /xmlrpc.php { deny all; } location / { proxy_pass http://127.0.0.1:8030; include /etc/nginx/templates/proxy.tmpl; } } client_max_body_size 64m: The same as the upload limit in php.ini. The iRedMail installation sets 12m and rejects bigger uploads before they reach PHP. vpn-only.tmpl: Let\u0026rsquo;s Encrypt writes every certificate we get to the public Certificate Transparency logs. Some bots watch these logs for new domains and look for half-finished WordPress installations; whoever finishes the wizard first becomes the admin. So until the wizard is finished, the site will be reachable only over the VPN. xmlrpc.php: An old remote access API; a common target for brute force and DDoS attacks. If you\u0026rsquo;ll use Jetpack or the WordPress mobile app, remove this block. WordPress itself redirects requests for www.example.com to the site address (example.com). Let\u0026rsquo;s test the NGINX configuration and reload it:\nbash sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx Setup Wizard # Let\u0026rsquo;s connect to the VPN with the full tunnel, go to https://example.com and finish the setup wizard:\nLet\u0026rsquo;s not use admin as the admin username; it is the first username brute force attempts try. Let\u0026rsquo;s pick a strong password and save it in the password manager. Note With a split tunnel, the domain resolves to the server\u0026rsquo;s public IP, so the request doesn\u0026rsquo;t go through the VPN and gets a 403 (see 7.3 Possible Problems).\nAfter the wizard is finished, let\u0026rsquo;s delete the include /etc/nginx/templates/vpn-only.tmpl; line in the virtual host and reload NGINX:\nbash sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx Check # bash curl -I https://example.com # HTTP/2 200 In the admin panel, the Tools → Site Health page should show no critical problems.\nExtra Settings # Sending Mail # There is no mail server in the WordPress container, so PHP\u0026rsquo;s mail() function doesn\u0026rsquo;t work. Password reset, new user and contact form mails won\u0026rsquo;t go out. Let\u0026rsquo;s install an SMTP plugin (WP Mail SMTP or similar) and use our own mail server:\nSetting Value SMTP server mail.xenonly.com Port 587 (STARTTLS) User The mail account opened for the site in iRedAdmin Note The container resolves mail.xenonly.com to the server\u0026rsquo;s public IP, and the connection comes to the host over the Docker network. In Firewalld the target of the docker zone is ACCEPT, so no extra rule is needed.\nNote If the mail will be sent from an @example.com address, the domain must be added to iRedAdmin and its SPF, DKIM and DMARC records must be added in DNS (see 2.2 Adding a New Domain to the Mail Server). Or you can send from an account under xenonly.com.\nUpdates # WordPress, themes and plugins: The files are in the html directory; they are updated from the admin panel or with automatic updates. Updating the image doesn\u0026rsquo;t update WordPress. PHP and Apache: sudo docker compose pull \u0026amp;\u0026amp; sudo docker compose up -d in the site directory. Upgrading the PHP version: Changing the image tag in the compose file is enough (for example php8.4-apache → php8.5-apache). Check first that the plugins work with the new version. MariaDB: sudo docker compose pull \u0026amp;\u0026amp; sudo docker compose up -d in the MariaDB directory. The image tag is 11.4, so it stays within version 11.4. ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/wordpress/","section":"Self Hosting","summary":" Requirements 3 NGINX Configuration, 4 Docker Setup and 4.1 A Ready Template for Docker Containers must be done. For the sites to send mail, 2 Mail Server Setup must be done. To finish the setup wizard behind the VPN, 7.2 Putting Services Behind the VPN must be done. Assumptions\nThe example site is example.com, and the site’s short name is example. The short name is used in directory, container and database names; for each site, replace every example with the site’s name. A and AAAA records exist for example.com and www.example.com. The port range 8030–8049 is set aside for WordPress sites; the first site uses port 8030. Commands are run on the server with root rights (sudo). ","title":"WordPress Setup","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/vaultwarden/","section":"Tags","summary":"","title":"vaultwarden","type":"tags"},{"content":" Requirements 2 Mail Server Setup, 4.1 A Ready Template for Docker Containers, 6 Fail2Ban Configuration and 7.2 Putting Services Behind the VPN must be done. Assumptions\nVaultwarden is reached at password.xenonly.com. A and AAAA records exist for this domain. The Vaultwarden container uses port 127.0.0.1:8004. Commands are run on the server with root rights (sudo). What It Is # Vaultwarden is a light version of the Bitwarden server, written in Rust. It works with the official Bitwarden clients (browser extension, desktop, mobile). Self-hosting the official Bitwarden needs several containers, MSSQL and gigabytes of RAM; Vaultwarden runs in a single container with a few dozen MB of RAM.\nThe vault is encrypted on the client. The server never sees the master password, it only stores the encrypted data. This is also what drives the access decision below.\nDecisions Before Installing # Subdomain: I\u0026rsquo;ll use password.xenonly.com for Vaultwarden.\nPort: Vaultwarden will be served on port 8004.\nDatabase: Vaultwarden supports SQLite, MariaDB and PostgreSQL. We could use the MariaDB container we\u0026rsquo;ll set up for WordPress in 10 WordPress Setup, but for a single user SQLite is enough. All the data sits in a single data directory, it is easy to back up, and the service doesn\u0026rsquo;t depend on MariaDB.\nAccess: It will be public.\nFor autofill and sync on the phone, the server must be reachable all the time. The hosts file method we chose for the services behind the VPN can\u0026rsquo;t be done on mobile devices without root access; if Vaultwarden were reachable only over the VPN, the full tunnel would have to stay on all the time on the phone. The clients keep a copy of the vault on the device. When the server can\u0026rsquo;t be reached, the vault can still be read, but new entries don\u0026rsquo;t sync. The data is encrypted on the client, so even if the server is compromised, the vault can\u0026rsquo;t be opened without the master password. Since it will be public, we\u0026rsquo;ll close sign-ups, put the admin panel behind the VPN, turn on 2FA and add a Fail2Ban jail.\nInstallation # Mail Account # Vaultwarden sends mail for 2FA, new device notifications and invitations. Let\u0026rsquo;s create the account vaultwarden@xenonly.com in iRedAdmin.\nAdmin Token # bash sudo mkdir -p /opt/docker/vaultwarden cd /opt/docker/vaultwarden sudo docker run --rm -it vaultwarden/server /vaultwarden hash The command asks for a password twice and prints a line like ADMIN_TOKEN='$argon2id$v=19$...'. Let\u0026rsquo;s add this line as it is to the file /opt/docker/vaultwarden/.env:\n/opt/docker/vaultwarden/.envini ADMIN_TOKEN=\u0026#39;$argon2id$v=19$...\u0026#39; SMTP_PASSWORD=\u0026#39;\u0026lt;SMTP_PASSWORD\u0026gt;\u0026#39; Note \u0026lt;SMTP_PASSWORD\u0026gt;: The password of the vaultwarden@xenonly.com account.\nbash sudo chmod 600 .env Important The single quotes matter. The hash contains $ characters; without the quotes, Docker Compose reads them as variables and removes them.\nNote You log in to the admin panel with the password you entered in the command, not with the hash.\nCompose # Let\u0026rsquo;s create /opt/docker/vaultwarden/compose.yaml like this:\n/opt/docker/vaultwarden/compose.yamlyaml services: vaultwarden: image: vaultwarden/server:latest container_name: vaultwarden restart: unless-stopped ports: - \u0026#34;127.0.0.1:8004:80\u0026#34; volumes: - ./data:/data environment: DOMAIN: \u0026#34;https://password.xenonly.com\u0026#34; SIGNUPS_ALLOWED: \u0026#34;true\u0026#34; INVITATIONS_ALLOWED: \u0026#34;false\u0026#34; PASSWORD_HINTS_ALLOWED: \u0026#34;false\u0026#34; ADMIN_TOKEN: ${ADMIN_TOKEN} SMTP_HOST: mail.xenonly.com SMTP_PORT: 587 SMTP_SECURITY: starttls SMTP_FROM: vaultwarden@xenonly.com SMTP_FROM_NAME: Vaultwarden SMTP_USERNAME: vaultwarden@xenonly.com SMTP_PASSWORD: ${SMTP_PASSWORD} TZ: Europe/Istanbul Why each line is there:\nDOMAIN: The links in the mails, WebSocket and WebAuthn use this address. Write the full address, with https://. SIGNUPS_ALLOWED: \u0026quot;true\u0026quot;: Only to create the first account. After the account is created, it will be set to false. INVITATIONS_ALLOWED: \u0026quot;false\u0026quot;: When it is on, new accounts can be opened with organization invitations even if sign-ups are closed. There will be a single user, so we turn it off. PASSWORD_HINTS_ALLOWED: \u0026quot;false\u0026quot;: A password hint leaks information about the master password. SMTP_FROM and SMTP_USERNAME are the same: iRedMail rejects mail sent with a sender address different from the account that logged in. TZ: So the log times are written in local time. Note By default, Vaultwarden reads the visitor\u0026rsquo;s IP address from the X-Real-IP header; proxy.tmpl sends this header. Fail2Ban depends on this; without the header, every request looks like it comes from a 172.20.x.x address.\nLet\u0026rsquo;s start the container:\nbash sudo docker compose up -d sudo docker logs vaultwarden 2\u0026gt;\u0026amp;1 | tail -5 Careful If a setting is changed and saved in the admin panel, Vaultwarden creates the file data/config.json, and the values in this file override the environment variables in the compose file. After that, changes made in the compose file are silently ignored. So we\u0026rsquo;ll manage the settings only from the compose file; we\u0026rsquo;ll use the admin panel for user management and diagnostics, not for saving settings.\nCertificate and NGINX Reverse Proxy # Let\u0026rsquo;s get the certificate:\nbash sudo certbot certonly --webroot -w /opt/www/well_known -d password.xenonly.com Let\u0026rsquo;s create /etc/nginx/vhost.d/vhost_password.xenonly.com.conf like this:\n/etc/nginx/vhost.d/vhost_password.xenonly.com.confnginx server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name password.xenonly.com; ssl_certificate /etc/letsencrypt/live/password.xenonly.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/password.xenonly.com/privkey.pem; add_header Strict-Transport-Security \u0026#34;max-age=31536000\u0026#34; always; client_max_body_size 128m; # Until the first account is created, remove afterwards include /etc/nginx/templates/vpn-only.tmpl; location / { proxy_pass http://127.0.0.1:8004; include /etc/nginx/templates/proxy.tmpl; } location /admin { include /etc/nginx/templates/vpn-only.tmpl; proxy_pass http://127.0.0.1:8004; include /etc/nginx/templates/proxy.tmpl; } } add_header Strict-Transport-Security: Vaultwarden sends its own CSP and security headers; if the headers from headers.conf were added too, some of them would appear twice in the response. When a single add_header is defined in a virtual host, the headers in headers.conf are not inherited by that virtual host (see 3 NGINX Configuration). We add HSTS ourselves, and Vaultwarden sends the rest. client_max_body_size 128m: For file attachments and Send. The 12m iRedMail sets is not enough. WebSocket: Live sync to the other devices goes over WebSocket through /notifications/hub. Since version 1.29 no separate port is needed; the Upgrade and Connection headers in proxy.tmpl are enough. location /admin: Keeps the admin panel behind the VPN even after the vpn-only line in the server block is removed. To reach it with a split tunnel, add the entry 10.8.0.1 password.xenonly.com to the hosts file on your personal computer (see 7.3 Possible Problems). Let\u0026rsquo;s test the NGINX configuration and reload it:\nbash sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx First Account and Closing Sign-Ups # Let\u0026rsquo;s connect to the VPN with the full tunnel and create our account at https://password.xenonly.com. Let\u0026rsquo;s turn on 2FA from Settings → Security → Two-step login → Authenticator app. Let\u0026rsquo;s save the recovery code somewhere outside the server. In the compose file, let\u0026rsquo;s set SIGNUPS_ALLOWED: \u0026quot;false\u0026quot; and recreate the container with sudo docker compose up -d. In the virtual host, let\u0026rsquo;s delete the server-level include /etc/nginx/templates/vpn-only.tmpl; line and reload NGINX with sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx. Careful If the master password is forgotten, there is no way to recover it; it can\u0026rsquo;t be reset on the server side. Learn it by heart and keep it on paper in a safe place.\nClients # In the Bitwarden apps, choose Self-hosted from the region selection on the login screen and enter https://password.xenonly.com as the Server URL.\nCheck # From our personal computer, while not connected to the VPN:\nbash curl -s https://password.xenonly.com/alive # should return a timestamp curl -I https://password.xenonly.com/admin # should return 403 Over the VPN, the https://password.xenonly.com/admin/diagnostics page should show no errors in the domain, time and WebSocket checks. You can test SMTP with Send test email in the admin panel; this button doesn\u0026rsquo;t save any settings. If an entry added on one device shows up on another device within a few seconds while the vault is open on both, WebSocket works. Extra Settings # Fail2Ban # The Docker logs go to journald, so we\u0026rsquo;ll define the jail with the systemd backend.\nLet\u0026rsquo;s create the file /etc/fail2ban/filter.d/vaultwarden.local with the content below:\n/etc/fail2ban/filter.d/vaultwarden.localini [Definition] failregex = ^.*Username or password is incorrect\\. Try again\\. IP: \u0026lt;ADDR\u0026gt;\\. Username:.*$ ignoreregex = Let\u0026rsquo;s create the file /etc/fail2ban/jail.d/vaultwarden.local with the content below:\n/etc/fail2ban/jail.d/vaultwarden.localini [vaultwarden] enabled = true backend = systemd journalmatch = CONTAINER_NAME=vaultwarden filter = vaultwarden port = http,https maxretry = 5 findtime = 10m After trying to log in once with a wrong password, let\u0026rsquo;s test the filter and restart the service:\nbash sudo fail2ban-regex \u0026#34;systemd-journal[journalmatch=\u0026#39;CONTAINER_NAME=vaultwarden\u0026#39;]\u0026#34; vaultwarden sudo systemctl restart fail2ban sudo fail2ban-client status vaultwarden Note The ban works because NGINX runs on the host; the request comes to port 443 on the host. If the container port were open to the internet directly, the traffic would go through Docker\u0026rsquo;s FORWARD chain and the ban rules on the host wouldn\u0026rsquo;t catch it.\nNote I didn\u0026rsquo;t add a jail for the admin panel; the panel is behind the VPN, and the VPN network is already in ignoreip.\nTip If you get a backend error, install the package for journald support with sudo dnf install fail2ban-systemd.\nBackup # Everything that needs a backup is under /opt/docker/vaultwarden/data:\nFile Note db.sqlite3 A plain copy while the service is running can give an inconsistent backup; take it with .backup attachments/, sends/ File attachments and Send files config.json If it exists rsa_key.pem Signs the sessions. If it is lost, all devices are logged out; no data is lost bash sudo dnf install sqlite sudo sqlite3 /opt/docker/vaultwarden/data/db.sqlite3 \u0026#34;.backup \u0026#39;\u0026lt;BACKUP_DIR\u0026gt;/db-$(date +%F).sqlite3\u0026#39;\u0026#34; Note The vault data is encrypted with the master password; when you restore from a backup, you need the master password too.\nTip For the worst case, take an export from the web vault now and then with Tools → Export → Encrypted JSON and keep it outside the server.\nUpdates # bash cd /opt/docker/vaultwarden \u0026amp;\u0026amp; sudo docker compose pull \u0026amp;\u0026amp; sudo docker compose up -d Bitwarden clients update themselves, and an old Vaultwarden version can have problems with new clients. So keeping Vaultwarden up to date matters more than for the other services; it should be one of the first services to get automatic updates.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/vaultwarden/","section":"Self Hosting","summary":" Requirements 2 Mail Server Setup, 4.1 A Ready Template for Docker Containers, 6 Fail2Ban Configuration and 7.2 Putting Services Behind the VPN must be done. Assumptions\nVaultwarden is reached at password.xenonly.com. A and AAAA records exist for this domain. The Vaultwarden container uses port 127.0.0.1:8004. Commands are run on the server with root rights (sudo). ","title":"Vaultwarden Setup","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/nginx/","section":"Tags","summary":"","title":"nginx","type":"tags"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/vault/","section":"Tags","summary":"","title":"vault","type":"tags"},{"content":" Requirements 3 NGINX Configuration and 7.2 Putting Services Behind the VPN must be done (the vpn-only template is used). Assumptions\nVault is reached at vault.xenonly.com, only over the VPN. A and AAAA records exist for this domain. The install commands are run on the server with root rights (sudo). The vault CLI commands are run on the server as the normal user. What It Is # Vault is a service that keeps secrets (passwords, API keys, certificates, tokens) in one central, encrypted place, controls who can reach what, and records every access. It is not just an \u0026ldquo;encrypted safe\u0026rdquo;; it can create many secrets itself and revoke them itself when they expire.\nInstallation # Let\u0026rsquo;s add the HashiCorp repository and install Vault with the commands below:\nbash sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo sudo dnf install vault Storage Method # We\u0026rsquo;ll edit the configuration before starting the service. Vault has two options for storing data:\nFile: The default after installation. Vault writes its data as encrypted files straight to a directory on disk (/opt/vault/data). The simplest method to set up and configure. It works only on a single server and doesn\u0026rsquo;t support high availability (HA). Raft (Integrated Storage): The distributed storage that comes built into Vault. The data is again kept encrypted on disk. You can build a cluster with several servers, and it gives HA. You can take a backup with vault operator raft snapshot save while Vault is running. It needs a bit more configuration (api_addr, cluster_addr, port 8201). If the server address changes, you may need to recover it by hand. This setup is for a single server and personal use, so I\u0026rsquo;ll install it with the File method.\nConfiguration # In /etc/vault.d/vault.hcl, let\u0026rsquo;s comment out the HTTPS listener section and uncomment the HTTP listener section. That part should look like this:\n/etc/vault.d/vault.hclhcl # HTTP listener listener \u0026#34;tcp\u0026#34; { address = \u0026#34;127.0.0.1:8200\u0026#34; tls_disable = 1 x_forwarded_for_authorized_addrs = \u0026#34;127.0.0.1\u0026#34; x_forwarded_for_reject_not_present = false } # HTTPS listener #listener \u0026#34;tcp\u0026#34; { # address = \u0026#34;0.0.0.0:8200\u0026#34; # tls_cert_file = \u0026#34;/opt/vault/tls/tls.crt\u0026#34; # tls_key_file = \u0026#34;/opt/vault/tls/tls.key\u0026#34; #} Note Vault listens only on 127.0.0.1 and will be opened to the outside through NGINX. NGINX provides HTTPS, so inside the server Vault doesn\u0026rsquo;t need to use HTTPS too.\nNote The x_forwarded_for_* settings let Vault take the client\u0026rsquo;s real IP address from the X-Forwarded-For header NGINX sends; the audit logs show the client\u0026rsquo;s address instead of NGINX\u0026rsquo;s.\nLet\u0026rsquo;s fix the directory ownership and the permissions of the configuration file:\nbash sudo chown -R vault:vault /opt/vault sudo chmod 640 /etc/vault.d/vault.hcl Let\u0026rsquo;s enable and start the service:\nbash sudo systemctl enable --now vault sudo systemctl status vault To use Vault from the CLI, let\u0026rsquo;s set Vault\u0026rsquo;s address in our normal user\u0026rsquo;s shell:\nbash echo \u0026#39;export VAULT_ADDR=http://127.0.0.1:8200\u0026#39; \u0026gt;\u0026gt; ~/.bashrc \u0026amp;\u0026amp; source ~/.bashrc vault -autocomplete-install vault status Initialize and Unseal # bash vault operator init -key-shares=1 -key-threshold=1 -key-shares: The number of unseal keys to create. -key-threshold: The number of unseal keys needed to open Vault. Note This is for personal use, so I chose 1 and 1, but in production values like 5 and 3 make more sense.\nThe output of this command has the unseal key and the root token, and it is shown only once. Keep the unseal key and the root token somewhere safe, outside the server.\nNote When the system or the service restarts, Vault starts sealed (locked), and we need to unseal it by hand by entering the keys with vault operator unseal. There are ways to automate this, but that makes sealing pointless. So I\u0026rsquo;ll do this by hand when needed and try not to make the services that run all the time depend on Vault.\nWe can open Vault by entering the unseal key with the command below:\nbash vault operator unseal NGINX Reverse Proxy # Vault is not open to the outside right now; to reach it we\u0026rsquo;ll use NGINX.\nLet\u0026rsquo;s get the certificate:\nbash sudo certbot certonly --webroot -w /opt/www/well_known -d vault.xenonly.com Let\u0026rsquo;s create /etc/nginx/vhost.d/vhost_vault.xenonly.com.conf like this:\n/etc/nginx/vhost.d/vhost_vault.xenonly.com.confnginx server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name vault.xenonly.com; ssl_certificate /etc/letsencrypt/live/vault.xenonly.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/vault.xenonly.com/privkey.pem; include /etc/nginx/templates/vpn-only.tmpl; location / { proxy_pass http://127.0.0.1:8200; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } } Let\u0026rsquo;s test the NGINX configuration and reload it:\nbash sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx The Vault UI can now be used at https://vault.xenonly.com.\nNote Because the vpn-only template is used, Vault can be reached only with a VPN connection. To reach it with a split tunnel, add the entry 10.8.0.1 vault.xenonly.com to the hosts file on your personal computer (see 7.3 Possible Problems).\nUsing the CLI from the Desktop # We need to install Vault on our personal computer, in a version close to the one on the server. Then adding the line below to the configuration of the shell we use (bash, zsh, fish) is enough:\nbash export VAULT_ADDR=https://vault.xenonly.com First Configuration After the Installation # We unseal Vault and log in with the vault login command, entering the root token.\nSecrets Engine # Let\u0026rsquo;s list the current secrets engines:\nbash vault secrets list Path Type Accessor Description ---- ---- -------- ----------- agent-registry/ agent_registry agent-registry_4d63d95d agent registry cubbyhole/ cubbyhole cubbyhole_76e2bfaf per-token private secret storage identity/ identity identity_331ce865 identity store sys/ system system_5d30d32d system endpoints used for control, policy and debugging If the list has no engine of type kv, let\u0026rsquo;s mount a secrets engine of type kv-v2 with the command below:\nbash vault secrets enable -path=secret kv-v2 kv-v2: A secrets engine that keeps key-value data. The data is permanent; it stays there until it is deleted. cubbyhole: The private area of each token. When the token expires, this area is deleted too. -path=secret: The name of the mount point; you can give it any value. Logging # With the command below we send the audit logs to the service\u0026rsquo;s standard output, so to journald:\nbash vault audit enable file file_path=stdout Admin Policy and User # To use instead of the root token, let\u0026rsquo;s create a policy and a user with admin rights:\nbash vault policy write admin - \u0026lt;\u0026lt;\u0026#39;EOF\u0026#39; path \u0026#34;*\u0026#34; { capabilities = [\u0026#34;create\u0026#34;, \u0026#34;read\u0026#34;, \u0026#34;update\u0026#34;, \u0026#34;patch\u0026#34;, \u0026#34;delete\u0026#34;, \u0026#34;list\u0026#34;, \u0026#34;sudo\u0026#34;] } EOF vault auth enable userpass read -rs PW vault write auth/userpass/users/\u0026lt;USERNAME\u0026gt; password=\u0026#34;$PW\u0026#34; policies=admin token_ttl=8h token_max_ttl=24h unset PW Note read -rs: Reads the password without showing it on the screen, and the password is not written to the command history.\nNote In practice this policy gives the same rights as root. The difference: the token is valid for at most 24 hours, it can be revoked, and the actions show up in the audit log with our own username.\nLet\u0026rsquo;s check that we can log in with the new user:\nbash vault login -method=userpass username=\u0026lt;USERNAME\u0026gt; vault token lookup # policies: [admin default], ttl: ~8h Tip You can also log in from the UI by choosing userpass as the login method.\nIf the new user works, let\u0026rsquo;s revoke the root token:\nbash vault token revoke \u0026lt;ROOT_TOKEN\u0026gt; Note The CLI and policies are worth reading about on your own; I won\u0026rsquo;t go into them here.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/vault/","section":"Self Hosting","summary":" Requirements 3 NGINX Configuration and 7.2 Putting Services Behind the VPN must be done (the vpn-only template is used). Assumptions\nVault is reached at vault.xenonly.com, only over the VPN. A and AAAA records exist for this domain. The install commands are run on the server with root rights (sudo). The vault CLI commands are run on the server as the normal user. ","title":"Vault Setup","type":"self-hosting"},{"content":" Requirements 7.1 Adding WireGuard Clients and 7.2 Putting Services Behind the VPN must be done. Assumptions\nThe desktop has the two profiles created in 7.1 Adding WireGuard Clients: xenternet (full tunnel) and xentranet (split tunnel). The commands in this part are run on the Linux desktop (the client) that uses NetworkManager. Access Problem with a Split Tunnel # We can set up the VPN connection in two ways. If we set AllowedIPs in the client configuration to:\nAllowedIPs = 0.0.0.0/0, ::/0 (full tunnel), all traffic goes through the VPN. AllowedIPs = 10.8.0.0/24, fd42:8::/64 (split tunnel), only the traffic for the VPN network goes through the VPN. We can use either one, depending on what we need. But here a problem shows up:\nIf our connection is a full tunnel and we try to reach a service that is reachable only from the VPN network (for example the iRedAdmin panel), all traffic, the DNS query included, goes through the VPN when we enter iRedAdmin\u0026rsquo;s domain, and we can reach the service.\nIf our connection is a split tunnel and we try to reach iRedAdmin:\nOur DNS query goes over the public internet, and we try to connect to the server\u0026rsquo;s public IP address. Our connection goes over the public internet, so the server sees the request as coming from outside the VPN network and rejects it. To fix this, the DNS query must return the server\u0026rsquo;s IP address on the VPN network (10.8.0.1) instead of its public IP. We can solve this problem in these ways:\nVPN IP at the DNS provider: We set the A record of the domains we\u0026rsquo;ll reach only over the VPN to 10.8.0.1 instead of the server\u0026rsquo;s public IP. Wherever the DNS query comes from, it returns 10.8.0.1, and if there is a VPN connection, the service can be reached.\nBut Let\u0026rsquo;s Encrypt can\u0026rsquo;t reach this address during its check, so a certificate can\u0026rsquo;t be issued with the HTTP-01 (webroot) method; a DNS-01 check is needed. Not a great method just to reach a simple service. The hosts file: We add the record to the hosts file on the client computer ourselves. The public DNS record stays only so we can get certificates, and NGINX handles the access restriction. For personal use, the services behind the VPN will be few and for specific needs (for example connecting to SSH and the iRedAdmin panel now and then, only over the VPN), so this one-time effort is not much of a problem.\nThe downside: on mobile devices it can\u0026rsquo;t be done without root access. A DNS service on the server: We install a light DNS service on the server and put its address in the DNS value of the VPN client configuration. For queries about the services behind the VPN, the DNS service on the server returns the server\u0026rsquo;s VPN address, and it asks a public DNS server for everything else.\nThis method can add a small delay to DNS queries. I plan to reach the services I put behind the VPN only from my own computer, and it is simpler than the others, so I\u0026rsquo;ll use method 2, adding a record to the hosts file:\nbash echo \u0026#34;10.8.0.1 iredadmin.xenonly.com\u0026#34; | sudo tee -a /etc/hosts Access Problem with Both Profiles On # When It Happens # If we want the split tunnel profile (xentranet) to stay on all the time so we can always reach the 10.8.0.0/24 network, and turn the full tunnel profile (xenternet) on and off only when needed, both profiles stay connected at the same time. In this case our access to 10.8.0.0/24 stops and we can\u0026rsquo;t reach the services behind the VPN.\nWith both profiles connected at the same time, the internet works, but ping to 10.8.0.1, SSH and the services reachable only from the VPN don\u0026rsquo;t work. With only one profile connected, there is no problem.\nWhy It Happens # Every packet that goes through WireGuard has two layers:\nInner packet: 10.8.0.3 → 10.8.0.1 (the packet we send) Outer packet: home IP → SERVER IP:51820 UDP (the inner packet, encrypted) The kernel makes a separate routing decision for each of these two packets:\nWith a full tunnel, NetworkManager puts the default route in a separate routing table and adds a rule: \u0026ldquo;every packet without a mark (fwmark) goes to this table\u0026rdquo;. The full tunnel marks its own packets, so they don\u0026rsquo;t go back into the tunnel. The inner packet takes the right path. The kernel looks at the main table first (except for the default route). The 10.8.0.0/24 route of xentranet is in the main table, so the ping goes into xentranet. The outer packet of xentranet has no mark, so it matches the rule of xenternet and goes into the xenternet tunnel. The server receives this packet through wg0 and checks it against the rules of the VPN zone. In our current firewall configuration the wireguard service is not allowed in the VPN zone, so the packet is rejected and the handshake of xentranet never completes. WireGuard has no idea of a connection state, so the kernel doesn\u0026rsquo;t know that the tunnel isn\u0026rsquo;t working. The most specific route for 10.8.0.0/24 is still xentranet, so access to the server stops. With only one profile connected, the outer packet of xentranet goes over the normal internet and reaches the server through the public zone. wireguard is allowed in the public zone, so there is no problem.\nA check with both profiles connected:\nbash ip route get \u0026lt;SERVER_IPV4\u0026gt; # if it says \u0026#34;dev xenternet\u0026#34;, xentranet\u0026#39;s outer packets go into the tunnel Ways to Fix It # Method What It Does Effect Switching between profiles Only one profile is on at a time. The full tunnel covers 10.8.0.0/24 too The simplest method. Open connections drop while switching Allowing wireguard in the VPN zone The packet of xentranet reaches the server inside the xenternet tunnel The packet is encrypted and decrypted twice. The MTU of xentranet must be lowered. Not recommended Priority with metric While xenternet is on, 10.8.0.0/24 traffic always goes through xenternet The firewall is not touched. When xenternet comes up, connections opened through xentranet drop, because the server doesn\u0026rsquo;t accept xentranet\u0026rsquo;s IP from the xenternet peer fwmark (chosen) The outer packets of xentranet are marked too, so they go over the normal internet The packet is encrypted only once, connections don\u0026rsquo;t drop, and xenternet can be turned on and off on its own Steps: fwmark # fwmark A number the kernel puts on a packet. It lives only in the computer\u0026rsquo;s memory, it never goes out on the network and it has nothing to do with ports. 51820 is a habit that comes from wg-quick; it can be any number. NetworkManager also uses this number as the routing table number of the full tunnel.\nLet\u0026rsquo;s give both profiles the same fwmark value. Then the rule of xenternet becomes \u0026ldquo;packets whose mark is not 51820\u0026rdquo;, and the packets of xentranet don\u0026rsquo;t match it.\nbash nmcli con modify xenternet wireguard.fwmark 51820 nmcli con modify xentranet wireguard.fwmark 51820 nmcli con modify xentranet connection.autoconnect yes nmcli con up xentranet nmcli con up xenternet A check with both profiles connected:\nbash ip route get 10.8.0.1 # dev xentranet ip route get \u0026lt;SERVER_IPV4\u0026gt; mark 51820 # the normal network interface (wlan0 / eth0), not xenternet sudo wg show xentranet # fwmark: 0xca6c, latest handshake is recent Test: let\u0026rsquo;s open an SSH session to the server through xentranet and turn xenternet on and off a few times. The session should not drop.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/wireguard-troubleshooting/","section":"Self Hosting","summary":" Requirements 7.1 Adding WireGuard Clients and 7.2 Putting Services Behind the VPN must be done. Assumptions\nThe desktop has the two profiles created in 7.1 Adding WireGuard Clients: xenternet (full tunnel) and xentranet (split tunnel). The commands in this part are run on the Linux desktop (the client) that uses NetworkManager. ","title":"WireGuard: Possible Problems","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/vpn/","section":"Tags","summary":"","title":"vpn","type":"tags"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/wireguard/","section":"Tags","summary":"","title":"wireguard","type":"tags"},{"content":" Requirements 7 WireGuard Setup and 7.1 Adding WireGuard Clients must be done; you must be able to connect to the VPN from your personal computer. For the NGINX part, 3 NGINX Configuration must be done. Assumptions\nThe VPN networks are 10.8.0.0/24 and fd42:8::/64, and the server\u0026rsquo;s VPN address is 10.8.0.1. SSH is allowed in the vpn zone (7 WireGuard Setup). Server commands are run on the server with root rights (sudo). The tests with ssh and curl are done from a personal computer. We\u0026rsquo;ll make the services on the server that only we want to reach (the iRedAdmin panel, vault, SSH and so on) reachable only while there is a VPN connection.\nRoughly, what we need to do is allow, in the configuration of each service, only the requests that come from these addresses:\n10.8.0.0/24 (IPv4) and fd42:8::/64 (IPv6) Reaching SSH Only Over the VPN # What we need to do is remove SSH from the public zone in the firewall; it is already allowed in the VPN zone.\nChecks Before We Start # Firewalld # bash sudo firewall-cmd --zone=vpn --list-all With this command, let\u0026rsquo;s make sure SSH is in the VPN zone.\nWarning Also make sure root or the normal user has a password, and that you know it. If something goes wrong with the VPN, the only way into the server will be the VNC console of the provider, and you\u0026rsquo;ll need to log in there with a username and password.\nVPN Connection # Let\u0026rsquo;s connect to the VPN (split or full tunnel) from our personal computer and make sure we can open an SSH connection over the VPN with the command below:\nbash ssh \u0026lt;USER\u0026gt;@10.8.0.1 Rescue Timer and a Temporary (Runtime) Change # In case something goes wrong and we can\u0026rsquo;t open an SSH connection, let\u0026rsquo;s set up a timer that undoes the change:\nbash sudo systemd-run --on-active=10min --unit=ssh-rescue firewall-cmd --reload We won\u0026rsquo;t use --permanent for the changes we make in Firewalld, so if we don\u0026rsquo;t cancel the timer, it runs after 10 minutes, reloads Firewalld and loads the permanent (old) settings again.\nSteps # Let\u0026rsquo;s remove the SSH service from the public zone with the command below:\nbash sudo firewall-cmd --zone=public --remove-service=ssh Checking # From our personal computer, with the split tunnel profile connected, let\u0026rsquo;s test:\nbash ssh \u0026lt;USER\u0026gt;@10.8.0.1 # should connect, goes through the VPN ssh -o ConnectTimeout=5 \u0026lt;USER\u0026gt;@\u0026lt;SERVER_IPV4\u0026gt; # over the internet, should not connect ssh -o ConnectTimeout=5 \u0026lt;USER\u0026gt;@\u0026lt;SERVER_IPV6\u0026gt; # IPv6, should not connect Warning If you do this test with the full tunnel connected, the result is misleading: the traffic to the server\u0026rsquo;s public IP also goes through the tunnel and comes in through wg0, so the VPN zone\u0026rsquo;s rules apply and the connection works.\nMaking It Permanent # If there is no problem, let\u0026rsquo;s make the change permanent with the commands below before the 10 minutes are up:\nbash sudo firewall-cmd --permanent --zone=public --remove-service=ssh sudo systemctl stop ssh-rescue.timer sudo firewall-cmd --reload bash sudo firewall-cmd --zone=public --list-services # ssh should not be in the list Editing the SSH Configuration # We\u0026rsquo;ll always connect to SSH over the VPN, and the server\u0026rsquo;s IP address on the VPN network doesn\u0026rsquo;t change, so for convenience we can edit the ~/.ssh/config file on our personal computer like this:\n~/.ssh/configssh-config Host \u0026lt;SERVER_NAME\u0026gt; HostName 10.8.0.1 User \u0026lt;USER\u0026gt; IdentityFile ~/.ssh/\u0026lt;SSH_KEY\u0026gt; IdentitiesOnly yes Note The reason we write 10.8.0.1 instead of the domain as the HostName is the split tunnel: the domain resolves to the server\u0026rsquo;s public IP, so the traffic goes over the internet, and since SSH is closed in the public zone, the connection fails. With the full tunnel this problem doesn\u0026rsquo;t happen.\nNote We could also set sshd to listen only on 10.8.0.1 with ListenAddress. But the firewall already blocks connections from outside, and that would make the SSH service depend on WireGuard, so I didn\u0026rsquo;t see the need. The only risk we accept with this choice is that SSH becomes open to the internet if the firewall goes down.\nPutting NGINX Virtual Hosts Behind the VPN # Web services like iRedAdmin already run behind NGINX. So we\u0026rsquo;ll put a restriction in the NGINX configuration only for the services we want to reach over the VPN.\nThe /etc/nginx/templates directory already has the templates we use. Let\u0026rsquo;s add the template /etc/nginx/templates/vpn-only.tmpl to them with the content below:\n/etc/nginx/templates/vpn-only.tmplnginx allow 10.8.0.0/24; allow fd42:8::/64; deny all; From now on, all we need to do is add the line include /etc/nginx/templates/vpn-only.tmpl; to the server block of the virtual hosts we want to reach only over the VPN.\nPutting the iRedAdmin Panel Behind the VPN # Let\u0026rsquo;s open /etc/nginx/vhost.d/vhost_iredadmin.xenonly.com.conf and include the vpn-only template in the server block. The file will look like this:\n/etc/nginx/vhost.d/vhost_iredadmin.xenonly.com.confnginx server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name iredadmin.xenonly.com; ssl_certificate /etc/letsencrypt/live/iredadmin.xenonly.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/iredadmin.xenonly.com/privkey.pem; include /etc/nginx/templates/vpn-only.tmpl; include /etc/nginx/templates/misc.tmpl; include /etc/nginx/templates/iredadmin-subdomain.tmpl; } Let\u0026rsquo;s test the NGINX configuration and reload it:\nbash sudo nginx -t \u0026amp;\u0026amp; sudo systemctl reload nginx Checking # From our personal computer, while not connected to the VPN:\nbash curl -sI https://iredadmin.xenonly.com | head -1 # HTTP/2 403 While connected to the VPN (with the full tunnel, or with the split tunnel and the hosts entry from 7.3 Possible Problems), the same command should return something other than 403 (for example 200 or a redirect).\nNGINX Location Inheritance # Note It doesn\u0026rsquo;t matter in which part of the server block the vpn-only template is added.\nThe point to watch here is how NGINX location blocks behave.\nIn NGINX, settings are defined in nested blocks: http → server → location. A child block inherits the settings of its parent block. But there is a rule:\nImportant If a child block defines even one directive of a kind, all the directives of that kind from the parent block stop working for that child block.\nBy adding the vpn-only template to the server block, we allow requests from the VPN network and reject the rest. But if a separate location block (maybe one that comes from an include) has an allow or deny rule, our rules don\u0026rsquo;t work for that location.\nAlso, the return and rewrite directives run at a stage of request processing that comes before access control (allow/deny). A location that answers with return (or redirects with rewrite) sends its response without ever reaching the deny rule.\nSo let\u0026rsquo;s check our current configuration:\nbash sudo grep -RnE \u0026#39;allow|deny|return|rewrite\u0026#39; /etc/nginx roundcube-subdomain.tmpl has deny all for many locations; this doesn\u0026rsquo;t cause a problem. The return 301 in 00-default.conf only redirects HTTP requests on port 80 to HTTPS; the restriction applies when the real request reaches the virtual host on port 443. The allow all directives in misc.tmpl and 00-default.conf are in the .well-known location. They override our rule, but that is what we want: the .well-known directory holds the temporary files Let\u0026rsquo;s Encrypt creates while it checks the certificate. Note Certificate renewal is not affected by this restriction: the Let\u0026rsquo;s Encrypt check is done through 00-default.conf on port 80, and there is no VPN restriction there.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/services-behind-vpn/","section":"Self Hosting","summary":" Requirements 7 WireGuard Setup and 7.1 Adding WireGuard Clients must be done; you must be able to connect to the VPN from your personal computer. For the NGINX part, 3 NGINX Configuration must be done. Assumptions\nThe VPN networks are 10.8.0.0/24 and fd42:8::/64, and the server’s VPN address is 10.8.0.1. SSH is allowed in the vpn zone (7 WireGuard Setup). Server commands are run on the server with root rights (sudo). The tests with ssh and curl are done from a personal computer. ","title":"Putting Services Behind the VPN","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/ssh/","section":"Tags","summary":"","title":"ssh","type":"tags"},{"content":" Requirements 7 WireGuard Setup must be done. Assumptions\nThe server\u0026rsquo;s VPN address is 10.8.0.1; clients connect to the VPN through xenonly.com:51820. Server-side commands are run on the server, client-side commands on a Linux desktop that uses NetworkManager. Commands that need root rights are written with sudo. The desktop uses two VPN profiles: xenternet (full tunnel), which sends all traffic through the tunnel, and xentranet (split tunnel), which sends only the traffic for the VPN network through the tunnel. Adding a Client # These are the steps for adding a client to WireGuard:\nCreating a key pair for the client Preparing the client configuration Adding the client to wg0.conf with a [Peer] block Applying the change to the interface We\u0026rsquo;ll do these steps by hand first, then automate them with a script.\nAdding by Hand # In the steps below we\u0026rsquo;ll add a client named desktop.\n1. Creating the Key Pair # On the server, as the normal user, we create a private key, a public key and a preshared key for the client in our home directory:\nbash ( umask 077 wg genkey | tee desktop.key | wg pubkey \u0026gt; desktop.pub wg genpsk \u0026gt; desktop.psk ) Note The commands run in a subshell inside the parentheses. So umask 077 applies only to these files and doesn\u0026rsquo;t affect the rest of the session.\nThe client configuration will also need the server\u0026rsquo;s public key:\nbash sudo wg show wg0 public-key 2. Preparing the Client Configuration # Example client configuration:\ndesktop.confini [Interface] PrivateKey = \u0026lt;desktop.key\u0026gt; Address = 10.8.0.2/32, fd42:8::2/128 DNS = 1.1.1.1, 2606:4700:4700::1111 [Peer] PublicKey = \u0026lt;server.pub\u0026gt; PresharedKey = \u0026lt;desktop.psk\u0026gt; Endpoint = \u0026lt;SERVER_DOMAIN\u0026gt;:51820 AllowedIPs = 0.0.0.0/0, ::/0 PersistentKeepalive = 25 Address: The IP address the client gets. DNS: The DNS server the client will use. If it is left empty, the client\u0026rsquo;s default DNS is used. PersistentKeepalive: Sends a packet every 25 seconds so the connection doesn\u0026rsquo;t drop. AllowedIPs: 0.0.0.0/0, ::/0 sends all internet traffic through the VPN (full tunnel). With 10.8.0.0/24, fd42:8::/64, only the traffic to the server and to the other devices on the VPN uses the VPN (split tunnel). We write the contents of the matching files into the places marked with \u0026lt;...\u0026gt; and save the configuration as desktop.conf.\n3. Adding It to wg0.conf # We add the client to the end of /etc/wireguard/wg0.conf:\n/etc/wireguard/wg0.confini # peer: desktop [Peer] PublicKey = \u0026lt;desktop.pub\u0026gt; PresharedKey = \u0026lt;desktop.psk\u0026gt; AllowedIPs = 10.8.0.2/32, fd42:8::2/128 Important The # peer: desktop line is the marker the script below uses to find the peers. We add this line so that peers added by hand can be managed with the script too.\nWarning Leave an empty line before and after every peer block. When the script removes a peer, it deletes everything from the marker line to the next empty line; if there is no empty line, the peer below gets deleted too.\n4. Applying the Change # bash sudo bash -c \u0026#39;wg syncconf wg0 \u0026lt;(wg-quick strip wg0)\u0026#39; syncconf applies the change to the live interface without dropping the current connections.\nIf a mobile client will be used, we can print the configuration as a QR code:\nbash qrencode -t ansiutf8 \u0026lt; desktop.conf After the configuration has been moved to the client, we delete the key files and the configuration from the server:\nbash rm desktop.key desktop.pub desktop.psk desktop.conf Automating It # Instead of doing this by hand every time, we\u0026rsquo;ll automate it. Let\u0026rsquo;s create the script below on the server at /usr/local/sbin/wg-peer, and then set its permissions.\nImportant Before saving the script, change the ENDPOINT value in it to your own server\u0026rsquo;s address.\n/usr/local/sbin/wg-peerbash #!/usr/bin/env bash # wg-peer: WireGuard client management # wg-peer add \u0026lt;name\u0026gt; create a new client (full tunnel), print its config as text and QR code # wg-peer add \u0026lt;name\u0026gt; --local same, but the client routes only the VPN network and keeps its own DNS (split tunnel) # wg-peer remove \u0026lt;name\u0026gt; remove a client # wg-peer list list clients and their latest handshake set -euo pipefail IFACE=\u0026#34;wg0\u0026#34; CONF=\u0026#34;/etc/wireguard/${IFACE}.conf\u0026#34; ENDPOINT=\u0026#34;xenonly.com:51820\u0026#34; NET4=\u0026#34;10.8.0.\u0026#34; # clients: 10.8.0.2 - 10.8.0.254 NET6=\u0026#34;fd42:8::\u0026#34; # clients: fd42:8::2 - fd42:8::254 DNS=\u0026#34;1.1.1.1, 2606:4700:4700::1111\u0026#34; FULL_ALLOWED=\u0026#34;0.0.0.0/0, ::/0\u0026#34; # full tunnel: all traffic goes through the VPN LOCAL_ALLOWED=\u0026#34;${NET4}0/24, ${NET6}/64\u0026#34; # split tunnel (--local): only the VPN network # Print an error message and exit die() { echo \u0026#34;Error: $*\u0026#34; \u0026gt;\u0026amp;2; exit 1; } [[ $EUID -eq 0 ]] || die \u0026#34;must be run as root\u0026#34; umask 077 # Apply wg0.conf to the live interface without dropping connections, # restore the backup if it fails apply() { if ! wg syncconf \u0026#34;$IFACE\u0026#34; \u0026lt;(wg-quick strip \u0026#34;$IFACE\u0026#34;); then cp -p \u0026#34;$CONF.bak\u0026#34; \u0026#34;$CONF\u0026#34; wg syncconf \u0026#34;$IFACE\u0026#34; \u0026lt;(wg-quick strip \u0026#34;$IFACE\u0026#34;) die \u0026#34;failed to apply config, backup restored\u0026#34; fi } # Check whether a peer with the given name exists peer_exists() { grep -qxF \u0026#34;# peer: $1\u0026#34; \u0026#34;$CONF\u0026#34;; } # Create a peer: pick the first free IP, generate keys, append it to wg0.conf, # then print the client config (the private key is never written to disk). # $2 is the client\u0026#39;s AllowedIPs: FULL_ALLOWED or LOCAL_ALLOWED. # The DNS line is added only for the full tunnel. cmd_add() { local name=$1 allowed=$2 n ip=\u0026#34;\u0026#34; priv pub psk server_pub client dns=\u0026#34;\u0026#34; [[ $allowed == \u0026#34;$FULL_ALLOWED\u0026#34; ]] \u0026amp;\u0026amp; dns=\u0026#34;DNS = $DNS\u0026#34;$\u0026#39;\\n\u0026#39; [[ $name =~ ^[a-z0-9-]{1,15}$ ]] || die \u0026#34;name may contain only lowercase letters, digits and \u0026#39;-\u0026#39; (max 15 chars)\u0026#34; peer_exists \u0026#34;$name\u0026#34; \u0026amp;\u0026amp; die \u0026#34;\u0026#39;$name\u0026#39; already exists\u0026#34; for n in $(seq 2 254); do grep -qF \u0026#34;${NET4}${n}/32\u0026#34; \u0026#34;$CONF\u0026#34; || { ip=$n; break; } done [[ -n $ip ]] || die \u0026#34;no free IP left\u0026#34; server_pub=$(wg show \u0026#34;$IFACE\u0026#34; public-key) priv=$(wg genkey) pub=$(wg pubkey \u0026lt;\u0026lt;\u0026lt; \u0026#34;$priv\u0026#34;) psk=$(wg genpsk) cp -p \u0026#34;$CONF\u0026#34; \u0026#34;$CONF.bak\u0026#34; cat \u0026gt;\u0026gt; \u0026#34;$CONF\u0026#34; \u0026lt;\u0026lt;EOF # peer: $name [Peer] PublicKey = $pub PresharedKey = $psk AllowedIPs = ${NET4}${ip}/32, ${NET6}${ip}/128 EOF apply client=$(cat \u0026lt;\u0026lt;EOF [Interface] PrivateKey = $priv Address = ${NET4}${ip}/32, ${NET6}${ip}/128 ${dns} [Peer] PublicKey = $server_pub PresharedKey = $psk Endpoint = $ENDPOINT AllowedIPs = $allowed PersistentKeepalive = 25 EOF ) echo \u0026#34;=== $name ${NET4}${ip} ${NET6}${ip} AllowedIPs: $allowed ===\u0026#34; echo echo \u0026#34;$client\u0026#34; echo qrencode -t ansiutf8 \u0026lt;\u0026lt;\u0026lt; \u0026#34;$client\u0026#34; echo echo \u0026#34;This config is shown only once, the client\u0026#39;s private key is not stored on the server.\u0026#34; } # Remove a peer: drop its block (from the marker line to the next blank line) # from wg0.conf and apply cmd_remove() { local name=$1 peer_exists \u0026#34;$name\u0026#34; || die \u0026#34;\u0026#39;$name\u0026#39; not found\u0026#34; cp -p \u0026#34;$CONF\u0026#34; \u0026#34;$CONF.bak\u0026#34; awk -v m=\u0026#34;# peer: $name\u0026#34; \u0026#39; $0 == m { skip = 1; next } skip \u0026amp;\u0026amp; NF { next } skip { skip = 0; next } { print } \u0026#39; \u0026#34;$CONF.bak\u0026#34; \u0026gt; \u0026#34;$CONF\u0026#34; apply echo \u0026#34;\u0026#39;$name\u0026#39; removed.\u0026#34; } # List peers with their IP and latest handshake time cmd_list() { local handshakes name pub ip ts last handshakes=$(wg show \u0026#34;$IFACE\u0026#34; latest-handshakes) printf \u0026#39;%-15s %-12s %s\\n\u0026#39; \u0026#34;NAME\u0026#34; \u0026#34;IP\u0026#34; \u0026#34;LATEST HANDSHAKE\u0026#34; awk \u0026#39; /^# peer: / { name = substr($0, 9) } /^PublicKey/ \u0026amp;\u0026amp; name { pub = $3 } /^AllowedIPs/ \u0026amp;\u0026amp; name { split($3, a, \u0026#34;,\u0026#34;); sub(\u0026#34;/32\u0026#34;, \u0026#34;\u0026#34;, a[1]); print name, pub, a[1]; name = \u0026#34;\u0026#34; } \u0026#39; \u0026#34;$CONF\u0026#34; | while read -r name pub ip; do ts=$(awk -v k=\u0026#34;$pub\u0026#34; \u0026#39;$1 == k { print $2 }\u0026#39; \u0026lt;\u0026lt;\u0026lt; \u0026#34;$handshakes\u0026#34;) if [[ -z $ts || $ts == 0 ]]; then last=\u0026#34;-\u0026#34; else last=$(date -d \u0026#34;@$ts\u0026#34; \u0026#39;+%F %T\u0026#39;) fi printf \u0026#39;%-15s %-12s %s\\n\u0026#39; \u0026#34;$name\u0026#34; \u0026#34;$ip\u0026#34; \u0026#34;$last\u0026#34; done } case \u0026#34;${1:-}\u0026#34; in add) [[ $# -eq 2 || ( $# -eq 3 \u0026amp;\u0026amp; ${3:-} == \u0026#34;--local\u0026#34; ) ]] || die \u0026#34;usage: wg-peer add \u0026lt;name\u0026gt; [--local]\u0026#34; if [[ ${3:-} == \u0026#34;--local\u0026#34; ]]; then cmd_add \u0026#34;$2\u0026#34; \u0026#34;$LOCAL_ALLOWED\u0026#34; else cmd_add \u0026#34;$2\u0026#34; \u0026#34;$FULL_ALLOWED\u0026#34; fi ;; remove) [[ $# -eq 2 ]] || die \u0026#34;usage: wg-peer remove \u0026lt;name\u0026gt;\u0026#34;; cmd_remove \u0026#34;$2\u0026#34; ;; list) cmd_list ;; *) echo \u0026#34;usage: wg-peer {add \u0026lt;name\u0026gt; [--local] | remove \u0026lt;name\u0026gt; | list}\u0026#34; \u0026gt;\u0026amp;2; exit 1 ;; esac bash sudo chown root:root /usr/local/sbin/wg-peer sudo chmod 700 /usr/local/sbin/wg-peer How It Works # It finds the peers by a marker. A # peer: \u0026lt;name\u0026gt; line is written before each peer\u0026rsquo;s [Peer] block. The remove and list commands find the peers by this line. The name rule comes from Linux\u0026rsquo;s limit for network interface names. Names may contain lowercase letters, digits and -, and can be at most 15 characters long; this is the same as the interface name limit in the Linux kernel. So the client name can also be used directly as the interface name in NetworkManager. Changes don\u0026rsquo;t drop connections. Before every change the script makes a wg0.conf.bak backup and applies the change to the live interface with syncconf. If applying fails, it restores the backup. The configuration is shown only once. If it is lost, you need to create it again with remove and add. The --local option only changes the client configuration: the AllowedIPs line is limited to the VPN network and no DNS line is added. The peer entry on the server is the same in both cases; the client decides which traffic goes through the tunnel. The split tunnel has no DNS line because internet traffic doesn\u0026rsquo;t go through the tunnel. With the line, the client\u0026rsquo;s DNS setting would change for no reason and the queries would still go outside the tunnel. The client keeps using its own DNS server. Usage # The Secure Path Setting # We put wg-peer in the /usr/local/sbin directory. sudo looks for the command to run in the secure_path list in /etc/sudoers, and on Rocky Linux /usr/local/sbin is not in this list. So without this setting, sudo wg-peer is not found. The same problem happens in a root shell opened with sudo -s; it doesn\u0026rsquo;t happen in a shell opened with sudo -i.\nTo add /usr/local/sbin to the secure_path list, let\u0026rsquo;s open a new file with visudo:\nbash sudo visudo -f /etc/sudoers.d/secure_path and add the line below to it:\n/etc/sudoers.d/secure_path Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin Adding a New Device # Full tunnel (all traffic through the VPN):\nWarning If you did the manual steps, we already added a peer named desktop. Use a different name so the script doesn\u0026rsquo;t give an error.\nbash sudo wg-peer add desktop Split tunnel (only the VPN network, --local):\nbash sudo wg-peer add xentranet --local After it runs, it prints the client configuration on the screen as text and as a QR code. The difference between the configurations of the two commands is in the AllowedIPs and DNS lines:\nCommand AllowedIPs on the client DNS on the client wg-peer add \u0026lt;name\u0026gt; 0.0.0.0/0, ::/0 1.1.1.1, 2606:4700:4700::1111 wg-peer add \u0026lt;name\u0026gt; --local 10.8.0.0/24, fd42:8::/64 None (the client\u0026rsquo;s own DNS) Listing # bash sudo wg-peer list Removing a Device # bash sudo wg-peer remove desktop Desktop Client # I do the steps below on a Linux desktop that uses NetworkManager. I\u0026rsquo;ll use two profiles on the desktop:\nxenternet: All traffic goes through the tunnel (full tunnel). For going out to the internet through the VPN. xentranet: Only the traffic for the VPN network (10.8.0.0/24, fd42:8::/64) goes through the tunnel (split tunnel). For reaching the services behind the VPN at any time. Note The server accepts packets from a peer only from that peer\u0026rsquo;s AllowedIPs addresses, so each profile must be added on the server as a separate peer (with its own key and IP).\nFull Tunnel Profile (xenternet) # We copy the configuration text (the output of wg-peer add, or the desktop.conf we prepared by hand), create the file /tmp/xenternet.conf on our personal computer and paste it in.\nNote The file name will be used as the connection and interface name in NetworkManager.\nbash nmcli connection import type wireguard file /tmp/xenternet.conf rm /tmp/xenternet.conf nmcli con modify xenternet connection.autoconnect no \\ ipv4.dns-priority -50 ipv6.dns-priority -50 ipv4.dns-search \u0026#34;~.\u0026#34; nmcli con up xenternet Split Tunnel Profile (xentranet) # On the server we create a separate peer for this profile with the --local option:\nbash sudo wg-peer add xentranet --local In the configuration in the output, the AllowedIPs line is already 10.8.0.0/24, fd42:8::/64 and there is no DNS line; the system\u0026rsquo;s DNS setting doesn\u0026rsquo;t change. We paste the configuration into the file /tmp/xentranet.conf on our personal computer.\nbash nmcli connection import type wireguard file /tmp/xentranet.conf rm /tmp/xentranet.conf nmcli con up xentranet The connections should work. From now on the profiles can be turned on and off from the desktop\u0026rsquo;s network menu.\nNote When both profiles are connected at the same time, access to the VPN network stops. The reason and the fix are in 7.3 Possible Problems.\nMobile Client # In the WireGuard mobile app we use the \u0026ldquo;Create from QR code\u0026rdquo; option to scan the QR code in the terminal, and the connection is set up.\nCheck # bash ping 10.8.0.1 # should answer curl -4 ifconfig.me # with the full tunnel, the server\u0026#39;s IPv4 address curl -6 ifconfig.me # with the full tunnel, the server\u0026#39;s IPv6 address ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/wireguard-clients/","section":"Self Hosting","summary":" Requirements 7 WireGuard Setup must be done. Assumptions\nThe server’s VPN address is 10.8.0.1; clients connect to the VPN through xenonly.com:51820. Server-side commands are run on the server, client-side commands on a Linux desktop that uses NetworkManager. Commands that need root rights are written with sudo. The desktop uses two VPN profiles: xenternet (full tunnel), which sends all traffic through the tunnel, and xentranet (split tunnel), which sends only the traffic for the VPN network through the tunnel. ","title":"Adding WireGuard Clients","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/firewalld/","section":"Tags","summary":"","title":"firewalld","type":"tags"},{"content":" Requirements 4 Docker Setup and 5 Firewalld Configuration must be done (this part changes the configuration of both). Assumptions\nThe outside network interface is eth0, it is managed by NetworkManager, and its IPv6 address is set statically. The VPN networks are 10.8.0.0/24 (IPv4) and fd42:8::/64 (IPv6); the server\u0026rsquo;s VPN address is 10.8.0.1 / fd42:8::1. WireGuard listens on port 51820/udp. Commands are run on the server with root rights (sudo). We\u0026rsquo;ll use WireGuard for these things:\nSending clients to the internet through the VPN Letting clients talk to each other (for example a laptop and a phone) Making some services on the server (for example the iRedAdmin panel) reachable only over the VPN instead of by everyone Installation # bash sudo dnf install wireguard-tools qrencode Note The WireGuard kernel module is already in the Rocky Linux 10 kernel, so we only install the tools. qrencode is for showing the phone configuration as a QR code.\nCreating the Key Pair # Let\u0026rsquo;s create the key pair the WireGuard service will use:\nbash sudo sh -c \u0026#39;cd /etc/wireguard \u0026amp;\u0026amp; umask 077 \u0026amp;\u0026amp; wg genkey | tee server.key | wg pubkey \u0026gt; server.pub\u0026#39; Note cd and umask are commands of the shell itself, so running them as sudo cd or sudo umask doesn\u0026rsquo;t affect the current shell. That\u0026rsquo;s why we run the commands in a single root shell with sudo sh -c. umask 077 makes sure only root can read the key files we create.\nPermanent IP Forwarding # Note We turn on IP forwarding so that packets can be passed from one interface to another (in practice, so that traffic from the VPN interface can go out to the internet).\nNote Docker already turns forwarding on, but only when its own service starts. This file turns forwarding on at boot, independent of Docker.\nCheck IPv6 First # On Linux, once IPv6 forwarding is on, the kernel no longer accepts Router Advertisements (RA). If the VPS gets its IPv6 address through RA (SLAAC), the IPv6 connection may drop the moment we turn forwarding on. So before turning forwarding on, let\u0026rsquo;s check the default IPv6 route:\nbash ip -6 route show default The output should look similar to this:\ndefault via fe80::1 dev eth0 proto static metric 100 pref medium On this server IPv6 is static (proto static) and RA is not used, so turning forwarding on doesn\u0026rsquo;t affect the IPv6 connection. If the output shows proto ra, you also need to add the line net.ipv6.conf.eth0.accept_ra = 2 to the file below.\nTurning On Forwarding # Let\u0026rsquo;s create the file /etc/sysctl.d/90-wireguard.conf with the content below:\n/etc/sysctl.d/90-wireguard.confini net.ipv4.ip_forward = 1 net.ipv6.conf.all.forwarding = 1 Let\u0026rsquo;s apply the settings:\nbash sudo sysctl --system WireGuard Configuration # Let\u0026rsquo;s create /etc/wireguard/wg0.conf like this:\n/etc/wireguard/wg0.confini [Interface] Address = 10.8.0.1/24, fd42:8::1/64 ListenPort = 51820 PrivateKey = \u0026lt;server.key\u0026gt; Note \u0026lt;server.key\u0026gt;: The contents of the file /etc/wireguard/server.key (sudo cat /etc/wireguard/server.key).\nLet\u0026rsquo;s set the file\u0026rsquo;s permissions so only root can read it:\nbash sudo chmod 600 /etc/wireguard/wg0.conf Firewalld Configuration # Binding the Outside Interface to the Public Zone Explicitly # Note eth0 is in the default zone right now, so it is already in the public zone. This step makes sure eth0 stays in the public zone even if the default zone changes later, so the VPN policy we\u0026rsquo;ll define below (its outgoing zone is public) keeps working.\nbash sudo nmcli -t -f NAME,DEVICE con show --active sudo nmcli con modify \u0026#34;\u0026lt;CONNECTION_NAME\u0026gt;\u0026#34; connection.zone public Note \u0026lt;CONNECTION_NAME\u0026gt;: The name of the connection that belongs to eth0 in the output of the first command.\nOpening the WireGuard Port # bash sudo firewall-cmd --permanent --zone=public --add-service=wireguard Creating a Zone for the VPN in Firewalld # bash # Creates a new, empty zone named vpn sudo firewall-cmd --permanent --new-zone=vpn # Binds the wg0 interface to this zone. From now on, all traffic from the WireGuard tunnel is checked against the rules of the vpn zone, not the public zone. sudo firewall-cmd --permanent --zone=vpn --add-interface=wg0 # Sets which services on the server the traffic from the VPN may reach: sudo firewall-cmd --permanent --zone=vpn \\ --add-service=ssh --add-service=http --add-service=https \\ --add-service=smtp-submission --add-service=smtps \\ --add-service=imap --add-service=imaps # Allows forwarding inside the same zone, so clients can talk to each other. sudo firewall-cmd --permanent --zone=vpn --add-forward Note Why we allow the services that are already allowed in the public zone again in the VPN zone: when a client is connected to the VPN, its traffic to the server (with a full tunnel, even the traffic to the server\u0026rsquo;s public IP) comes in through wg0. If we don\u0026rsquo;t allow these services in the VPN zone, the client can\u0026rsquo;t reach them while it is connected to the VPN.\nFrom the VPN to the Internet # Note A zone manages traffic that comes to the server itself. For example: \u0026ldquo;Can someone coming from the VPN connect to SSH on the server?\u0026rdquo;\nNote A policy manages traffic that goes through the server, so packets forwarded from one zone to another.\nIn Firewalld, forwarding between zones is off by default. So for the VPN clients to reach the internet, we need to define a policy explicitly.\nbash # Creates a new, empty policy named vpn-internet. sudo firewall-cmd --permanent --new-policy=vpn-internet # Sets the direction of the policy. It applies when traffic comes from the vpn zone (wg0) and goes to the public zone (the outside interface, so the internet). sudo firewall-cmd --permanent --policy=vpn-internet --add-ingress-zone=vpn sudo firewall-cmd --permanent --policy=vpn-internet --add-egress-zone=public # Accepts traffic in this direction. A VPN client can go to any address on the internet; port 25 is blocked by the no-smtp-out policy from part 5. sudo firewall-cmd --permanent --policy=vpn-internet --set-target=ACCEPT # Turns on NAT. sudo firewall-cmd --permanent --policy=vpn-internet --add-masquerade # --add-masquerade only applies to IPv4, IPv6 needs a separate rich rule sudo firewall-cmd --permanent --policy=vpn-internet \\ --add-rich-rule=\u0026#39;rule family=\u0026#34;ipv6\u0026#34; source address=\u0026#34;fd42:8::/64\u0026#34; masquerade\u0026#39; Let\u0026rsquo;s apply the rules we added to Firewalld:\nbash sudo firewall-cmd --reload Let\u0026rsquo;s check the zone and the policy:\nbash # Shows which interface is in which zone sudo firewall-cmd --get-active-zones docker interfaces: docker0 public (default) interfaces: eth0 vpn interfaces: wg0 bash # Shows the settings of the policy sudo firewall-cmd --info-policy=vpn-internet vpn-internet (active) disable: no priority: -1 target: ACCEPT ingress-zones: vpn egress-zones: public services: ports: protocols: masquerade: yes forward-ports: source-ports: icmp-blocks: rich rules: rule family=\u0026#34;ipv6\u0026#34; source address=\u0026#34;fd42:8::/64\u0026#34; masquerade Note The no-smtp-out policy we created in 5 Firewalld Configuration uses ANY as the ingress zone, so it applies to the VPN clients too. Its priority (-10) is smaller than that of vpn-internet (-1), so it is checked first. After adding a client (7.1), while it is connected with the full tunnel profile, the command nc -v -w 5 gmail-smtp-in.l.google.com 25 \u0026lt;/dev/null on the client should give a connection error. On Windows, Test-NetConnection gmail-smtp-in.l.google.com -Port 25 should return TcpTestSucceeded : False.\nDocker\u0026rsquo;s FORWARD DROP Policy # Docker sets the default policy of the FORWARD chain in iptables to DROP. Even if Firewalld allows the VPN traffic, the packet also passes through Docker\u0026rsquo;s table, and the DROP policy drops it.\nLet\u0026rsquo;s check whether this policy is in place:\nbash sudo iptables -S FORWARD | head -1 sudo ip6tables -S FORWARD | head -1 If the output shows -P FORWARD DROP, the policy is in place.\nLet\u0026rsquo;s stop Docker from setting the DROP policy by adding the line below to /etc/docker/daemon.json:\n/etc/docker/daemon.jsonjson \u0026#34;ip-forward-no-drop\u0026#34;: true The file should look like this:\n/etc/docker/daemon.jsonjson { \u0026#34;ip\u0026#34;: \u0026#34;127.0.0.1\u0026#34;, \u0026#34;default-network-opts\u0026#34;: { \u0026#34;bridge\u0026#34;: { \u0026#34;com.docker.network.bridge.host_binding_ipv4\u0026#34;: \u0026#34;127.0.0.1\u0026#34; } }, \u0026#34;log-driver\u0026#34;: \u0026#34;journald\u0026#34;, \u0026#34;live-restore\u0026#34;: true, \u0026#34;ip-forward-no-drop\u0026#34;: true, \u0026#34;default-address-pools\u0026#34;: [ { \u0026#34;base\u0026#34;: \u0026#34;172.20.0.0/16\u0026#34;, \u0026#34;size\u0026#34;: 24 } ] } Let\u0026rsquo;s check the Docker configuration:\nbash sudo dockerd --validate --config-file /etc/docker/daemon.json If we got the configuration OK output, let\u0026rsquo;s restart Docker and fix the FORWARD policy:\nbash sudo systemctl restart docker sudo iptables -P FORWARD ACCEPT \u0026amp;\u0026amp; sudo ip6tables -P FORWARD ACCEPT Note Restarting Docker doesn\u0026rsquo;t change the current DROP policy. The ip-forward-no-drop setting stops Docker from setting the policy to DROP from now on. The policy that is DROP right now doesn\u0026rsquo;t fix itself, so we set it to ACCEPT by hand once.\nNote This doesn\u0026rsquo;t mean forwarded traffic is no longer filtered. Firewalld keeps filtering forwarded traffic with the zone and policy rules in its own nftables table. The ACCEPT policy in iptables only removes the second block Docker put there.\nStarting WireGuard # Let\u0026rsquo;s enable and start the service with the commands below:\nbash sudo systemctl enable --now wg-quick@wg0 sudo wg show The output should show interface: wg0 and listening port: 51820.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/wireguard/","section":"Self Hosting","summary":" Requirements 4 Docker Setup and 5 Firewalld Configuration must be done (this part changes the configuration of both). Assumptions\nThe outside network interface is eth0, it is managed by NetworkManager, and its IPv6 address is set statically. The VPN networks are 10.8.0.0/24 (IPv4) and fd42:8::/64 (IPv6); the server’s VPN address is 10.8.0.1 / fd42:8::1. WireGuard listens on port 51820/udp. Commands are run on the server with root rights (sudo). ","title":"WireGuard Setup","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/fail2ban/","section":"Tags","summary":"","title":"fail2ban","type":"tags"},{"content":" Requirements 2 Mail Server Setup must be done (Fail2Ban is installed together with iRedMail). Assumptions\nThe VPN networks are 10.8.0.0/24 and fd42:8::/64 from 7 WireGuard Setup; these networks are never banned. Commands are run on the server with root rights (sudo). Fail2Ban was installed together with iRedMail. Let\u0026rsquo;s add a few useful settings on top of it.\nLonger Bans for Repeat Offenders # Let\u0026rsquo;s create the file /etc/fail2ban/jail.d/99-local.local with the content below.\nNote Fail2Ban reads the files in this order: jail.conf → jail.d/*.conf → jail.local → jail.d/*.local (alphabetical). 99-local.local is read last, so its [DEFAULT] settings override the [DEFAULT] settings in the earlier files. But settings defined in jail sections (for example [sshd]) win over [DEFAULT]; this file doesn\u0026rsquo;t change them.\n/etc/fail2ban/jail.d/99-local.localini [DEFAULT] bantime.increment = true bantime.factor = 2 bantime.maxtime = 1w ignoreip = 127.0.0.1/8 ::1 10.8.0.0/24 fd42:8::/64 Note ignoreip: Only localhost and the VPN network are never banned. We can\u0026rsquo;t leave out localhost; Roundcube and iRedAdmin connect to Dovecot and Postfix from 127.0.0.1. The VPN network is never banned because after 7.2 Putting Services Behind the VPN SSH is reachable only over the VPN; if our VPN address gets banned, we lose access to the server.\nNote We leave the Docker network (172.20.0.0/16) out of ignoreip on purpose. Containers connect to the ports on the host from 172.20.x.x addresses; if a compromised container tries mail passwords, it should be banned. The ban only affects that container. A container with a wrong SMTP password can get banned too; then fixing the password and lifting the ban with sudo fail2ban-client unban \u0026lt;IP\u0026gt; is enough.\nfail2ban.conf has dbpurgeage = 1d, so Fail2Ban remembers an IP in its database for at most 1 day. The longer bans work by reading an IP\u0026rsquo;s earlier bans from this database, so dbpurgeage must not be shorter than bantime.maxtime. Otherwise bans older than 1 day are forgotten and the ban time doesn\u0026rsquo;t grow.\nWithout changing fail2ban.conf, let\u0026rsquo;s create the file /etc/fail2ban/fail2ban.local with the content below (if the file already exists, add the dbpurgeage line to its [Definition] section):\n/etc/fail2ban/fail2ban.localini [Definition] dbpurgeage = 1w Apply and Check # bash sudo fail2ban-client -t # OK: configuration test is successful sudo systemctl restart fail2ban sudo fail2ban-client get sshd bantime # 3600 sudo fail2ban-client get dbpurgeage # 604800 (1 week) ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/fail2ban/","section":"Self Hosting","summary":" Requirements 2 Mail Server Setup must be done (Fail2Ban is installed together with iRedMail). Assumptions\nThe VPN networks are 10.8.0.0/24 and fd42:8::/64 from 7 WireGuard Setup; these networks are never banned. Commands are run on the server with root rights (sudo). ","title":"Fail2Ban Configuration","type":"self-hosting"},{"content":" Requirements 2 Mail Server Setup, 3 NGINX Configuration and 4 Docker Setup must be done. Assumptions\nFirewalld was turned off in 1 Post-Install Configuration, and iRedMail\u0026rsquo;s Firewalld configuration was not applied during the installation. The outside network interface is eth0, and SSH runs on the default port, 22. Commands are run on the server with root rights (sudo). Which Ports We\u0026rsquo;ll Open # Service Port Why ssh 22/tcp The default port for SSH. If SSH runs on another port, add it with --add-port=\u0026lt;PORT\u0026gt;/tcp http / https 80/tcp, 443/tcp NGINX smtp 25/tcp Mail coming from other servers smtp-submission 587/tcp Clients sending mail (STARTTLS) smtps 465/tcp Clients sending mail (TLS) imap / imaps 143/tcp, 993/tcp Reading mail Starting Point # Let\u0026rsquo;s check the starting point:\nbash sudo systemctl is-active firewalld sudo firewall-offline-cmd --get-default-zone sudo firewall-offline-cmd --zone=public --list-all The output should look like this:\ninactive public public (default) target: default ingress-priority: 0 egress-priority: 0 icmp-block-inversion: no interfaces: sources: services: cockpit dhcpv6-client ssh ports: protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: This is the default Firewalld configuration. Firewalld is off right now; we\u0026rsquo;ll keep it that way for now.\nPublic Zone Configuration # Cockpit is allowed by default; we won\u0026rsquo;t use it, so let\u0026rsquo;s remove it. Firewalld is off, so we\u0026rsquo;ll use firewall-offline-cmd instead of firewall-cmd.\nbash sudo firewall-offline-cmd --zone=public --remove-service-from-zone=cockpit We add the services we use:\nbash sudo firewall-offline-cmd --zone=public \\ --add-service=ssh --add-service=http --add-service=https \\ --add-service=smtp --add-service=smtp-submission --add-service=smtps \\ --add-service=imap --add-service=imaps ssh is on by default, so the warning Warning: ALREADY_ENABLED: ssh is normal. After it, a success output follows.\nThe services we added are http and https for NGINX, and the ones the mail service needs. I won\u0026rsquo;t use POP3, so I didn\u0026rsquo;t add it.\nLet\u0026rsquo;s check the changes:\nbash sudo firewall-offline-cmd --zone=public --list-all The output should look like this:\npublic (default) target: default ingress-priority: 0 egress-priority: 0 icmp-block-inversion: no interfaces: sources: services: dhcpv6-client http https imap imaps smtp smtp-submission smtps ssh ports: protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: Rescue Timer and Start # In case something goes wrong after Firewalld is on and we can\u0026rsquo;t connect over SSH, let\u0026rsquo;s set up a timer that stops Firewalld after 10 minutes:\nbash sudo systemd-run --on-active=10min --unit=fw-rescue systemctl stop firewalld Then we can enable and start Firewalld:\nbash sudo systemctl enable --now firewalld sudo firewall-cmd --get-active-zones When Firewalld starts, the current SSH session doesn\u0026rsquo;t drop, because connections that are already open are still allowed. So let\u0026rsquo;s do the test by opening a new SSH connection from a new terminal. If the connection works, we can cancel the timer:\nbash sudo systemctl stop fw-rescue.timer Docker Integration # We installed Docker before configuring Firewalld, so Docker couldn\u0026rsquo;t create its own Firewalld settings (the docker zone and the docker-forwarding policy). Restarting Docker is enough for this:\nbash sudo systemctl restart docker Check # bash sudo firewall-cmd --get-active-zones docker interfaces: docker0 public (default) interfaces: eth0 bash sudo firewall-cmd --zone=docker --list-all docker (active) target: ACCEPT ingress-priority: 0 egress-priority: 0 icmp-block-inversion: no interfaces: docker0 sources: services: ports: protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: bash sudo firewall-cmd --get-policies allow-host-ipv6 docker-forwarding gateway-dmz-to-HOST gateway-lan-to-HOST gateway-lan-to-work gateway-lan-to-world gateway-world-to-HOST If the outputs show the docker zone and the docker-forwarding policy, Docker\u0026rsquo;s Firewalld configuration was done.\nBlocking Outgoing Port 25 # Everything that goes out to the internet through the server, so the containers and the VPN clients we\u0026rsquo;ll set up in 7 WireGuard Setup, uses the same IP addresses as the mail server. The PTR record of these addresses points to mail.xenonly.com. If a compromised container or a device on the VPN sends spam directly out on port 25, our mail server\u0026rsquo;s IP gets on a blocklist.\nMail servers talk to each other on port 25, and only Postfix on the host needs to go out on this port. The containers send their mail to our own mail server on port 587, with a login. That connection is not forwarded, it comes straight to the host, so the block doesn\u0026rsquo;t affect it.\nFirst let\u0026rsquo;s see the problem. Let\u0026rsquo;s try to connect from a container to Gmail\u0026rsquo;s mail server on port 25:\nbash sudo docker run --rm alpine nc -v -w 5 gmail-smtp-in.l.google.com 25 gmail-smtp-in.l.google.com (64.233.167.26:25) open The open line shows that the container can connect directly to a mail server outside on port 25.\nLet\u0026rsquo;s create a policy that rejects traffic that goes through the server (is forwarded) to port 25 outside:\nbash # Creates a new, empty policy named no-smtp-out. sudo firewall-cmd --permanent --new-policy=no-smtp-out # Applies to traffic forwarded from any zone (ANY) to the public zone (the internet). # ANY doesn\u0026#39;t include the server\u0026#39;s own traffic (HOST), so Postfix is not affected. sudo firewall-cmd --permanent --policy=no-smtp-out --add-ingress-zone=ANY sudo firewall-cmd --permanent --policy=no-smtp-out --add-egress-zone=public # Makes the policy run before the zone rules and the other policies. sudo firewall-cmd --permanent --policy=no-smtp-out --set-priority=-10 # Rejects connections to port 25. Logs at most 3 lines per minute. sudo firewall-cmd --permanent --policy=no-smtp-out \\ --add-rich-rule=\u0026#39;rule port port=\u0026#34;25\u0026#34; protocol=\u0026#34;tcp\u0026#34; log prefix=\u0026#34;SMTP-OUT-BLOCK: \u0026#34; level=\u0026#34;warning\u0026#34; limit value=\u0026#34;3/m\u0026#34; reject\u0026#39; sudo firewall-cmd --reload Note Policies are checked in order of their priority value; the smaller value comes first. Policies with a negative priority run before the zone rules. -10 makes this policy run before the ACCEPT target of the docker zone and before the vpn-internet policy (-1) we\u0026rsquo;ll create in part 7.\nNote We didn\u0026rsquo;t change the policy\u0026rsquo;s target; the default is CONTINUE. Traffic to ports other than 25 moves on to the next rule and works as before. We didn\u0026rsquo;t set family in the rich rule, so the rule applies to both IPv4 and IPv6.\nNote We used ANY as the ingress zone, so the rule also applies by itself to zones added later (for example the vpn zone in part 7).\nLet\u0026rsquo;s check the policy:\nbash sudo firewall-cmd --info-policy=no-smtp-out The output should show priority: -10, ingress-zones: ANY, egress-zones: public and the rich rule we added.\nLet\u0026rsquo;s run the test again:\nbash sudo docker run --rm alpine nc -v -w 5 gmail-smtp-in.l.google.com 25 This time the open line should not show up; nc should print a connection error. The blocked attempts go to the kernel log:\nbash sudo journalctl -k -g SMTP-OUT-BLOCK Note The SRC= field in the log shows the IP address of the container or VPN client that tried to go out on port 25. If there is an unexpected entry here, that container or device may be compromised.\nTo see that Postfix is not affected, let\u0026rsquo;s send a mail to a Gmail address and look for the status=sent line in Postfix\u0026rsquo;s log:\nbash sudo journalctl -t postfix/smtp -n 20 ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/firewalld/","section":"Self Hosting","summary":" Requirements 2 Mail Server Setup, 3 NGINX Configuration and 4 Docker Setup must be done. Assumptions\nFirewalld was turned off in 1 Post-Install Configuration, and iRedMail’s Firewalld configuration was not applied during the installation. The outside network interface is eth0, and SSH runs on the default port, 22. Commands are run on the server with root rights (sudo). ","title":"Firewalld Configuration","type":"self-hosting"},{"content":" Requirements 3 NGINX Configuration and 4 Docker Setup must be done. Assumptions\nContainer ports are published in the compose files as 127.0.0.1:\u0026lt;HOST_PORT\u0026gt;:\u0026lt;CONTAINER_PORT\u0026gt; and opened to the outside only through NGINX. The settings in 4 Docker Setup also bind ports published without an IP address to 127.0.0.1. Commands are run on the server with root rights (sudo). Let\u0026rsquo;s put the containers we\u0026rsquo;ll install into a standard layout.\nLet\u0026rsquo;s keep the Docker Compose files in one place:\nbash sudo mkdir /opt/docker Port Plan # The containers open their ports only on 127.0.0.1, and NGINX forwards to these ports. To avoid clashes, the ports of the services installed in this series are:\nService Port Note 8 Vault Setup 127.0.0.1:8200 Not Docker, runs as a service on the host 9 Vaultwarden Setup 127.0.0.1:8004 10 WordPress Setup 127.0.0.1:8030–8049 One port for each site 11 Usememos Setup 127.0.0.1:8001 12 Syncthing Setup 127.0.0.1:8384, 22000 Not Docker, runs as a service on the host You can check the ports in use with sudo ss -tlnp | grep docker-proxy.\nNGINX Settings # WebSocket Support # First let\u0026rsquo;s check whether the $connection_upgrade variable is already defined. If the same map is defined twice, NGINX gives an error.\nbash sudo grep -rn connection_upgrade /etc/nginx/ # output should be empty If the output is empty, let\u0026rsquo;s create /etc/nginx/conf.d/websocket.conf like this:\n/etc/nginx/conf.d/websocket.confnginx map $http_upgrade $connection_upgrade { default upgrade; \u0026#39;\u0026#39; close; } Proxy Template # Let\u0026rsquo;s create /etc/nginx/templates/proxy.tmpl like this:\n/etc/nginx/templates/proxy.tmplnginx proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; Note The basic configuration for a reverse proxy; we\u0026rsquo;ll use it in most of the virtual hosts that forward to containers.\nWarning proxy_set_header is inherited the same way as add_header: if even one proxy_set_header is defined in a location block, all the ones from the parent block stop working in that block. That\u0026rsquo;s why the safest way is to include the template in the same location block as proxy_pass.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/docker-template/","section":"Self Hosting","summary":" Requirements 3 NGINX Configuration and 4 Docker Setup must be done. Assumptions\nContainer ports are published in the compose files as 127.0.0.1:\u003cHOST_PORT\u003e:\u003cCONTAINER_PORT\u003e and opened to the outside only through NGINX. The settings in 4 Docker Setup also bind ports published without an IP address to 127.0.0.1. Commands are run on the server with root rights (sudo). ","title":"A Ready Template for Docker Containers","type":"self-hosting"},{"content":" Requirements 1 Post-Install Configuration must be done. Assumptions\nContainers are reached through the NGINX configured in 3 NGINX Configuration. Firewalld is still off. Docker\u0026rsquo;s Firewalld integration is finished in 5 Firewalld Configuration. Commands are run on the server with root rights (sudo). Check and Install # On RHEL-based systems, Podman, Buildah and runc may come preinstalled. Since they may clash with Docker\u0026rsquo;s own packages, let\u0026rsquo;s remove them and install Docker from its own repository:\nbash sudo dnf remove podman buildah runc Let\u0026rsquo;s add the Docker repository and install it:\nbash sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin Before starting Docker, let\u0026rsquo;s write our configuration to /etc/docker/daemon.json. If the directory doesn\u0026rsquo;t exist yet, let\u0026rsquo;s create it first:\nbash sudo mkdir -p /etc/docker /etc/docker/daemon.jsonjson { \u0026#34;ip\u0026#34;: \u0026#34;127.0.0.1\u0026#34;, \u0026#34;default-network-opts\u0026#34;: { \u0026#34;bridge\u0026#34;: { \u0026#34;com.docker.network.bridge.host_binding_ipv4\u0026#34;: \u0026#34;127.0.0.1\u0026#34; } }, \u0026#34;log-driver\u0026#34;: \u0026#34;journald\u0026#34;, \u0026#34;live-restore\u0026#34;: true, \u0026#34;default-address-pools\u0026#34;: [ { \u0026#34;base\u0026#34;: \u0026#34;172.20.0.0/16\u0026#34;, \u0026#34;size\u0026#34;: 24 } ] } Why each line is there:\n\u0026quot;ip\u0026quot; and \u0026quot;default-network-opts\u0026quot;: By default, Docker binds ports published without an IP address, like -p 8080:80, to 0.0.0.0 and writes its own rules for them. Traffic to these ports is passed to the container without going through Firewalld\u0026rsquo;s zone rules; even with Firewalld on, the port stays open to the internet. The services that need to be reached will be reached through NGINX, so no container needs to be open to the internet; being reachable over localhost is enough. The \u0026quot;ip\u0026quot; setting only applies to the default bridge network (docker run). For the networks Compose creates, we set the same default with default-network-opts. This setting is applied when a network is created; if it is added later, it doesn\u0026rsquo;t affect the existing networks. Still, in the compose files we\u0026rsquo;ll write the ports explicitly, like 127.0.0.1:8080:80. \u0026quot;log-driver\u0026quot;: \u0026quot;journald\u0026quot;: By default, logs are written to files with the json-file driver. To reach and manage all logs from one place, we send them to journald. The docker logs command keeps working. \u0026quot;live-restore\u0026quot;: true: Keeps the containers running when the Docker service is restarted or updated. \u0026quot;default-address-pools\u0026quot;: Sets the range the container networks get their IP addresses from. We can start the service:\nbash sudo systemctl enable --now docker We can check that Docker works with the command below:\nbash sudo docker run --rm hello-world The output should have these lines:\nHello from Docker! This message shows that your installation appears to be working correctly. Let\u0026rsquo;s check that a port published without an IP address is bound only to localhost on the kind of network Compose uses too:\nbash sudo docker network create porttest sudo docker network inspect porttest --format \u0026#39;{{json .Options}}\u0026#39; sudo docker run -d --rm --name porttest --network porttest -p 18080:80 alpine sleep 60 sudo ss -tln | grep 18080 sudo docker rm -f porttest \u0026amp;\u0026amp; sudo docker network rm porttest The inspect output should show \u0026quot;com.docker.network.bridge.host_binding_ipv4\u0026quot;:\u0026quot;127.0.0.1\u0026quot;, and the ss output only 127.0.0.1:18080; 0.0.0.0 or [::] should not show up.\nThings to Keep in Mind # We don\u0026rsquo;t add the normal user to the docker group, because that would let the user become root without a password. When NGINX proxies to a container, it must send the X-Forwarded-For and X-Real-IP headers. Otherwise the applications see every visitor as 172.20.x.x. For this we\u0026rsquo;ll create a shared template in 4.1 A Ready Template for Docker Containers. ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/docker/","section":"Self Hosting","summary":" Requirements 1 Post-Install Configuration must be done. Assumptions\nContainers are reached through the NGINX configured in 3 NGINX Configuration. Firewalld is still off. Docker’s Firewalld integration is finished in 5 Firewalld Configuration. Commands are run on the server with root rights (sudo). ","title":"Docker Setup","type":"self-hosting"},{"content":" Requirements 2 Mail Server Setup and 2.1 Setting Up SSL for the Mail Server must be done. Assumptions\nNGINX was installed and configured by iRedMail (version 1.26 from the Rocky Linux 10 repository). A and AAAA records exist for mail.xenonly.com and iredadmin.xenonly.com. Commands are run on the server with root rights (sudo). Understanding the Current Configuration # iRedMail\u0026rsquo;s Default Layout # The NGINX on the system was installed by iRedMail, and iRedMail changed its configuration.\nNote On a normal RHEL installation, the include directive in /etc/nginx/nginx.conf includes the conf.d directory. iRedMail uses the same directory layout on every distribution, so during the installation it rewrites nginx.conf and includes the sites-enabled and conf-enabled directories.\nIn the steps part, I\u0026rsquo;ll change this layout like this:\nconf.d for configuration files vhost.d for virtual host definitions Templates (/etc/nginx/templates) # Under /etc/nginx/templates there are the default templates iRedMail brought. The netdata.tmpl, netdata-subdomain.tmpl, sogo.tmpl, sogo-subdomain.tmpl and adminer.tmpl templates won\u0026rsquo;t be used; we\u0026rsquo;ll delete them in the steps part.\nLet\u0026rsquo;s look at the other templates.\nfastcgi_php.tmpl # Has the shared settings for passing PHP requests to PHP-FPM (php_workers → 127.0.0.1:9999). Roundcube and the other PHP blocks include this file.\nhsts.tmpl # Sends the Strict-Transport-Security header to the browser. A browser that gets this header connects to the site only over HTTPS for 1 year.\nThe current NGINX version (1.26) doesn\u0026rsquo;t support the add_header_inherit directive. So if add_header is defined in a virtual host or a location block, the headers in conf.d/headers.conf are not applied in that block.\nThe hsts.tmpl template is included from the roundcube-subdomain.tmpl, roundcube.tmpl and iredadmin-subdomain.tmpl templates.\nSo in the steps part we\u0026rsquo;ll add the definition in hsts.tmpl to headers.conf, remove the include lines from these three templates and delete hsts.tmpl.\niredadmin-subdomain.tmpl # A ready configuration for serving the admin panel that comes with iRedMail on a subdomain. This is what we\u0026rsquo;ll use on our system too.\niredadmin.tmpl # For the admin panel that comes with iRedMail; it passes requests for the /iredadmin path to iRedAdmin.\nWe\u0026rsquo;ll serve iRedAdmin on a subdomain, so we\u0026rsquo;ll delete this one in the steps part.\nmisc.tmpl # Handles .well-known requests that come over HTTPS Blocks access to hidden files Turns off logging for favicon.ico and robots.txt requests php-catchall.tmpl # Passes every .php request not caught by the earlier templates to PHP-FPM.\nThis is not what we want; we\u0026rsquo;ll decide ourselves what runs where. So we don\u0026rsquo;t need it, and we\u0026rsquo;ll delete it in the steps part.\nredirect_to_https.tmpl # Redirects requests for the sogo, iredadmin and mail paths to HTTPS.\nIn the current setup every request is already redirected to HTTPS. We don\u0026rsquo;t need it; we\u0026rsquo;ll delete it in the steps part.\nroundcube-subdomain.tmpl # A ready configuration for serving Roundcube webmail on a subdomain.\nroundcube.tmpl # Used for Roundcube webmail; passes requests for the /mail path to Roundcube.\nOn this system Roundcube will be served on a subdomain, but for other domains we may need to serve it on the /mail path. So I won\u0026rsquo;t delete it.\nssl.tmpl # The standard SSL settings for HTTPS, and the definition of the SSL certificate that iRedMail, which set up our mail server, uses.\nWe\u0026rsquo;ll use this server for many services and virtual hosts, so in the steps part we\u0026rsquo;ll remove the certificate definition from here.\nAlso, the settings in ssl.tmpl can be set at the http level, and we\u0026rsquo;ll use them for every virtual host. So instead of including it in every virtual host configuration, we\u0026rsquo;ll move it to the conf.d directory.\nstub_status.tmpl # Serves the NGINX (/stub_status) and PHP-FPM (/status) status pages for monitoring tools, reachable only from localhost.\nI don\u0026rsquo;t plan to use it, so I\u0026rsquo;ll delete it in the steps part.\nConfiguration Files (/etc/nginx/conf-available → conf.d) # Applied at the http {} level; unless something else is set in a virtual host or location block, they apply to every request.\nI\u0026rsquo;ll only look at the ones that need to change.\nWhat We\u0026rsquo;ll Change # cache.conf # We\u0026rsquo;ll add the current JavaScript MIME types (application/javascript, text/javascript).\nheaders.conf # We\u0026rsquo;ll remove the outdated X-XSS-Protection and X-Download-Options headers and add the Strict-Transport-Security definition from hsts.tmpl here. We\u0026rsquo;ll also remove the Content-Security-Policy header iRedMail set.\nVirtual Hosts (/etc/nginx/sites-available → vhost.d) # The current configuration has only the default virtual host definitions and the templates included in them.\n00-default.conf # Its default version roughly does this:\nListens on port 80 (HTTP) Serves .well-known/acme-challenge requests for SSL from the /opt/www/well_known directory Redirects all other requests to HTTPS 00-default-ssl.conf # Its default version roughly does this:\nListens on port 443 (HTTPS) Has /var/www/html as the root directory and index.php as the index Then includes a set of templates from the templates directory By default these files are included:\nmisc.tmpl → Will be included in the vhosts that need it ssl.tmpl → Will be moved to conf.d iredadmin.tmpl → Will be served on a subdomain roundcube.tmpl → Will be served on a subdomain php-catchall.tmpl → Not used stub_status.tmpl → Not used The Layout We Want # Every request that comes to port 80 (HTTP), except the acme challenge, should be redirected to 443 (HTTPS). The conf.d directory should hold the default settings for every request, and the vhost.d directory the configuration of each virtual host.\nSteps # Directory Layout # As we said in the understanding part, we\u0026rsquo;ll use the conf.d directory for configuration files and vhost.d for virtual host definitions.\nThe whole conf-available directory becomes conf.d, so if there is a file there with no link in conf-enabled (so a file not in use right now), it will start being loaded too. Let\u0026rsquo;s compare the two directories before the move:\nbash ls /etc/nginx/conf-available ls -l /etc/nginx/conf-enabled Then let\u0026rsquo;s rearrange the directories:\nbash cd /etc/nginx sudo rm -rf conf.d # If it exists; it isn\u0026#39;t used right now anyway sudo mv conf-available conf.d sudo mv sites-available vhost.d sudo rm -rf sites-enabled conf-enabled and change the conf-enabled and sites-enabled include lines in nginx.conf like this:\n/etc/nginx/nginx.confnginx http { ... # Requires Nginx 1.25.1+. # http2 on; include /etc/nginx/conf.d/*.conf; include /etc/nginx/vhost.d/*.conf; } Templates # hsts.tmpl # As we said in the understanding part, the hsts.tmpl template is included from three templates:\nbash sudo grep -rn hsts.tmpl /etc/nginx/templates /etc/nginx/templates/iredadmin-subdomain.tmpl:4:include /etc/nginx/templates/hsts.tmpl; /etc/nginx/templates/roundcube-subdomain.tmpl:19: include /etc/nginx/templates/hsts.tmpl; /etc/nginx/templates/roundcube-subdomain.tmpl:23: include /etc/nginx/templates/hsts.tmpl; /etc/nginx/templates/roundcube-subdomain.tmpl:28: include /etc/nginx/templates/hsts.tmpl; /etc/nginx/templates/roundcube.tmpl:27: include /etc/nginx/templates/hsts.tmpl; /etc/nginx/templates/roundcube.tmpl:32: include /etc/nginx/templates/hsts.tmpl; Let\u0026rsquo;s delete the include /etc/nginx/templates/hsts.tmpl; lines in these three templates:\nbash sudo sed -i \u0026#39;/hsts.tmpl/d\u0026#39; /etc/nginx/templates/{iredadmin-subdomain,roundcube-subdomain,roundcube}.tmpl We\u0026rsquo;ll add the definition in hsts.tmpl to headers.conf below, and delete the template itself together with the unused templates.\nssl.tmpl # Let\u0026rsquo;s delete the lines starting with ssl_certificate and ssl_certificate_key in /etc/nginx/templates/ssl.tmpl and move the file to the conf.d directory:\nbash sudo sed -i \u0026#39;/^\\s*ssl_certificate/d\u0026#39; /etc/nginx/templates/ssl.tmpl sudo mv /etc/nginx/templates/ssl.tmpl /etc/nginx/conf.d/ssl.conf Configuration Files # cache.conf # /etc/nginx/conf.d/cache.conf will look like this:\n/etc/nginx/conf.d/cache.confnginx map $sent_http_content_type $expires { default off; application/javascript 1d; text/javascript 1d; application/x-javascript 1d; text/css 1d; ~image/ 1d; } expires $expires; Note map only defines the $expires variable. For the variable to be used, the expires $expires; line at the bottom is needed; without it the map has no effect.\nheaders.conf # Let\u0026rsquo;s edit /etc/nginx/conf.d/headers.conf like this:\n/etc/nginx/conf.d/headers.confnginx add_header Strict-Transport-Security \u0026#34;max-age=31536000\u0026#34; always; add_header X-Frame-Options sameorigin always; add_header X-Content-Type-Options nosniff always; add_header X-Permitted-Cross-Domain-Policies none always; add_header Referrer-Policy strict-origin always; Note Without the always parameter, NGINX adds the headers only to successful and redirect responses (200, 301, 304 and so on); it doesn\u0026rsquo;t send them with 403, 404 and 5xx responses.\nNote We removed the Content-Security-Policy header iRedMail set. Its value, default-src https: data: 'unsafe-inline' 'unsafe-eval', allows every HTTPS source, inline scripts and eval, so it gives almost no protection against XSS. On the other hand, because it is set at the http level, it goes to every application behind NGINX, and since it blocks blob: and wss: sources it can break applications. Applications that need a CSP (for example Vaultwarden) send their own header.\nVirtual Hosts # 00-default.conf # Expected behavior: redirect every request except the acme challenge to 443/HTTPS.\nWe add the default_server parameter to the listen 80 and listen [::]:80 directives in the current configuration:\n/etc/nginx/vhost.d/00-default.confnginx server { listen 80 default_server; listen [::]:80 default_server; server_name _; # Allow ACME challenge to be served over HTTP (don\u0026#39;t redirect to HTTPS). location ~* ^/.well-known/acme-challenge/ { root /opt/www/well_known; try_files $uri =404; allow all; } # Redirect all insecure http requests to https location / { return 301 https://$host$request_uri; } } 00-default-ssl.conf # Expected behavior: there will be a separate definition for each virtual host, so this one takes the requests that no virtual host catches.\nWe edit /etc/nginx/vhost.d/00-default-ssl.conf like this:\n/etc/nginx/vhost.d/00-default-ssl.confnginx server { listen 443 ssl default_server; listen [::]:443 ssl default_server; server_name _; ssl_reject_handshake on; } If no server_name (SNI) matches an incoming request, the TLS handshake is rejected.\nAs we said in the understanding part, the templates that used to be included here are no longer used.\nWarning After this configuration, HTTPS requests to names that have no virtual host (for example https://xenonly.com, or straight to the IP address) are rejected. The /mail and /iredadmin addresses from 2 Mail Server Setup are now used through the subdomains below.\nvhost_mail.xenonly.com.conf # We\u0026rsquo;ll use it to serve Roundcube Webmail. Let\u0026rsquo;s create /etc/nginx/vhost.d/vhost_mail.xenonly.com.conf like this:\n/etc/nginx/vhost.d/vhost_mail.xenonly.com.confnginx server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name mail.xenonly.com; ssl_certificate /etc/letsencrypt/live/mail.xenonly.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/mail.xenonly.com/privkey.pem; include /etc/nginx/templates/misc.tmpl; include /etc/nginx/templates/roundcube-subdomain.tmpl; } Note We got the certificate in 2.1 Setting Up SSL for the Mail Server, so we don\u0026rsquo;t get it again.\nTip Using a subdomain is purely a personal choice; it can also be served on a path like /mail.\nNote If we need to serve the webmail for more than one domain, each domain will have its own certificate, so we need to create a separate virtual host or add a new server block to this file.\nvhost_iredadmin.xenonly.com.conf # First let\u0026rsquo;s get the certificate:\nbash sudo certbot certonly --webroot -w /opt/www/well_known -d iredadmin.xenonly.com Note The deploy hook we created in 2.1 Setting Up SSL for the Mail Server reloads NGINX when the certificate is renewed.\nThen let\u0026rsquo;s create /etc/nginx/vhost.d/vhost_iredadmin.xenonly.com.conf like this:\n/etc/nginx/vhost.d/vhost_iredadmin.xenonly.com.confnginx server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name iredadmin.xenonly.com; ssl_certificate /etc/letsencrypt/live/iredadmin.xenonly.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/iredadmin.xenonly.com/privkey.pem; include /etc/nginx/templates/misc.tmpl; include /etc/nginx/templates/iredadmin-subdomain.tmpl; } Tip Using a subdomain is purely a personal choice; it can also be served on the /iredadmin path.\nNote It is an admin panel and doesn\u0026rsquo;t need to be reached from outside, so it can be made reachable only over the VPN. We\u0026rsquo;ll do that in 7.2 Putting Services Behind the VPN.\nDeleting the Unused Templates # The templates we said won\u0026rsquo;t be used in the understanding part:\nnetdata.tmpl netdata-subdomain.tmpl sogo.tmpl sogo-subdomain.tmpl adminer.tmpl stub_status.tmpl redirect_to_https.tmpl php-catchall.tmpl iredadmin.tmpl hsts.tmpl bash cd /etc/nginx/templates sudo rm -f netdata.tmpl netdata-subdomain.tmpl sogo.tmpl sogo-subdomain.tmpl adminer.tmpl sudo rm -f stub_status.tmpl redirect_to_https.tmpl php-catchall.tmpl iredadmin.tmpl hsts.tmpl Note Right now NGINX serves only Roundcube webmail and the iRedAdmin panel. More sites will come later and we\u0026rsquo;ll add their definitions too. That\u0026rsquo;s it for now.\nChecking # Let\u0026rsquo;s check the configuration and restart the service:\nbash sudo nginx -t sudo systemctl restart nginx Troubleshooting # If nginx -t gives an error, the problem is most likely invisible or formatted characters that got mixed into the configuration text while copying it from the document.\nbash sudo cat -A /etc/nginx/vhost.d/\u0026lt;FILE\u0026gt;.conf | head With this command we can check whether the problem comes from character formatting. Non-breaking space (NBSP) characters show up as M-BM- in the lines.\nbash sudo sed -i \u0026#39;s/\\xC2\\xA0/ /g\u0026#39; /etc/nginx/vhost.d/\u0026lt;FILE\u0026gt;.conf And with this command we can fix it.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/nginx/","section":"Self Hosting","summary":" Requirements 2 Mail Server Setup and 2.1 Setting Up SSL for the Mail Server must be done. Assumptions\nNGINX was installed and configured by iRedMail (version 1.26 from the Rocky Linux 10 repository). A and AAAA records exist for mail.xenonly.com and iredadmin.xenonly.com. Commands are run on the server with root rights (sudo). ","title":"NGINX Configuration","type":"self-hosting"},{"content":" Requirements 2 Mail Server Setup must be done. Assumptions\nThe example alias forwards abuse@xenonly.com to the info@xenonly.com account. Commands are run on the server with root rights (sudo). In this part we\u0026rsquo;ll make a few settings that the mail server doesn\u0026rsquo;t need, but that are useful.\nSetting Up an Alias # An alias is an address that has no mailbox of its own and forwards incoming mail to one or more accounts. For example, we want mail sent to abuse@xenonly.com to land in the info@xenonly.com account.\nNote The open-source version of iRedAdmin has no alias management (the Add → Alias menu is only in iRedAdmin-Pro). So we\u0026rsquo;ll add the alias directly to the vmail database.\nLet\u0026rsquo;s connect to the vmail database in the MariaDB on the host:\nbash sudo mariadb vmail Let\u0026rsquo;s add the alias and the account it forwards to:\nsql INSERT INTO alias (address, domain, active) VALUES (\u0026#39;abuse@xenonly.com\u0026#39;, \u0026#39;xenonly.com\u0026#39;, 1); INSERT INTO forwardings (address, forwarding, domain, dest_domain, is_list, active) VALUES (\u0026#39;abuse@xenonly.com\u0026#39;, \u0026#39;info@xenonly.com\u0026#39;, \u0026#39;xenonly.com\u0026#39;, \u0026#39;xenonly.com\u0026#39;, 1, 1); exit alias table: The alias address itself. forwardings table: The address the alias\u0026rsquo;s mail goes to. To forward to more than one account, add a separate row for each account. is_list = 1: Marks this row as an alias membership. Note Postfix looks up the addresses in the database, so there is no need to restart any service.\nLet\u0026rsquo;s send a test mail to abuse@xenonly.com; it should land in the info@xenonly.com account.\nAuto-Completing the Roundcube Username # To log in to Roundcube, you have to type the full email address as the username. So that typing only info is completed to info@xenonly.com, let\u0026rsquo;s add the line below to the end of /opt/www/roundcubemail/config/config.inc.php:\n/opt/www/roundcubemail/config/config.inc.phpphp $config[\u0026#39;username_domain\u0026#39;] = \u0026#39;xenonly.com\u0026#39;; Note This setting is only for the Roundcube login screen. Users of another domain (for example info@example.com) still type the full address. In IMAP clients, the username is always the full address too (see 2.3 Using a Mail Client).\nPHP reads the configuration on every request, so there is no need to restart any service.\nChecking for Plain Text Passwords # In the setup wizard we enter two passwords: the MariaDB root password and the postmaster password. On top of these, iRedMail creates its own random passwords for the database users of the services. The install script writes all of these passwords in plain text to a few places.\nIn this section we\u0026rsquo;ll look at which password is kept where, which service really uses it, and how to get rid of the plain text copies.\nWhere the Passwords Are Kept # Place Content Does a service use it? /opt/iRedMail-1.8.8/iRedMail.tips All passwords No, it is only for information /opt/iRedMail-1.8.8/config The wizard\u0026rsquo;s answers and all passwords No. The install script reads it so it doesn\u0026rsquo;t ask the questions again if it runs again in the same directory; after the installation it is not needed The Details of this iRedMail installation mail in the postmaster mailbox The content of iRedMail.tips No /root/.iredmail/kv/ A separate file for each password No, no part of iRedMail reads this directory /root/.my.cnf Only the MariaDB root password Yes, see below /root/.my.cnf-\u0026lt;user\u0026gt; The passwords of the service database users No, it is there so root can connect as these users easily The configuration files of the services (/etc/postfix/mysql/, Roundcube, iRedAdmin, Amavis, iRedAPD and so on) Only that service\u0026rsquo;s own database password Yes, the services read the password from these files Which Password Is Used Where # Postmaster password: Used only for logging in (Roundcube, iRedAdmin, IMAP/SMTP). It is stored as a hash in the database; no service needs it in plain text. The plain text copies:\niRedMail.tips config /root/.iredmail/kv/first_domain_admin_password The installation mail MariaDB root password: No mail service uses this password; every service has its own database user. Only these use it, through /root/.my.cnf:\nThe mariadb and mariadb-dump commands run with root rights (for example the sudo mariadb commands in this part and in 2.4 Moving the Mail Server) The database backup script that runs every night at 03:30 (/var/vmail/backup/backup_mysql.sh) The plain text copies: iRedMail.tips, config, /root/.iredmail/kv/sql_user_root, the installation mail and /root/.my.cnf.\nService passwords: The passwords of the vmail, vmailadmin, roundcube, amavisd, iredadmin, iredapd and fail2ban database users, Roundcube\u0026rsquo;s encryption key (roundcube_des_key) and iRedAPD\u0026rsquo;s SRS key (iredapd_srs_secret). They are all random and used in the services\u0026rsquo; own configuration files; we don\u0026rsquo;t touch them.\nNote The wizard asks for the MariaDB root password and the postmaster password separately and suggests a random sample password for both. If the same password was entered for both, you\u0026rsquo;ll see the postmaster password in /root/.my.cnf, but the password in that file is the MariaDB root password.\nCleaning Up # 1. Deleting the Copies Kept for Information # If needed, after saving the passwords in a password manager (for example 9 Vaultwarden Setup), let\u0026rsquo;s delete the files in the installation directory:\nbash sudo rm /opt/iRedMail-1.8.8/iRedMail.tips /opt/iRedMail-1.8.8/config sudo chmod 700 /opt/iRedMail-1.8.8 sudo rm /opt/1.8.8.tar.gz Let\u0026rsquo;s delete the copies of the two passwords we typed in from the /root/.iredmail/kv/ directory:\nbash sudo rm /root/.iredmail/kv/first_domain_admin_password /root/.iredmail/kv/sql_user_root Note The files left in the directory are the random service passwords. They are not used anywhere else and only root can read them, so we keep them; if you ever need a service\u0026rsquo;s database password, you can look it up here.\nLet\u0026rsquo;s log in to Roundcube as postmaster@xenonly.com, delete the mail with the subject Details of this iRedMail installation and empty the trash. Let\u0026rsquo;s check that the mail is completely gone from the server:\nbash sudo find /var/vmail -name \u0026#39;details.eml*\u0026#39; # output should be empty 2. Changing the MariaDB Root Password # If the MariaDB root password was not random (for example if it is the same as the postmaster password, or a password we also use somewhere else), it should be changed. Only /root/.my.cnf uses this password, so it is enough to create a new random password and update it in the database and in this file.\nFirst let\u0026rsquo;s see which hosts the root user is defined for:\nbash sudo mariadb -e \u0026#34;SELECT user, host FROM mysql.user WHERE user=\u0026#39;root\u0026#39;;\u0026#34; The output should have only the root | localhost row. If there are other rows, repeat the SET PASSWORD command below for each of them.\nbash PW=$(openssl rand -hex 24) sudo mariadb -e \u0026#34;SET PASSWORD FOR \u0026#39;root\u0026#39;@\u0026#39;localhost\u0026#39; = PASSWORD(\u0026#39;$PW\u0026#39;);\u0026#34; sudo sed -i \u0026#34;s/^password=.*/password=\\\u0026#34;$PW\\\u0026#34;/\u0026#34; /root/.my.cnf unset PW The command history gets $PW, not the password itself, so the new password doesn\u0026rsquo;t show up in the history. The order matters: the second command connects with the old password (through /root/.my.cnf) and changes the password, the third command updates the file with the new password. Note We don\u0026rsquo;t need to write the new password down anywhere. The root user connects to MariaDB through /root/.my.cnf; if you ever need the password, you can look at it with sudo cat /root/.my.cnf.\nLet\u0026rsquo;s check that root can still connect and that the backup script works:\nbash sudo mariadb -e \u0026#34;SELECT CURRENT_USER();\u0026#34; # root@localhost sudo bash /var/vmail/backup/backup_mysql.sh # should take a backup without errors The backups are written to the /var/vmail/backup/mysql/\u0026lt;year\u0026gt;/\u0026lt;month\u0026gt;/\u0026lt;day\u0026gt;/ directory.\nSending Limit (Throttle) # Every account that can log in to SMTP can send as much mail as it wants from its own address. An account with a stolen password, or a service account in a compromised container, can send thousands of spam mails in a short time. All domains send from the same IP, so the damage doesn\u0026rsquo;t stay with that account: the IP gets on blocklists and the mail of every domain starts to be rejected.\nThe throttle plugin of iRedAPD, which comes with iRedMail, limits how many mails an account can send in a given time. In this section we\u0026rsquo;ll set a default limit for all accounts.\nNote The open-source version of iRedAdmin has no throttle settings; they are only in iRedAdmin-Pro. So we\u0026rsquo;ll add the settings directly to the iredapd database.\n1. First Checks # Let\u0026rsquo;s check that the throttle plugin is on:\nbash sudo grep \u0026#39;^plugins\u0026#39; /opt/iredapd/settings.py throttle should be in the list. If it is not, add it to the list and restart iRedAPD (sudo systemctl restart iredapd).\nThe plugin counts sent mail after the whole mail has been received (at the END-OF-MESSAGE stage). For this, Postfix must also ask iRedAPD at this stage:\nbash sudo postconf smtpd_end_of_data_restrictions # check_policy_service ... 127.0.0.1 ... 7777 sudo postconf -P | grep -E \u0026#39;^(submission|smtps)/.*end_of_data\u0026#39; # output should be empty The first command: The output should show iRedAPD\u0026rsquo;s address (127.0.0.1, port 7777). If it is empty, the limit doesn\u0026rsquo;t apply to any mail. The second command: Checks whether the 587 (submission) or 465 (smtps) service in master.cf overrides this setting. If it does, the limit doesn\u0026rsquo;t apply to mail sent by clients. Let\u0026rsquo;s look at the current throttle settings:\nbash sudo mariadb iredapd -e \u0026#34;SELECT * FROM throttle;\u0026#34; On a clean installation the table is empty. That means no account has a limit.\n2. Adding the Default Limit # Let\u0026rsquo;s connect to the iredapd database in the MariaDB on the host:\nbash sudo mariadb iredapd Let\u0026rsquo;s add a limit of 300 mails a day for all accounts:\nsql INSERT INTO throttle (account, kind, priority, period, max_msgs) VALUES (\u0026#39;@.\u0026#39;, \u0026#39;outbound\u0026#39;, 0, 86400, 300); exit account = '@.': All accounts. The dot at the end is needed. The limit applies to each account separately; mail sent by one account doesn\u0026rsquo;t count against the limit of the others. kind = 'outbound': Mail sent after logging in (SASL). Clients like Thunderbird, Roundcube and the containers all log in on port 587 or 465 to send, so this covers all of them. period = 86400: The time window in seconds (1 day). It starts with the account\u0026rsquo;s first mail; when it ends, the counter resets. max_msgs = 300: How many mails can be sent in this time. It counts per recipient: a mail with 10 recipients counts as 10 mails. priority = 0: If more than one setting matches an account, the one with the higher priority wins. We\u0026rsquo;ll add account-specific settings with 100. The columns we didn\u0026rsquo;t add (msg_size, max_quota, max_rcpts): They stay at -1. -1 means the value is taken from a setting with a lower priority. There is no setting with a lower priority, so these limits don\u0026rsquo;t apply. The mail size is already limited by Postfix\u0026rsquo;s message_size_limit setting. Note Mail to addresses in the same domain is not counted (THROTTLE_BYPASS_SAME_DOMAIN, True by default). For example, a mail from info@xenonly.com to abuse@xenonly.com doesn\u0026rsquo;t count against the limit. Spam is sent to the outside, so this doesn\u0026rsquo;t open a hole.\niRedAPD reads the settings from the database for every mail, so there is no need to restart the service.\nNote 300 is a value picked for personal use. With this limit, an account with a stolen password can send mail to at most 300 recipients a day. Even if nobody notices the account, the chance of the IP getting on a blocklist becomes very low. Accounts that need to send more can get a separate limit as below.\n3. A Limit for One Account # Service accounts (for example vaultwarden@xenonly.com from 9 Vaultwarden Setup) send a few mails a day. Let\u0026rsquo;s give them a lower limit:\nsql INSERT INTO throttle (account, kind, priority, period, max_msgs) VALUES (\u0026#39;vaultwarden@xenonly.com\u0026#39;, \u0026#39;outbound\u0026#39;, 100, 86400, 50); Because of priority = 100, this setting is used for this account instead of the default one. In the same way, an account that needs to send more can get a higher limit. To remove an account\u0026rsquo;s limit completely, set max_msgs = 0.\nTo change an existing limit:\nsql UPDATE throttle SET max_msgs = 100 WHERE account = \u0026#39;vaultwarden@xenonly.com\u0026#39; AND kind = \u0026#39;outbound\u0026#39;; To reset the counter of an account that hit its limit before the time is up:\nbash sudo mariadb iredapd -e \u0026#34;DELETE FROM throttle_tracking WHERE account = \u0026#39;info@xenonly.com\u0026#39;;\u0026#34; 4. Test # Let\u0026rsquo;s test that the limit works with a low limit. Let\u0026rsquo;s add a temporary limit of 2 mails an hour for info@xenonly.com:\nbash sudo mariadb iredapd -e \u0026#34;INSERT INTO throttle (account, kind, priority, period, max_msgs) VALUES (\u0026#39;info@xenonly.com\u0026#39;, \u0026#39;outbound\u0026#39;, 100, 3600, 2);\u0026#34; From Roundcube, as info@xenonly.com, let\u0026rsquo;s send three mails one by one to an address in another domain (for example our personal Gmail address). The first two mails should go out, and Roundcube should show an error on the third.\nImportant The test must go to another domain. Mail to addresses in the same domain is not counted, so mail sent to xenonly.com addresses doesn\u0026rsquo;t fill the limit.\nWe can see the rejected mail in the iRedAPD log and in the account\u0026rsquo;s counter:\nbash sudo grep -i exceeded /var/log/iredapd/iredapd.log | tail -n 3 sudo mariadb iredapd -e \u0026#34;SELECT account, cur_msgs, FROM_UNIXTIME(init_time) FROM throttle_tracking;\u0026#34; After the test, let\u0026rsquo;s delete the temporary limit and its counter:\nbash sudo mariadb iredapd -e \u0026#34; DELETE FROM throttle_tracking WHERE tid = (SELECT id FROM throttle WHERE account = \u0026#39;info@xenonly.com\u0026#39; AND kind = \u0026#39;outbound\u0026#39;); DELETE FROM throttle WHERE account = \u0026#39;info@xenonly.com\u0026#39; AND kind = \u0026#39;outbound\u0026#39;;\u0026#34; Note The counter table (throttle_tracking) is tied to the settings table with a foreign key. If the counter is not deleted first, the setting can\u0026rsquo;t be deleted.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/mail-server-extras/","section":"Self Hosting","summary":" Requirements 2 Mail Server Setup must be done. Assumptions\nThe example alias forwards abuse@xenonly.com to the info@xenonly.com account. Commands are run on the server with root rights (sudo). ","title":"Mail Server: Extra Settings","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/iredmail/","section":"Tags","summary":"","title":"iredmail","type":"tags"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/mail/","section":"Tags","summary":"","title":"mail","type":"tags"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/roundcube/","section":"Tags","summary":"","title":"roundcube","type":"tags"},{"content":" Requirements 2 Mail Server Setup must be done on the new server. You must have root access to the old server. Assumptions\nThe old server was also set up with iRedMail (MariaDB + /var/vmail). There is no valuable data on the new server yet; the vmail database of the new installation can be overwritten. Commands are run with root rights (sudo). The server each command runs on is written before it. In this part we\u0026rsquo;ll look at what has to go where when moving an existing mail service to another server, or when restoring it from a backup.\nWarning The move must be done carefully and step by step. This document has the steps I used for my own move. Systems set up in a different way, or with different versions, may need different steps.\nUnderstanding Our Setup # In our system the mail data is kept in two places: in the MariaDB database and on the file system (Maildir).\nIn the database: Domains, users, mailbox paths, aliases, forwardings and so on. On the file system (/var/vmail): The mail itself. The inbox, sent items and all the other folders, and the users\u0026rsquo; Sieve filters. I set up the mail service on a new server from scratch, so there is no valuable data in the new mail service. So my plan is to move the whole vmail database and the /var/vmail/vmail1 directory from the old server to the new one.\nNote Roundcube\u0026rsquo;s own database (roundcubemail: address books, identities, signatures, user settings) is not part of this plan. If you want to keep this data of the users too, move the roundcubemail database the same way. If the Roundcube versions are different, a schema update may also be needed.\nWarning Mail that reaches the old server during the move is not copied to the new server. To avoid this, you can stop the mail services on the old server with sudo systemctl stop postfix dovecot before starting, or run rsync once more after all the steps to copy the last changes.\nMoving the Old Data # Comparing the Database Schema # Let\u0026rsquo;s check whether the schemas of the old and new vmail databases differ because of a version difference.\nOn the old server:\nbash sudo mariadb-dump --no-data --skip-comments --skip-dump-date \\ --result-file=/root/vmail-old-schema.sql vmail On the new server:\nbash sudo mariadb-dump --no-data --skip-comments --skip-dump-date \\ --result-file=/root/vmail-new-schema.sql vmail Note We use --result-file instead of redirecting the output with \u0026gt; /root/.... The redirect is done by the normal user\u0026rsquo;s shell, not by sudo, so it can\u0026rsquo;t write to the /root directory.\nWith these commands we took the database schemas. Next, let\u0026rsquo;s get both files to the same place with scp or another way that suits you, and look at the differences:\nbash diff -u vmail-old-schema.sql vmail-new-schema.sql In my case there was no difference, so I decided to move the whole database.\nMoving the Database # On the old server we take a dump of the database:\nbash sudo mariadb-dump --single-transaction \\ --routines --triggers --events \\ --result-file=/root/vmail-old.sql \\ --databases vmail We copy the file /root/vmail-old.sql to the new server.\nOn the new server we first back up the current database:\nbash sudo mariadb-dump --single-transaction \\ --routines --triggers --events \\ --result-file=/root/vmail-backup.sql \\ --databases vmail Then we import the old database:\nbash sudo sh -c \u0026#39;mariadb \u0026lt; /root/vmail-old.sql\u0026#39; Note An input redirect is also done in the normal user\u0026rsquo;s shell, so it can\u0026rsquo;t read the file under /root. That\u0026rsquo;s why we run the command in a single root shell with sudo sh -c.\nWe can check the result with the commands below:\nbash sudo mariadb -e \u0026#34;SELECT domain FROM vmail.domain;\u0026#34; sudo mariadb -e \u0026#34; SELECT username, domain, maildir FROM vmail.mailbox; \u0026#34; Moving the Maildir # On the old server we send the Maildir to the new server with rsync:\nbash sudo rsync -aHAX --numeric-ids --info=progress2 /var/vmail/vmail1/ root@\u0026lt;NEW_SERVER_IP\u0026gt;:/var/vmail/vmail1/ Warning --numeric-ids copies file ownership by uid/gid number instead of by username. So the uid/gid of the vmail user must be the same on both servers; you can check it with id vmail on both.\nNote The users\u0026rsquo; Sieve filters are kept in their own mailbox directories (~/sieve), so they move together with vmail1. To see whether there is any other directory under /var/vmail that needs to move, run ls /var/vmail on the old server.\nWarning Rsync sends the files over SSH as the root user. Because of the PermitRootLogin no setting from 1 Post-Install Configuration, root can\u0026rsquo;t log in over SSH. Just for this job, set PermitRootLogin prohibit-password for a while in /etc/ssh/sshd_config.d/00-hardening.conf on the new server, and add the old server\u0026rsquo;s root public key to /root/.ssh/authorized_keys. Undo both after the transfer.\nNote This method works while SSH is reachable from the internet. After 7.2 Putting Services Behind the VPN, SSH is reachable only over the VPN, so the old server can\u0026rsquo;t connect to the new one; in that case pull the data from the new server, as in 10.1 Moving an Old WordPress Site into This Setup.\nMoving the DKIM Keys # We also need to move the DKIM keys of the domains on the old server:\nWe copy the /var/lib/dkim/*.pem files on the old server to the same directory on the new server and fix their permissions (chown amavis:amavis, chmod 0400). We add each domain to /etc/amavisd/amavisd.conf as explained in 2.2 Adding a New Domain to the Mail Server. Restarting the Services # On the new server let\u0026rsquo;s restart the services:\nbash sudo systemctl restart postfix dovecot amavisd Recalculating the Mailbox Quotas # bash sudo doveadm quota recalc -A With this command we recalculate the current usage of the mailboxes.\nFinal Checks # For every domain, check that the DKIM public key on the server matches the record in DNS:\nbash sudo amavisd showkeys \u0026lt;DOMAIN\u0026gt; | awk -F\u0026#39;\u0026#34;\u0026#39; \u0026#39;/^[[:space:]]*\u0026#34;/ {printf \u0026#34;%s\u0026#34;, $2} END {print \u0026#34;\u0026#34;}\u0026#39; Update the DNS records of the moved domains for the new server:\nThe IP addresses in the SPF records must be the new server\u0026rsquo;s IP addresses. The MX records must point to the new mail server (mail.xenonly.com). The PTR record of the new server must be set (see 2 Mail Server Setup). ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/mail-server-migration/","section":"Self Hosting","summary":" Requirements 2 Mail Server Setup must be done on the new server. You must have root access to the old server. Assumptions\nThe old server was also set up with iRedMail (MariaDB + /var/vmail). There is no valuable data on the new server yet; the vmail database of the new installation can be overwritten. Commands are run with root rights (sudo). The server each command runs on is written before it. ","title":"Moving the Mail Server","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/imap/","section":"Tags","summary":"","title":"imap","type":"tags"},{"content":" Requirements 2 Mail Server Setup and 2.1 Setting Up SSL for the Mail Server must be done. Assumptions\nThe mail server\u0026rsquo;s name is mail.xenonly.com and the example user is info@xenonly.com. The settings in this part are made in the mail client on a personal computer or phone, not on the server. Our mail server is installed and working. We can log in with the users we created through Roundcube Webmail: at https://xenonly.com/mail before 3 NGINX Configuration, and at https://mail.xenonly.com after it.\nWe can also connect to the mail accounts with any mail client that supports IMAP, like Thunderbird, Outlook, iOS Mail or Thunderbird for Android.\nConnection Details # Note Whatever domain is used, the server address is always mail.xenonly.com.\nServer Port Security Authentication Incoming (IMAP) mail.xenonly.com 993 SSL/TLS Normal password Outgoing (SMTP) mail.xenonly.com 587 STARTTLS Normal password Username: The full email address (for example info@xenonly.com). If you write only info, the login fails. Password: The account\u0026rsquo;s password. Note We use IMAP because the POP3 ports are not opened in the firewall (5 Firewalld Configuration). With IMAP the mail stays on the server and looks the same on every device.\nAdding an Account in Thunderbird # We go to Account Settings → Account Actions → Add Mail Account. We enter the name, email address and password, and click Continue. Thunderbird tries to find the settings by itself. If it can\u0026rsquo;t, or if the settings it finds don\u0026rsquo;t match the table above, we click Configure manually and enter the details as in the table. We click Re-test, then Done. Common Problems # Certificate warning: A name other than mail.xenonly.com (for example mail.example.com) may have been entered as the server address. The certificate is valid only for mail.xenonly.com. Authentication error: Make sure the full email address is entered as the username. Mail can\u0026rsquo;t be sent: Port 25 may have been chosen for the outgoing server. That port is for server-to-server traffic; clients should use 587. ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/mail-clients/","section":"Self Hosting","summary":" Requirements 2 Mail Server Setup and 2.1 Setting Up SSL for the Mail Server must be done. Assumptions\nThe mail server’s name is mail.xenonly.com and the example user is info@xenonly.com. The settings in this part are made in the mail client on a personal computer or phone, not on the server. ","title":"Mail Server: Using a Mail Client","type":"self-hosting"},{"content":" Requirements 2 Mail Server Setup must be done. Assumptions\nThe main mail server is mail.xenonly.com; the example domain we add is example.com. You can edit the DNS records of example.com. The mail records it needs are explained in this part. iRedAdmin is reached at https://xenonly.com/iredadmin before 3 NGINX Configuration, and at https://iredadmin.xenonly.com after it (only over the VPN after 7.2 Putting Services Behind the VPN). Commands are run on the server with root rights (sudo). In the current setup, mail.xenonly.com is the name of this server\u0026rsquo;s mail server, and xenonly.com is the first domain the server sends and receives mail for. The settings behind this fall into two groups.\nServer identity (mail.xenonly.com, shared by all domains):\nA and AAAA records Reverse DNS (PTR) record for IPv4 and IPv6 Domain identity (xenonly.com, separate for each domain):\nMX record SPF record DKIM record DMARC record Note Giving each domain its own mail server identity (its own server name, PTR record and IPv4 address) needs extra IP addresses and extra configuration on a single VPS. Unless there is a special reason for it, it is not worth it.\nIn our design the main mail server is mail.xenonly.com. The domains added later also use this server to send and receive mail. For each of them, only their own MX, SPF, DKIM and DMARC records are set.\nWhat to Do for Each Domain # Adding the domain to the server in iRedAdmin Creating the DKIM key on the server and adding it to the Amavis configuration and to DNS Adding the MX record Adding the SPF record Adding the DMARC record and creating the report account Steps # 1. Adding the Domain to the Server in iRedAdmin # We log in to the iRedAdmin panel and add the domain example.com by following Add → Domain.\nThen, following Add → User, we create at least one user for example.com (for example info@example.com). We\u0026rsquo;ll use this account at the end to send a test mail.\n2. Creating the DKIM Key on the Server and Adding It to the Amavis Configuration and to DNS # Creating the DKIM Key # Let\u0026rsquo;s create the DKIM key with the commands below:\nbash sudo amavisd genrsa /var/lib/dkim/example.com.pem 2048 sudo chown amavis:amavis /var/lib/dkim/example.com.pem sudo chmod 0400 /var/lib/dkim/example.com.pem Editing the Amavis Configuration # We open /etc/amavisd/amavisd.conf:\nUnder # Add dkim_key here, we add our new key in the format shown there. The key of the primary domain was added automatically during the installation. We comment out the catch-all part under @dkim_signature_options_bysender_maps. Under Per-domain dkim key, we add our domains in the format shown there. Important The catch-all entry signs the mail of all domains with the key of the first domain. Then mail from example.com is signed with d=xenonly.com and fails the adkim=s (strict matching) check in DMARC. That\u0026rsquo;s why we define each domain with its own key.\nThe file should look roughly like this:\n/etc/amavisd/amavisd.confperl # Add dkim_key here. dkim_key(\u0026#39;example.com\u0026#39;, \u0026#39;dkim\u0026#39;, \u0026#39;/var/lib/dkim/example.com.pem\u0026#39;); dkim_key(\u0026#39;xenonly.com\u0026#39;, \u0026#39;dkim\u0026#39;, \u0026#39;/var/lib/dkim/xenonly.com.pem\u0026#39;); @dkim_signature_options_bysender_maps = ({ # \u0026#39;d\u0026#39; defaults to a domain of an author/sender address, # \u0026#39;s\u0026#39; defaults to whatever selector is offered by a matching key # Per-domain dkim key #\u0026#34;domain.com\u0026#34; =\u0026gt; { d =\u0026gt; \u0026#34;domain.com\u0026#34;, a =\u0026gt; \u0026#39;rsa-sha256\u0026#39;, ttl =\u0026gt; 10*24*3600 }, \u0026#34;example.com\u0026#34; =\u0026gt; { d =\u0026gt; \u0026#34;example.com\u0026#34;, a =\u0026gt; \u0026#39;rsa-sha256\u0026#39;, ttl =\u0026gt; 10*24*3600 }, \u0026#34;xenonly.com\u0026#34; =\u0026gt; { d =\u0026gt; \u0026#34;xenonly.com\u0026#34;, a =\u0026gt; \u0026#39;rsa-sha256\u0026#39;, ttl =\u0026gt; 10*24*3600 }, # catch-all (one dkim key for all domains) #\u0026#39;.\u0026#39; =\u0026gt; {d =\u0026gt; \u0026#39;xenonly.com\u0026#39;, # a =\u0026gt; \u0026#39;rsa-sha256\u0026#39;, # c =\u0026gt; \u0026#39;relaxed/simple\u0026#39;, # ttl =\u0026gt; 30*24*3600 }, }); After editing, let\u0026rsquo;s restart the service:\nbash sudo systemctl restart amavisd.service Adding the DKIM Key to DNS # To see the existing keys:\nbash sudo amavisd showkeys To get a single-line output that can go straight into the DNS record:\nbash sudo amavisd showkeys example.com | awk -F\u0026#39;\u0026#34;\u0026#39; \u0026#39;/^[[:space:]]*\u0026#34;/ {printf \u0026#34;%s\u0026#34;, $2} END {print \u0026#34;\u0026#34;}\u0026#39; Note The value added to DNS must be a single line. amavisd showkeys splits the key over several lines; the command above joins them.\nWe add this output to the DNS of example.com like this:\nName Type Content What It Means dkim._domainkey TXT \u0026lt;DKIM_KEY\u0026gt; Lets receivers verify the mail signed by Amavis After the DNS record has spread, let\u0026rsquo;s check that the key on the server matches the record in DNS. The output should show =\u0026gt; pass:\nbash sudo amavisd testkeys example.com 3. Adding the MX Record # In the panel of the provider that manages the DNS of example.com, let\u0026rsquo;s add the MX record below:\nName Type Content example.com MX mail.xenonly.com 4. Adding the SPF Record # In the same panel, let\u0026rsquo;s add the SPF record below:\nName Type Content example.com TXT \u0026quot;v=spf1 mx a ip4:\u0026lt;SERVER_IPV4\u0026gt; ip6:\u0026lt;SERVER_IPV6\u0026gt; ~all\u0026quot; Tip The a mechanism also allows the server in the A record of example.com to send mail. If the website of example.com is on another server, that server gets the permission too; in that case you can remove a from the record.\n5. Adding the DMARC Record and Creating the Report Account # In the same panel, let\u0026rsquo;s add the DMARC record below:\nName Type Content _dmarc TXT \u0026quot;v=DMARC1; p=quarantine; sp=quarantine; np=reject; adkim=s; aspf=s; rua=mailto:dmarc@example.com\u0026quot; So that the reports can reach dmarc@example.com from the DMARC record, we create the user dmarc for example.com in iRedAdmin by following Add → User.\nCheck # Example DNS Records for example.com # The DNS records should look roughly like this:\nName Type Content What It Means example.com MX mail.xenonly.com Says which mail server incoming mail should go to dkim._domainkey TXT \u0026lt;DKIM_KEY\u0026gt; Lets receivers verify the mail signed by Amavis _dmarc TXT \u0026quot;v=DMARC1; p=quarantine; sp=quarantine; np=reject; adkim=s; aspf=s; rua=mailto:dmarc@example.com\u0026quot; Says what to do with mail that fails the SPF or DKIM check example.com TXT \u0026quot;v=spf1 mx a ip4:\u0026lt;SERVER_IPV4\u0026gt; ip6:\u0026lt;SERVER_IPV6\u0026gt; ~all\u0026quot; Says which servers may send mail for this domain Checking SPF, DKIM and DMARC with a Test Mail # Let\u0026rsquo;s log in to Roundcube as info@example.com and send a test mail to the address shown on https://www.mail-tester.com/. The expected result:\nYour lovely total: 10/10 ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/mail-server-new-domain/","section":"Self Hosting","summary":" Requirements 2 Mail Server Setup must be done. Assumptions\nThe main mail server is mail.xenonly.com; the example domain we add is example.com. You can edit the DNS records of example.com. The mail records it needs are explained in this part. iRedAdmin is reached at https://xenonly.com/iredadmin before 3 NGINX Configuration, and at https://iredadmin.xenonly.com after it (only over the VPN after 7.2 Putting Services Behind the VPN). Commands are run on the server with root rights (sudo). ","title":"Adding a New Domain to the Mail Server","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/dkim/","section":"Tags","summary":"","title":"dkim","type":"tags"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/dns/","section":"Tags","summary":"","title":"dns","type":"tags"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/certbot/","section":"Tags","summary":"","title":"certbot","type":"tags"},{"content":" Requirements 2 Mail Server Setup must be done. Assumptions\nThe A and AAAA records of mail.xenonly.com point to the server. Port 80 (HTTP) of the server is reachable from the internet (Firewalld is still off). Commands are run on the server with root rights (sudo). We finished setting up the mail server. Right now the system uses the self-signed certificate created during the iRedMail installation. Instead, we\u0026rsquo;ll get a Let\u0026rsquo;s Encrypt certificate for mail.xenonly.com and make the system use it.\nGetting a Certificate from Let\u0026rsquo;s Encrypt # certbot was installed in 1 Post-Install Configuration. We\u0026rsquo;ll get the certificate with the webroot method. For this method, the domain\u0026rsquo;s A record must point to the server and the server must listen on port 80 (HTTP).\nNGINX was installed during the iRedMail installation and is already configured for the Let\u0026rsquo;s Encrypt (ACME) check:\nbash sudo grep well_known /etc/nginx/sites-enabled/00-default.conf # root /opt/www/well_known; To get the certificate, running the command below is enough.\nNote On the first run it asks for an email address and for accepting the terms of service.\nbash sudo certbot certonly --webroot -w /opt/www/well_known -d mail.xenonly.com Certificate is saved at: /etc/letsencrypt/live/mail.xenonly.com/fullchain.pem Key is saved at: /etc/letsencrypt/live/mail.xenonly.com/privkey.pem The self-signed certificates iRedMail uses are at these paths:\nSSL cert keys (size: 4096): - /etc/pki/tls/certs/iRedMail.crt - /etc/pki/tls/private/iRedMail.key Let\u0026rsquo;s back up the old certificates:\nbash sudo mv /etc/pki/tls/certs/iRedMail.crt /etc/pki/tls/certs/iRedMail.crt.bak sudo mv /etc/pki/tls/private/iRedMail.key /etc/pki/tls/private/iRedMail.key.bak Then let\u0026rsquo;s create symbolic links for the new certificate with the commands below:\nbash sudo ln -s /etc/letsencrypt/live/mail.xenonly.com/fullchain.pem \\ /etc/pki/tls/certs/iRedMail.crt sudo ln -s /etc/letsencrypt/live/mail.xenonly.com/privkey.pem \\ /etc/pki/tls/private/iRedMail.key and restart the related services:\nbash sudo systemctl restart postfix dovecot nginx Certificate Renewal # Let\u0026rsquo;s Encrypt certificates are valid for 90 days. The certbot package comes with a systemd timer for renewal (certbot-renew.timer). Let\u0026rsquo;s make sure the timer is enabled:\nbash sudo systemctl enable --now certbot-renew.timer sudo systemctl is-enabled certbot-renew.timer # enabled We\u0026rsquo;ll also create a hook that reloads the services when the certificate is renewed. Let\u0026rsquo;s create the file /etc/letsencrypt/renewal-hooks/deploy/reload-mail.sh with the content below:\n/etc/letsencrypt/renewal-hooks/deploy/reload-mail.shbash #!/bin/bash set -e systemctl reload postfix dovecot if nginx -t; then systemctl reload nginx else echo \u0026#34;Nginx config test failed, reload skipped\u0026#34; \u0026gt;\u0026amp;2 exit 1 fi Note The hooks under renewal-hooks/deploy/ run for every renewed certificate, not only for the mail certificate. This is useful for us: when the other certificates we\u0026rsquo;ll get in the next parts (for example iredadmin.xenonly.com) are renewed, this hook also reloads NGINX. If you want Postfix and Dovecot to reload only when the mail certificate is renewed, you can check the $RENEWED_DOMAINS variable that certbot passes to the hook.\nLet\u0026rsquo;s make the hook executable:\nbash sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-mail.sh Let\u0026rsquo;s test that the renewal and the hook work:\nbash sudo certbot renew --dry-run sudo /etc/letsencrypt/renewal-hooks/deploy/reload-mail.sh Note --dry-run doesn\u0026rsquo;t run the deploy hooks, so we test the hook by running it by hand.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/mail-server-ssl/","section":"Self Hosting","summary":" Requirements 2 Mail Server Setup must be done. Assumptions\nThe A and AAAA records of mail.xenonly.com point to the server. Port 80 (HTTP) of the server is reachable from the internet (Firewalld is still off). Commands are run on the server with root rights (sudo). ","title":"Setting Up SSL for the Mail Server","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/ssl/","section":"Tags","summary":"","title":"ssl","type":"tags"},{"content":" Requirements 1 Post-Install Configuration must be done. iRedMail must be installed on a freshly installed server; this part installs the first service on the server. Assumptions\nThe name of the mail server (hostname) is set to mail.xenonly.com and the first mail domain is xenonly.com. A and AAAA records exist for xenonly.com and mail.xenonly.com. The other records mail needs (MX, SPF, DKIM, DMARC, PTR) are added in this part. Commands are run on the server with root rights (sudo). The DNS checks with dig are done from a personal computer. For mail we\u0026rsquo;ll mainly use Postfix and Dovecot. For the installation and the first configuration we\u0026rsquo;ll use the iRedMail install script.\nImportant iRedMail must be installed on a freshly installed server. That\u0026rsquo;s why iRedMail is the first thing we install after setting up the server. We\u0026rsquo;ll add the other services later and adjust the configuration of the services that clash with iRedMail to fit our needs.\nPreparation # Changing the Hostname # I\u0026rsquo;ll use mail.xenonly.com as the name of the mail server. The other domains added later will also send mail using this server name. Let\u0026rsquo;s change the hostname with the command below:\nbash sudo hostnamectl set-hostname mail.xenonly.com During the installation, iRedMail expects the hostname to resolve as a fully qualified domain name (FQDN). Let\u0026rsquo;s check it:\nbash hostname -f # mail.xenonly.com If the output is not mail.xenonly.com, let\u0026rsquo;s add the server name to the start of the 127.0.0.1 line in /etc/hosts:\n/etc/hosts 127.0.0.1 mail.xenonly.com mail localhost localhost.localdomain Turning Off SELinux # iRedMail says it doesn\u0026rsquo;t work with SELinux and recommends turning it off. This is the recommended way to turn it off on Rocky Linux 10:\nbash sudo grubby --update-kernel ALL --args selinux=0 After turning SELinux off with this command, let\u0026rsquo;s reboot the system:\nbash sudo reboot Downloading and Installing iRedMail # We get the download link of the latest release from https://www.iredmail.org/download.html. At the time of writing (November 2026), the latest release is 1.8.8.\nbash cd /opt sudo wget https://github.com/iredmail/iRedMail/archive/refs/tags/1.8.8.tar.gz sudo tar zxf 1.8.8.tar.gz cd iRedMail-1.8.8 sudo bash iRedMail.sh Note cd is a command of the shell itself, so it is run directly, not with sudo. The commands that write files run with sudo, so they can write under /opt.\nWith these commands we download and run the iRedMail installer. After the needed packages are installed, the setup wizard opens:\nWe continue with Yes and leave the mail storage directory at the default, /var/vmail. Web server → Nginx Database for the mail accounts → MariaDB We set a password for the MariaDB root user. This password is written to /root/.my.cnf and used by root\u0026rsquo;s database commands and by the backup script; it should be random and different from the postmaster password. First mail domain → xenonly.com. The important point here: this value must not be the server\u0026rsquo;s hostname (mail.xenonly.com). We set a password for the address postmaster@xenonly.com. This address and password will be used as the admin account. Warning Strong random passwords are recommended for both; the wizard shows a random sample password on both screens. After the installation, the passwords entered during the setup are written in plain text to a few files on the server. Where they are kept and how to clean them up is in 2.5 Extra Settings.\nNext we choose the optional components:\nWebmail → Roundcube Admin panel → iRedAdmin Security → Fail2ban These are already selected by default. I also remove the system monitoring service Netdata.\nWhen the wizard is done, it shows a summary like this:\n********************** Review your settings ***************************** ************************************************************************* * Storage base directory: /var/vmail * Mailboxes: * Daily backup of SQL/LDAP databases: * Store mail accounts in: MariaDB * Web server: Nginx * First mail domain name: xenonly.com * Mail domain admin: postmaster@xenonly.com * Additional components: Roundcubemail iRedAdmin Fail2ban We continue with y and the installation starts. During the installation there will be some questions about the configuration.\n\u0026lt; Question \u0026gt; Would you like to use firewall rules provided by iRedMail? \u0026lt; Question \u0026gt; File: /etc/firewalld/zones/iredmail.xml, with SSHD ports: 22. [Y|n] I answer this question with n. I\u0026rsquo;ll do the firewall settings myself in 5 Firewalld Configuration.\n\u0026lt; Question \u0026gt; Would you like to use MySQL configuration file shipped within iRedMail now? \u0026lt; Question \u0026gt; File: /etc/my.cnf. [Y|n] We confirm this question with Y.\nThe installation finishes with an output like this:\n******************************************************************** * URLs of installed web applications: * * - Roundcube webmail: https://mail.xenonly.com/mail/ * * - Web admin panel (iRedAdmin): https://mail.xenonly.com/iredadmin/ * * You can login to above links with below credential: * * - Username: postmaster@xenonly.com * - Password: *** * ******************************************************************** * Congratulations, mail server setup completed successfully. Please * read below file for more information: * * - /opt/iRedMail-1.8.8/iRedMail.tips * * And it\u0026#39;s sent to your mail account postmaster@xenonly.com. * ********************* WARNING ************************************** * * Please reboot your system to enable all mail services. * ******************************************************************** Then we reboot the system:\nbash sudo reboot After the Installation # DNS Settings # To add the DNS records, we go to the panel of the provider that manages the domain\u0026rsquo;s DNS.\nAt this point we\u0026rsquo;ll add the DNS records xenonly.com needs for the mail server. The records will look roughly like the ones below.\nWe\u0026rsquo;ll get the \u0026lt;DKIM_KEY\u0026gt; value in the DKIM Record section below.\nName Type Content What It Means xenonly.com A \u0026lt;SERVER_IPV4\u0026gt; IPv4 record for the domain xenonly.com AAAA \u0026lt;SERVER_IPV6\u0026gt; IPv6 record for the domain mail.xenonly.com A \u0026lt;SERVER_IPV4\u0026gt; IPv4 record for the mail server mail.xenonly.com AAAA \u0026lt;SERVER_IPV6\u0026gt; IPv6 record for the mail server xenonly.com MX mail.xenonly.com Says which mail server incoming mail should go to dkim._domainkey TXT \u0026lt;DKIM_KEY\u0026gt; Lets receivers verify the mail signed by Amavis _dmarc TXT \u0026quot;v=DMARC1; p=quarantine; sp=quarantine; np=reject; adkim=s; aspf=s; rua=mailto:dmarc@xenonly.com\u0026quot; Says what to do with mail that fails the SPF or DKIM check xenonly.com TXT \u0026quot;v=spf1 mx a ip4:\u0026lt;SERVER_IPV4\u0026gt; ip6:\u0026lt;SERVER_IPV6\u0026gt; ~all\u0026quot; Says which servers may send mail for this domain mail.xenonly.com TXT \u0026quot;v=spf1 a -all\u0026quot; SPF for the server\u0026rsquo;s HELO name; bounces with an empty sender address are checked against this name Note The dkim._domainkey and _dmarc values in the Name column are relative to the domain; the full names are dkim._domainkey.xenonly.com and _dmarc.xenonly.com.\nDMARC Record # Example record:\nv=DMARC1; p=quarantine; sp=quarantine; np=reject; adkim=s; aspf=s; rua=mailto:dmarc@xenonly.com Parameter Meaning v=DMARC1 Version. It must always come first. p=quarantine Mail that fails the check goes to the spam folder. The other options: none (only a report is sent, the mail is not affected) and reject (the mail is rejected completely). sp=quarantine The same rule for subdomains (for example x.xenonly.com). If it is not written, the p value applies. If no mail is sent from any subdomain, reject can be used too. np=reject Mail sent in the name of subdomains that don\u0026rsquo;t exist in DNS at all (for example random.xenonly.com) is rejected. No real mail can come from these names, so the strictest setting is safe here. It is a fairly new parameter, so some servers may not know it yet, but adding it does no harm. adkim=s Strict matching for DKIM: the domain in the signature must be exactly the same as the domain in the sender address. With r (relaxed), subdomains are accepted too. aspf=s Strict matching for SPF. Same idea as above. rua=mailto:… The address the daily summary reports are sent to. Note We need a mailbox for dmarc@xenonly.com, the address the DMARC reports are sent to. We\u0026rsquo;ll create it below, in the Account for DMARC Reports section.\nPTR Record # The PTR (reverse DNS) record shows which name an IP address belongs to, and it is set in the VPS provider\u0026rsquo;s control panel. In the rDNS/PTR section of the panel, we enter mail.xenonly.com for the server\u0026rsquo;s IPv4 address and, if there is one, mail.xenonly.com again for the IPv6 address.\nWarning The PTR value must be the server\u0026rsquo;s hostname, mail.xenonly.com, not xenonly.com.\nWarning If the server has IPv6, mail will most likely be sent over IPv6. If the PTR for IPv6 doesn\u0026rsquo;t match, providers like Gmail reject the mail right away.\nWe can check the records from our personal computer with the commands below:\nbash dig +short A mail.xenonly.com # \u0026lt;SERVER_IPV4\u0026gt; dig +short AAAA mail.xenonly.com # \u0026lt;SERVER_IPV6\u0026gt; dig +short -x \u0026lt;SERVER_IPV4\u0026gt; # mail.xenonly.com. dig +short -x \u0026lt;SERVER_IPV6\u0026gt; # mail.xenonly.com. DKIM Record # What it is: A digital signature standard that proves the mail really comes from the authorized domain and was not changed on the way.\nHow It Works # There is a private key for each domain in the /var/lib/dkim/ directory. The domain and its key are defined for the Amavis service in /etc/amavisd/amavisd.conf. The public key is in the dkim._domainkey DNS record. Note We gave xenonly.com as the first domain during the installation, so its keys were created automatically.\nTo see the existing keys:\nbash sudo amavisd showkeys To get a single-line output that can go straight into the DNS record:\nbash sudo amavisd showkeys xenonly.com | awk -F\u0026#39;\u0026#34;\u0026#39; \u0026#39;/^[[:space:]]*\u0026#34;/ {printf \u0026#34;%s\u0026#34;, $2} END {print \u0026#34;\u0026#34;}\u0026#39; Note The value added to DNS must be a single line. amavisd showkeys splits the key over several lines; the command above joins them.\nWe add this output to DNS like this:\nName Type Content What It Means dkim._domainkey TXT \u0026lt;DKIM_KEY\u0026gt; Lets receivers verify the mail signed by Amavis At this point our server can send and receive mail for xenonly.com.\nCreating Users in iRedAdmin # Note In the NGINX configuration that comes with iRedMail, iRedAdmin is at the /iredadmin path and Roundcube is at /mail. In 3 NGINX Configuration these addresses are moved to subdomains (iredadmin.xenonly.com and mail.xenonly.com).\nNote The server is still using the self-signed certificate iRedMail created, so the browser will show a certificate warning. We\u0026rsquo;ll get a Let\u0026rsquo;s Encrypt certificate in 2.1 Setting Up SSL for the Mail Server.\nWe go to https://xenonly.com/iredadmin and log in with the admin account (postmaster@xenonly.com).\nNote The xenonly.com domain was created as the first domain during the installation, so we don\u0026rsquo;t need to add it.\nFollowing Add → User, we create a user named info for xenonly.com.\nTip You can create as many users as you want for the existing domains. To add a new domain, see 2.2 Adding a New Domain to the Mail Server.\nAccount for DMARC Reports # So that the reports can reach rua=mailto:dmarc@xenonly.com from the DMARC record, we again follow Add → User and create a user named dmarc for xenonly.com.\nNote For every domain, there must be a mailbox for the report address given in that domain\u0026rsquo;s DMARC record.\nTest and Check # Let\u0026rsquo;s go to Roundcube at https://xenonly.com/mail and log in as info@xenonly.com.\nLet\u0026rsquo;s send a test mail to the address shown on https://www.mail-tester.com/. The expected result:\nYour lovely total: 10/10 ","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/mail-server/","section":"Self Hosting","summary":" Requirements 1 Post-Install Configuration must be done. iRedMail must be installed on a freshly installed server; this part installs the first service on the server. Assumptions\nThe name of the mail server (hostname) is set to mail.xenonly.com and the first mail domain is xenonly.com. A and AAAA records exist for xenonly.com and mail.xenonly.com. The other records mail needs (MX, SPF, DKIM, DMARC, PTR) are added in this part. Commands are run on the server with root rights (sudo). The DNS checks with dig are done from a personal computer. ","title":"Mail Server Setup","type":"self-hosting"},{"content":" Requirements A server (VPS) with Rocky Linux 10 installed and open to the internet A normal user with sudo rights, created during the installation, and an SSH key added for this user Assumptions\nYou can connect to the server over SSH with this user and get root rights with sudo. All commands are run on the server as this user. Commands that need root rights are written with sudo. We have a freshly installed Rocky Linux 10 server. In this part we\u0026rsquo;ll do the first checks and the basic settings on it.\nInstalling the Basic Packages # bash sudo dnf upgrade sudo dnf install epel-release dnf-plugins-core sudo dnf config-manager --set-enabled crb sudo dnf install \\ unzip tar wget \\ vim-enhanced tmux nano \\ git rsync bash-completion \\ bind-utils traceroute nmap-ncat \\ tcpdump lsof whois \\ htop sysstat plocate \\ rsyslog logrotate \\ certbot Recording Changes in /etc (etckeeper) # etckeeper keeps the /etc directory in a git repository. Every change to the configuration files is recorded: when it was made, by whom and how. A bad change can be undone. It also commits automatically on every package install and update done with dnf.\nWe install it first, so that all the changes the next steps make in /etc (the iRedMail installation too) get recorded.\nbash sudo dnf install etckeeper etckeeper-dnf sudo etckeeper init sudo etckeeper commit \u0026#34;Initial commit\u0026#34; etckeeper-dnf: The dnf plugin. Before every package operation it commits any uncommitted changes in /etc, and after the operation it commits the changes the packages made. etckeeper init: Creates the /etc/.git repository. The repository directory has 700 permissions, so only root can read it. The package\u0026rsquo;s default VCS is git (VCS=\u0026quot;git\u0026quot; in /etc/etckeeper/etckeeper.conf). Let\u0026rsquo;s commit the changes we make by hand, for example after editing a configuration file, together with a message:\nbash sudo git -C /etc status sudo git -C /etc diff sudo etckeeper commit \u0026#34;sshd: disable root login\u0026#34; The commits show the user who ran sudo as the author. To look at the history:\nbash sudo git -C /etc log --oneline | head sudo git -C /etc show \u0026lt;commit\u0026gt; Changes we forget to commit are committed once a day with the message daily autocommit. For this the package brings both the /etc/cron.daily/etckeeper file and etckeeper.timer. If cron is running, we don\u0026rsquo;t need to do anything else:\nbash systemctl is-active crond # active If the output is not active, let\u0026rsquo;s enable the timer:\nbash sudo systemctl enable --now etckeeper.timer Warning The /etc/.git repository keeps a copy of everything in /etc: /etc/shadow, the database passwords of the services (for example /etc/postfix/mysql/), TLS and WireGuard private keys. Since the repository is open only to root, it adds no extra risk on the server. But the repository must not be pushed to a remote server (PUSH_REMOTE must stay empty), and its backups must be stored with care. A password deleted from a file stays in the git history.\nTime Zone # bash sudo timedatectl set-timezone Europe/Istanbul Automatic Security Updates # Let\u0026rsquo;s install security updates automatically every day. We\u0026rsquo;ll do the other updates by hand, after checking them.\nbash sudo dnf install dnf-automatic sudo sed -i \u0026#39;s/^upgrade_type = default/upgrade_type = security/\u0026#39; /etc/dnf/automatic.conf grep \u0026#39;^upgrade_type\u0026#39; /etc/dnf/automatic.conf # upgrade_type = security sudo systemctl enable --now dnf-automatic-install.timer upgrade_type = security: Only packages marked as security updates are installed. dnf-automatic-install.timer: The timer that downloads and installs the updates. It ignores the download_updates and apply_updates settings in /etc/dnf/automatic.conf and always downloads and installs. That\u0026rsquo;s why we only changed upgrade_type in the file. Let\u0026rsquo;s look at when the timer will run and at the waiting security updates:\nbash systemctl list-timers dnf-automatic-install.timer sudo dnf updateinfo list --security The timer runs on local time, so we set the time zone before this. After it runs, you can see what it installed with sudo journalctl -u dnf-automatic-install.service.\nNote dnf-automatic doesn\u0026rsquo;t reboot the server. If an update that needs a reboot, like a new kernel, was installed, sudo dnf needs-restarting -r shows it; we\u0026rsquo;ll do the reboot ourselves. Services that still use the old version of an updated library (for example OpenSSL) are listed with sudo dnf needs-restarting -s.\nNote Most service packages restart their own service when they are updated (for example Postfix, MariaDB). This means a few seconds of downtime during the update.\nBash Settings # We\u0026rsquo;ll set the bash prompt and the command history for all users from a single file. Bash reads the .sh files under /etc/profile.d/ both in login sessions (SSH, sudo -i) and in non-login sessions like sudo -s. So we don\u0026rsquo;t need to edit the .bashrc files of the normal user and root one by one.\nbash sudo tee /etc/profile.d/zz-custom.sh \u0026gt; /dev/null \u0026lt;\u0026lt;\u0026#39;EOF\u0026#39; # Run only in interactive bash sessions [ -n \u0026#34;$BASH_VERSION\u0026#34; ] || return case $- in *i*) ;; *) return ;; esac # Prompt: root in red, normal users in green if [ \u0026#34;$EUID\u0026#34; -eq 0 ]; then PS1=\u0026#39;\\[\\e[1;31m\\]\\u\\[\\e[0;37m\\]@\\[\\e[1;36m\\]\\h \\[\\e[0;33m\\]\\w\\[\\e[0m\\]\\$ \u0026#39; else PS1=\u0026#39;\\[\\e[1;32m\\]\\u\\[\\e[0;37m\\]@\\[\\e[1;36m\\]\\h \\[\\e[0;33m\\]\\w\\[\\e[0m\\]\\$ \u0026#39; fi # Command history HISTTIMEFORMAT=\u0026#39;%F %T \u0026#39; HISTSIZE=50000 HISTFILESIZE=100000 HISTCONTROL=ignoreboth shopt -s histappend PROMPT_COMMAND=\u0026#34;history -a${PROMPT_COMMAND:+; $PROMPT_COMMAND}\u0026#34; EOF source /etc/profile.d/zz-custom.sh The first two checks: Files in /etc/profile.d/ can also be read by sh and by scripts. The settings are applied only in interactive bash sessions. PS1: The \\$ at the end of the prompt shows # for root and $ for a normal user. The if block only changes the color of the username: red for root, green for a normal user. HISTTIMEFORMAT: Shows the date and time of every command in the history output. The time is written to ~/.bash_history as lines like #1795210585. For commands saved before this setting, the real time is unknown. HISTSIZE, HISTFILESIZE: The number of commands kept in the session and in the history file. The Rocky Linux default is 1000. HISTCONTROL=ignoreboth: Doesn\u0026rsquo;t save a command repeated right after itself, or commands that start with a space. To keep a command with a password in it out of the history, put a space in front of it. histappend: When a session closes, its history is added to the end of the file instead of overwriting it. Sessions open at the same time don\u0026rsquo;t delete each other\u0026rsquo;s history. history -a: Writes the history to the file right after every command. If the SSH connection drops or the session is killed, the history is not lost. Let\u0026rsquo;s check it in a new session:\nbash history | tail -n 3 # every line should show the date and time Note The command history is under the user\u0026rsquo;s own control; the user can delete it or turn it off. So it is there for convenience, not for auditing. Commands run with sudo are also logged to the journal: sudo journalctl _COMM=sudo.\nChecking the SSH Service # Let\u0026rsquo;s run the command below:\nbash sudo sshd -T | grep -Ei \\ \u0026#39;^(port|permitrootlogin|passwordauthentication|kbdinteractiveauthentication|pubkeyauthentication|gssapiauthentication|x11forwarding|usepam|allowtcpforwarding|allowagentforwarding) \u0026#39; Let\u0026rsquo;s check that the values in the output are as below:\nport 22 usepam yes permitrootlogin no pubkeyauthentication yes gssapiauthentication no passwordauthentication no kbdinteractiveauthentication no x11forwarding no allowtcpforwarding yes allowagentforwarding yes To change the values that are different, let\u0026rsquo;s create the file /etc/ssh/sshd_config.d/00-hardening.conf with the content below:\n/etc/ssh/sshd_config.d/00-hardening.conf PermitRootLogin no PasswordAuthentication no KbdInteractiveAuthentication no GSSAPIAuthentication no X11Forwarding no Note sshd reads the files under sshd_config.d in alphabetical order and uses the first value it finds for a setting. On Rocky Linux, 50-redhat.conf (and 01-permitrootlogin.conf if root login over SSH was allowed during the installation) sets some of these options, so the file name must start with 00-.\nLet\u0026rsquo;s test the configuration and reload the service:\nbash sudo sshd -t \u0026amp;\u0026amp; sudo systemctl reload sshd Turning Off Firewalld for Now # I\u0026rsquo;ll keep Firewalld off during the setup. After installing all the services, I\u0026rsquo;ll configure it and turn it back on in 5 Firewalld Configuration.\nbash sudo systemctl disable --now firewalld Warning While Firewalld is off, every port the server listens on is open to the internet. Keeping this time short, or not turning Firewalld off at all and adding the needed services from the start, is the safer option. You can check the listening ports with sudo ss -tulpn.\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/post-install-configuration/","section":"Self Hosting","summary":" Requirements A server (VPS) with Rocky Linux 10 installed and open to the internet A normal user with sudo rights, created during the installation, and an SSH key added for this user Assumptions\nYou can connect to the server over SSH with this user and get root rights with sudo. All commands are run on the server as this user. Commands that need root rights are written with sudo. ","title":"Post-Install Configuration","type":"self-hosting"},{"content":"","date":"21 November 2026","externalUrl":null,"permalink":"/tags/rocky-linux/","section":"Tags","summary":"","title":"rocky-linux","type":"tags"},{"content":"In this series I\u0026rsquo;ll look at what you can self-host on a VPS and how to do it, in a technical and hands-on way.\nServer and Environment # This is the server I used while preparing these documents:\nOperating system: Rocky Linux 10.2 CPU: AMD EPYC™ 9645, 4 dedicated cores RAM: 8 GB Storage: 256 GB NVMe You also need a domain name. In this series I use the domain xenonly.com.\nAssumptions and Conventions # Domain Names # The domain I\u0026rsquo;ll use is xenonly.com. The mail server will use the name mail.xenonly.com, and I\u0026rsquo;ll serve the other services on subdomains of xenonly.com (for example iredadmin.xenonly.com).\nThe series assumes that the DNS records for the domain and the subdomains it uses are already in place. This step is not explained again, except for the records that need special care (MX, SPF, DKIM, DMARC, PTR).\nNote Basically, what you need to do is add A and AAAA records for the domain and its subdomains (or *.xenonly.com if you like).\nNotes at the Start of Each Part # At the start of each part there is a short note with the requirements (the parts that must be done first) and the assumptions (the domain names used, where and with which rights the commands are run, and so on).\nCode Blocks # Most commands need root rights. To show this and to keep the commands easy to copy, I write them as sudo ... instead of using a # prompt for root and a $ prompt for a normal user. Commands written without sudo are run as a normal user.\nThe expected output of a command is given in a separate text block, or as a comment starting with # next to the command.\nPlaceholders # Values written in capitals inside angle brackets, like \u0026lt;SERVER_IPV4\u0026gt;, must be replaced with your own values. Names that contain a file name, like \u0026lt;server.key\u0026gt;, stand for the contents of that file.\nRoadmap # 1 Post-Install Configuration # First checks and basic settings on a freshly installed Rocky Linux 10 server.\n2 Mail Server Setup # The first main service on the server will be mail. Right after setting up the server, we\u0026rsquo;ll install the mail service with iRedMail. This also installs NGINX and MariaDB.\n2.1 Setting Up SSL for the Mail Server 2.2 Adding a New Domain to the Mail Server 2.3 Using a Mail Client 2.4 Moving the Mail Server 2.5 Extra Settings 3 NGINX Configuration # Turning the NGINX setup that iRedMail installed into one that can serve many services and virtual hosts.\n4 Docker Setup # Installing Docker and setting it up so that containers are reachable only over localhost.\n4.1 A Ready Template for Docker Containers 5 Firewalld Configuration # Configuring and turning on Firewalld, which we keep off during the setup, and blocking containers and VPN clients from going out on port 25.\n6 Fail2Ban Configuration # Adding longer and longer ban times for repeat attackers to the Fail2Ban that comes with iRedMail.\n7 WireGuard Setup # A VPN server: sending clients to the internet through the VPN, letting clients talk to each other and making some services reachable only over the VPN.\n7.1 Adding WireGuard Clients 7.2 Putting Services Behind the VPN 7.3 Possible Problems 8 Vault Setup # Keeping secrets (API keys, tokens, passwords) in one central, encrypted place with HashiCorp Vault.\n9 Vaultwarden Setup # Installing Vaultwarden, a Bitwarden-compatible password manager.\n10 WordPress Setup # A WordPress setup where every site runs in its own container and all sites use one shared MariaDB container.\n10.1 Moving an Old WordPress Site into This Setup 11 Usememos Setup # Installing Memos, a note app you can host yourself.\n12 Syncthing Setup # Syncthing for syncing files between devices; the server is used as the shared peer that is always on.\n13 Hugo Blog Setup # Coming soon\n14 Log Management and Monitoring # Coming soon\n15 Backup Strategy # Coming soon\n","date":"21 November 2026","externalUrl":null,"permalink":"/self-hosting/planning-and-architecture/","section":"Self Hosting","summary":"In this series I’ll look at what you can self-host on a VPS and how to do it, in a technical and hands-on way.\nServer and Environment # This is the server I used while preparing these documents:\n","title":"Planning and Architecture","type":"self-hosting"},{"content":"Hi, I\u0026rsquo;m Talha.\nI\u0026rsquo;m actively interested in technology, and I use this blog to:\nTake notes on what I do and document it. Understand my work better while I write about it, and research it more so it is good enough to share. Show readers what I did and how to do it, and maybe help them see the bigger picture. Contact # If you find a mistake in a post or want to ask something, you can write to me.\nEmail: GitHub: atalhatabak LinkedIn: atalhatabak ","externalUrl":null,"permalink":"/about/","section":"Talha Tabak","summary":"Hi, I’m Talha.\nI’m actively interested in technology, and I use this blog to:\nTake notes on what I do and document it. Understand my work better while I write about it, and research it more so it is good enough to share. Show readers what I did and how to do it, and maybe help them see the bigger picture. Contact # If you find a mistake in a post or want to ask something, you can write to me.\n","title":"About","type":"page"},{"content":"","externalUrl":null,"permalink":"/glossary/","section":"Talha Tabak","summary":"","title":"Glossary","type":"page"},{"content":"","externalUrl":null,"permalink":"/posts/","section":"Talha Tabak","summary":"","title":"Posts","type":"page"}]