{"id":20536057,"url":"https://github.com/techprober/mosdns-opnsense-install","last_synced_at":"2025-04-14T07:21:16.517Z","repository":{"id":194772408,"uuid":"691546200","full_name":"techprober/mosdns-opnsense-install","owner":"techprober","description":"A generic guide to deploy mosdns to OPNSense","archived":false,"fork":false,"pushed_at":"2024-01-04T14:54:21.000Z","size":79,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-27T21:02:06.407Z","etag":null,"topics":["mosdns","opnsense"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techprober.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-09-14T11:58:45.000Z","updated_at":"2024-11-23T17:11:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"51778f12-01d8-437f-833f-c9660070b030","html_url":"https://github.com/techprober/mosdns-opnsense-install","commit_stats":null,"previous_names":["techprober/mosdns-opnsense-install"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techprober%2Fmosdns-opnsense-install","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techprober%2Fmosdns-opnsense-install/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techprober%2Fmosdns-opnsense-install/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techprober%2Fmosdns-opnsense-install/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techprober","download_url":"https://codeload.github.com/techprober/mosdns-opnsense-install/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837172,"owners_count":21169379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mosdns","opnsense"],"created_at":"2024-11-16T00:35:12.785Z","updated_at":"2025-04-14T07:21:16.493Z","avatar_url":"https://github.com/techprober.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003emosdns-opnsense-deploy\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    \u003cem\u003eA generic guide to deploy mosdns to OPNSense\u003c/em\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.herokuapp.com/github/license/techprober/mosdns-opnsense-install?logo=law\u0026color=critical\" alt=\"License\"/\u003e\n    \u003cimg src=\"https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Ftechprober%2Fmosdns-opnsense-deploy\u0026count_bg=%231D86BF\u0026title_bg=%23555555\u0026icon=\u0026icon_color=%23753131\u0026title=hits\u0026edge_flat=false\"/\u003e\n    \u003cimg src=\"https://custom-icon-badges.herokuapp.com/github/v/release/IrineSistiana/mosdns?logo=rocket\" alt=\"version\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.herokuapp.com/github/issues-pr-closed/TechProber/mosdns-opnsense-install?color=purple\u0026logo=git-pull-request\u0026logoColor=white\"/\u003e\n    \u003cimg src=\"https://custom-icon-badges.herokuapp.com/github/last-commit/TechProber/mosdns-opnsense-install?logo=history\u0026logoColor=white\" alt=\"lastcommit\"/\u003e\n\u003c/p\u003e\n\n## Introduction\n\nThis repo provides a generic guide to deploy mosdns to OPNSense with ease. However, it requires users to have some fundamental knowledge about OPNSense and mosdns.\n\n## Documentation\n\nMosdns Official Wiki: \u003chttps://irine-sistiana.gitbook.io/mosdns-wiki/\u003e\n\nKnow DNS Providers: \u003chttps://adguard-dns.io/kb/general/dns-providers/\u003e\n\n## Project Owner\n\nCopyright 2023-2024 @TechProber. All rights reserved.\n\nMaintainer: [Kevin Yu (@yqlbu)](https://github.com/yqlbu)\n\n## Table of Contents\n\n\u003c!-- vim-markdown-toc GFM --\u003e\n\n* [Related Projects](#related-projects)\n* [Steps to deploy](#steps-to-deploy)\n  * [Preparation](#preparation)\n  * [Download binary from GitHub release page](#download-binary-from-github-release-page)\n  * [Create log file](#create-log-file)\n  * [Download geodata artifacts](#download-geodata-artifacts)\n  * [Disable and stop Unbound service](#disable-and-stop-unbound-service)\n  * [Create mosdns rc service](#create-mosdns-rc-service)\n  * [Create mosdns config](#create-mosdns-config)\n  * [Enable mosdns service](#enable-mosdns-service)\n  * [Verify running status](#verify-running-status)\n  * [Check journal logs](#check-journal-logs)\n* [Cronjobs](#cronjobs)\n  * [Set up cron job](#set-up-cron-job)\n    * [Create cron action](#create-cron-action)\n    * [Clean up logs](#clean-up-logs)\n    * [Update geodata artifacts](#update-geodata-artifacts)\n  * [Add a new cron command available under OPNsense GUI](#add-a-new-cron-command-available-under-opnsense-gui)\n* [Forward requests to designated gateways](#forward-requests-to-designated-gateways)\n* [Maintenance](#maintenance)\n  * [Force stop mosdns](#force-stop-mosdns)\n* [Appendix](#appendix)\n\n\u003c!-- vim-markdown-toc --\u003e\n\n## Related Projects\n\n- [techprober/mosdns-lxc-deploy](https://github.com/techprober/mosdns-lxc-deploy) - Deploy mosdns in Proxmox LXC Container\n- [IrineSistiana/mosdns](https://github.com/IrineSistiana/mosdns) - A self-hosted DNS resolver\n- [tteck/Proxmox](https://github.com/tteck/Proxmox) - Proxmox Helper Scripts\n- [Loyalsoldier/v2ray-rules-dat](https://github.com/Loyalsoldier/v2ray-rules-dat) - Enhanced edition of V2Ray rules dat files, compatible with Xray-core, Shadowsocks-windows, Trojan-Go and leaf.\n- [Loyalsoldier/geoip](https://github.com/Loyalsoldier/geoip) - Enhanced edition of GeoIP files for V2Ray, Xray-core, Trojan-Go, Clash and Leaf, with replaced CN IPv4 CIDR available from ipip.net, appended CIDR lists and more.\n\n## Steps to deploy\n\n### Preparation\n\nCreate a new directory for mosdns\n\n```bash\nsudo mkdir -p /etc/usr/local/mosdns\n```\n\nCreate sub directories\n\n```bash\nsudo mkdir -p /usr/local/etc/mosdns/{ips,domains,downloads,custom}\n```\n\nMake sure you have the following file structure present on your host:\n\n```\n# /usr/local/etc/mosdns\n./\n|-- config.yml\n|-- custom\n|-- domains\n|-- downloads\n|-- scripts\n`-- ips\n\n5 directories, 1 file\n```\n\nInstall Vim (Optional)\n\n```bash\nsudo pkg install vim\n```\n\n### Download binary from GitHub release page\n\nhttps://github.com/IrineSistiana/mosdns/releases\n\n```bash\ncd /usr/local/etc/mosdns/downloads\ncurl -o mosdns.zip https://github.com/IrineSistiana/mosdns/releases/download/{VERSION}/mosdns-freebsd-amd64.zip\nunzip mosdns.zip\nsudo install -Dm755 mosdns /usr/bin/\n```\n\n### Create log file\n\n```bash\nsudo touch /var/log/mosdns.log\n```\n\n### Download geodata artifacts\n\nReference: https://github.com/techprober/mosdns-lxc-deploy\n\nArtifacts Source: https://github.com/techprober/v2ray-rules-dat/releases\n\n\u003e [!NOTE]\n\u003e You may selectively download the rule lists you need from the [release branch](https://github.com/techprober/v2ray-rules-dat/tree/release) from [@techprober/v2ray-rules-dat](https://github.com/techprober/v2ray-rules-dat/releases).\n\n```bash\nset MOSDNS_PATH=/usr/local/etc/mosdns\ncurl --progress-bar -JL -o $MOSDNS_PATH/downloads/geoip.zip https://github.com/techprober/v2ray-rules-dat/raw/release/geoip.zip\ncurl --progress-bar -JL -o $MOSDNS_PATH/downloads/geosite.zip https://github.com/techprober/v2ray-rules-dat/raw/release/geosite.zip\nunzip -o $MOSDNS_PATH/downloads/geoip.zip -d $MOSDNS_PATH/ips\nunzip -o $MOSDNS_PATH/downloads/geosite.zip -d $MOSDNS_PATH/domains\n```\n\n\u003e [!NOTE]\n\u003e Alternatively, you may use a dedicated script to automatically download and extract the geodata artifacts. See [./scripts/geodata-update.sh](./scripts/geodata-update.sh)\n\n### Disable and stop Unbound service\n\n\u003e [!WARNING]\n\u003e Doing so will free port `53` for mosdns to use\n\n```bash\n# stop unbound service\n# /usr/local/opnsense/service/conf/actions.d/actions_unbound.conf\nconfigctl unbound stop\n/usr/local/sbin/pluginctl dns stop\n/usr/local/sbin/pluginctl dns disable\n```\n\n### Create mosdns rc service\n\nPaste the content from [./rc.d/mosdns](./rc.d/mosdns) in this repo to `/usr/local/etc/rc.d/mosdns` in OPNSense.\n\n```bash\nsudo chmod +x /usr/local/etc/rc.d/mosdns\n```\n\n### Create mosdns config\n\n\u003e [!NOTE]\n\u003e You may start with the recommended [config](https://github.com/techprober/mosdns-lxc-deploy/blob/master/mosdns/config-v5.yml), which provides out-of-the-box ip leak prevent feature.\n\n\u003e [!WARNING]\n\u003e Please take a look at the content of `config-{VERSION}.yml` before you copy it to `/usr/local/etc/mosdns`. It is a boilerplate template which intends to provide users a reference to start with customizing their own config.\n\n### Enable mosdns service\n\n```bash\necho 'mosdns_enable=\"YES\"' \u003e\u003e /etc/rc.conf\nsudo service mosdns start\nsudo service mosdns enable\n```\n\n### Verify running status\n\n```bash\nps -aux | grep mosdns\nsudo service mosdns status\n```\n\n### Check journal logs\n\n\u003e [!IMPORTANT]\n\u003e To write logs to a file, you need to specify the log file destination in your config as shown in the following:\n\n```yaml\n## -- Log Config -- ##\nlog:\n  level: debug # [\"debug\", \"info\", \"warn\", and \"error\"], default is set to \"info\"\n  production: true\n  file: \"/var/log/mosdns.log\"\n```\n\n```bash\nsudo tail -f /var/log/mosdns.log\n```\n\n## Cronjobs\n\n### Set up cron job\n\n#### Create cron action\n\nCreate a `.conf `file in `/usr/local/opnsense/service/conf/actions.d/` (your file must start with `actions_`)\n`vi /usr/local/opnsense/service/conf/actions.d/actions_mosdns-logs-cleanup.conf`\n\nAvailable in [./actions.d/actions_mosdns.conf](./actions.d/actions_mosdns.conf)\n\nRestart and reload\n\n```bash\nsudo service configd restart\n```\n\n#### Clean up logs\n\n```bash\nsudo configctl mosdns logs-cleanup\n```\n\n---\n\n#### Update geodata artifacts\n\nAdd geodata-update script\n\nThe script is available in [./scripts/geodata-update.sh](./scripts/geodata-update.sh).\n\nDownload save it in `/usr/local/etc/mosdns/scripts/`\n\n```bash\ncurl -L -o /usr/local/etc/mosdns/scripts/geodata-update.sh https://github.com/techprober/mosdns-opnsense-install/raw/master/scripts/geodata-update.sh\n```\n\nSet permission\n\n```bash\nsudo chmod +x /usr/local/etc/mosdns/scripts/geodata-update.sh\n```\n\nRun the action\n\n```bash\nsudo configctl mosdns geodata-update\n```\n\n---\n\n### Add a new cron command available under OPNsense GUI\n\nGo to `System` \u003e `Settings` \u003e `Cron` and `Add a Job`\nYou can show your cron command in dropdown Command. Plan your cron schedule as you wish.\n\n\u003cimg width=\"1661\" alt=\"image\" src=\"https://github.com/techprober/mosdns-opnsense-install/assets/31861128/cb586f5a-b8cd-416e-a078-e14642d7de42\"\u003e\n\n## Forward requests to designated gateways\n\n\u003e [!NOTE]\n\u003e For those who would like to further forward DNS requests to designated gateways, depending on the DNS provider of choice, you may achieve so following the route setting below.\n\n![CleanShot 2023-09-14 at 22 58 10@2x](https://github.com/techprober/mosdns-opnsense-install/assets/31861128/c681317c-ecd1-43a9-b441-8a56be95f6da)\n\n## Maintenance\n\n### Force stop mosdns\n\n```bash\n# force stop\nps -aux | grep mosdns\nkill -9 \u003cmosdns pid\u003e\n# restart\nservice mosdns start\n```\n\n## Appendix\n\n- Auto-generate `geoip.txt`, `geosites.txt` (since `*.dat` are deprecated in v5) - https://github.com/techprober/v2dat\n- Available Rules - https://github.com/techprober/v2ray-rules-dat/releases\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechprober%2Fmosdns-opnsense-install","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechprober%2Fmosdns-opnsense-install","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechprober%2Fmosdns-opnsense-install/lists"}