Skip to content

Instantly share code, notes, and snippets.

@piyoki
Last active July 27, 2025 16:34
Show Gist options
  • Save piyoki/dbe18d4e023f68a903ee6273cde71ba9 to your computer and use it in GitHub Desktop.
Save piyoki/dbe18d4e023f68a903ee6273cde71ba9 to your computer and use it in GitHub Desktop.

Revisions

  1. piyoki revised this gist Aug 24, 2022. 1 changed file with 34 additions and 0 deletions.
    34 changes: 34 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    ---
    version: "3.4"
    services:
    redis:
    container_name: redis
    image: "redis:alpine"
    command: redis-server
    ports:
    - "6379:6379"
    volumes:
    - $PWD/redis-data:/var/lib/redis
    - $PWD/redis.conf:/usr/local/etc/redis/redis.conf
    environment:
    - REDIS_REPLICATION_MODE=master
    networks:
    node_net:
    ipv4_address: 172.28.1.4
    restart: unless-stopped

    watchtower:
    container_name: watchtower
    image: containrrr/watchtower
    restart: always
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    command: ["--cleanup", "--interval", "3600", "--debug"]

    # networking for the Redis container
    networks:
    node_net:
    ipam:
    driver: default
    config:
    - subnet: 172.28.0.0/16
  2. piyoki revised this gist Aug 24, 2022. 2 changed files with 10 additions and 365 deletions.
    21 changes: 10 additions & 11 deletions config.yml
    Original file line number Diff line number Diff line change
    @@ -83,7 +83,7 @@ plugins:

    # --- Domestic DNS --- #
    # alidns
    - tag: ali_dos
    - tag: ali_doh_dot
    type: forward
    args:
    upstream:
    @@ -94,7 +94,7 @@ plugins:
    - "2400:3200::1"
    - "223.6.6.6"
    trusted: true
    - addr: "tls://dns.alidns.com" # TLS server address
    - addr: "tls://dns.alidns.com" # DoT server address
    ip_addr: # server ip addresses
    - "2400:3200:baba::1"
    - "223.5.5.5"
    @@ -116,7 +116,7 @@ plugins:

    # --- Remote DNS --- #
    # google dns
    - tag: google_dos
    - tag: google_doh
    type: forward
    args:
    upstream:
    @@ -131,7 +131,7 @@ plugins:
    type: fast_forward
    args:
    upstream:
    - addr: "tls://dns.google"
    - addr: "tls://dns.google" # DoT server address
    dial_addr: "8.8.4.4"
    trusted: true
    enable_pipeline: true
    @@ -145,7 +145,7 @@ plugins:
    enable_pipeline: true

    # cloudflare
    - tag: cloudflare_dos
    - tag: cloudflare_doh
    type: forward
    args:
    upstream:
    @@ -160,7 +160,7 @@ plugins:
    type: fast_forward
    args:
    upstream:
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com" # DoT server address
    dial_addr: "2606:4700:4700::1001"
    trusted: true
    enable_pipeline: true
    @@ -277,7 +277,7 @@ plugins:
    exec:
    # - primary:
    - parallel:
    - - ali_dos
    - - ali_doh_dot
    # secondary:
    # - localdns
    # fast_fallback: 600
    @@ -290,8 +290,8 @@ plugins:
    exec:
    # - primary:
    - parallel:
    - - google_dos
    - - cloudflare_dos
    - - google_doh
    - - cloudflare_doh
    - - google_dot
    - - cloudflare_dot
    - - adguard # secondary
    @@ -349,7 +349,6 @@ plugins:
    exec:
    - _new_nxdomain_response # empty response
    - _return
    - mem_cache # cache
    - redis_cache # cache
    - main_sequence # run main query sequence
    - modify_ttl

    354 changes: 0 additions & 354 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -1,354 +0,0 @@
    #/etc/mosdns/config.json
    ---
    # log config
    log:
    level: info # ["debug", "info", "warn", and "error"], default is set to "info"
    file: "/var/log/mosdns.log"

    # data source config
    data_providers:
    - tag: cn
    file: "/etc/mosdns/cn.dat"
    auto_reload: false
    - tag: geoip
    file: "/etc/mosdns/geoip.dat"
    auto_reload: false
    - tag: geosite
    file: "/etc/mosdns/geosite.dat"
    auto_reload: false

    # api config
    api:
    http: ":8080"

    # server config
    servers:
    # main query sequence
    - exec: sequence_exec
    timeout: 5
    listeners:
    # --- local port binding --- #
    # local ipv6
    - protocol: udp
    addr: "[::1]:53"
    - protocol: tcp
    addr: "[::1]:53"
    # local ipv4
    - protocol: udp
    addr: "127.0.0.1:53"
    - protocol: tcp
    addr: "127.0.0.1:53"

    # --- interface binding --- #
    # lag group
    - protocol: udp
    addr: "10.178.0.3:53"
    - protocol: tcp
    addr: "10.178.0.3:53"
    # vlan 17
    - protocol: udp
    addr: "10.189.17.3:53"
    - protocol: tcp
    addr: "10.189.17.3:53"

    # plugin config
    plugins:
    # --- Excutable Plugins --- #
    # cache
    # - tag: "mem_cache"
    # type: "cache"
    # args:
    # size: 1024 # query max number
    # lazy_cache_ttl: 86400 # lazy cache ttl
    # lazy_cache_reply_ttl: 30 # timeout ttl
    # cache_everything: true

    - tag: "redis_cache"
    type: "cache"
    args:
    size: 1024 # query max number
    lazy_cache_ttl: 86400 # lazy cache ttl
    lazy_cache_reply_ttl: 30 # timeout ttl
    cache_everything: true
    # redis config
    redis: "redis://10.189.17.4:6379/1"
    redis_timeout: 50

    # ttl
    - tag: "modify_ttl"
    type: "ttl"
    args:
    minimal_ttl: 300
    maximum_ttl: 3600

    # --- Domestic DNS --- #
    # alidns
    - tag: ali_doh_dot
    type: forward
    args:
    upstream:
    - addr: "https://dns.alidns.com/dns-query" # DoH server address
    ip_addr: # server ip addresses
    - "2400:3200:baba::1"
    - "223.5.5.5"
    - "2400:3200::1"
    - "223.6.6.6"
    trusted: true
    - addr: "tls://dns.alidns.com" # DoT server address
    ip_addr: # server ip addresses
    - "2400:3200:baba::1"
    - "223.5.5.5"
    - "2400:3200::1"
    - "223.6.6.6"
    trusted: true

    bootstrap:
    - "tls://1.1.1.1"
    - "https://223.5.5.5/dns-query"
    timeout: 5 # default timeout

    # --- Local DNS --- #
    - tag: localdns
    type: forward
    args:
    upstream:
    - addr: "178.0.50.6:53"

    # --- Remote DNS --- #
    # google dns
    - tag: google_doh
    type: forward
    args:
    upstream:
    - addr: "https://dns.google/dns-query" # DoH server address
    ip_addr: # server ip addresses
    - "2001:4860:4860::8844"
    - "8.8.4.4"
    - "2001:4860:4860::8888"
    - "8.8.8.8"
    trusted: true
    - tag: google_dot
    type: fast_forward
    args:
    upstream:
    - addr: "tls://dns.google" # DoT server address
    dial_addr: "8.8.4.4"
    trusted: true
    enable_pipeline: true
    - addr: "tls://dns.google"
    dial_addr: "2001:4860:4860::8888"
    trusted: true
    enable_pipeline: true
    - addr: "tls://dns.google"
    dial_addr: "8.8.8.8"
    trusted: true
    enable_pipeline: true

    # cloudflare
    - tag: cloudflare_doh
    type: forward
    args:
    upstream:
    - addr: "https://cloudflare-dns.com/dns-query" # DoH server address
    ip_addr: # server ip addresses
    - "2606:4700:4700::1001"
    - "1.0.0.1"
    - "2606:4700:4700::1111"
    - "1.1.1.1"
    trusted: true
    - tag: cloudflare_dot
    type: fast_forward
    args:
    upstream:
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com" # DoT server address
    dial_addr: "2606:4700:4700::1001"
    trusted: true
    enable_pipeline: true
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "1.0.0.1"
    trusted: true
    enable_pipeline: true
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "2606:4700:4700::1111"
    trusted: true
    enable_pipeline: true
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "1.0.0.1"
    trusted: true
    enable_pipeline: true

    # h3 parallel
    - tag: google_h3
    type: "fast_forward"
    args:
    # upstream servers, at lease to configure one, send request in parallel to all servers
    upstream:
    - addr: "https://dns.google/dns-query"
    dial_addr: "2001:4860:4860::8844"
    trusted: true
    enable_http3: true
    - addr: "https://dns.google/dns-query"
    dial_addr: "8.8.4.4"
    trusted: true
    enable_http3: true
    - addr: "https://dns.google/dns-query"
    dial_addr: "2001:4860:4860::8888"
    trusted: true
    enable_http3: true
    - addr: "https://dns.google/dns-query"
    dial_addr: "8.8.8.8"
    trusted: true
    enable_http3: true
    - tag: cloudflare_h3
    type: "fast_forward"
    args:
    upstream:
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "2606:4700:4700::1001"
    trusted: true
    enable_http3: true
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "1.0.0.1"
    trusted: true
    enable_http3: true
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "2606:4700:4700::1111"
    trusted: true
    enable_http3: true
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "1.1.1.1"
    trusted: true
    enable_http3: true

    # doq backup resolver
    - tag: adguard
    type: forward
    args:
    upstream:
    - addr: "quic://dns-unfiltered.adguard.com" # DoQ server
    ip_addr: # server addresses
    - "2a10:50c0::1:ff"
    - "94.140.14.140"
    - "2a10:50c0::2:ff"
    - "94.140.14.141"
    trusted: true

    # --- query matcher --- #
    # query - CN domains
    - tag: query_cn
    type: query_matcher
    args:
    domain:
    - "provider:geosite:cn"

    # query - GFW domains
    - tag: query_gfw
    type: query_matcher
    args:
    domain:
    - "provider:geosite:gfw"

    # query - non-CN domains
    - tag: query_notcn
    type: query_matcher
    args:
    domain:
    - "provider:geosite:geolocation-!cn"

    # query - ad
    - tag: query_ad
    type: query_matcher
    args:
    domain:
    - "provider:geosite:category-ads-all"

    # query - CN IP
    - tag: response_cnip
    type: response_matcher
    args:
    ip:
    - "provider:geoip:cn"

    # --- Sequence --- #
    # local sequence
    - tag: local
    type: sequence
    args:
    exec:
    # - primary:
    - parallel:
    - - ali_doh_dot
    # secondary:
    # - localdns
    # fast_fallback: 600
    # always_standby: true

    # remote sequence
    - tag: remote
    type: sequence
    args:
    exec:
    # - primary:
    - parallel:
    - - google_doh
    - - cloudflare_doh
    - - google_dot
    - - cloudflare_dot
    - - adguard # secondary
    - - google_h3
    - - cloudflare_h3
    # secondary:
    # - adguard
    # fast_fallback: 600
    # always_standby: true

    # main_sequence
    - tag: main_sequence
    type: sequence
    args:
    exec:
    # CN domains
    - if: "query_cn"
    exec:
    - _prefer_ipv4 # ipv4 as priority
    - _pad_query
    - local # local ip as result
    - if: "response_cnip" # cnip as result
    exec:
    - _return # end

    # non-CN domains
    - if: query_notcn
    exec:
    - _prefer_ipv4 # ipv4 as priority
    - _pad_query
    - remote # uncontaminated ip
    - if: "!response_cnip" # non-CN ip as result
    exec:
    - _return # end

    # other condition
    - primary:
    - _prefer_ipv4
    - _pad_query
    - remote
    secondary:
    - _prefer_ipv4
    - _pad_query
    - local
    fast_fallback: 400
    always_standby: true

    # --- sequence execution --- #
    - tag: sequence_exec
    type: sequence
    args:
    exec:
    - _prefer_ipv4
    - if: query_ad # ad
    exec:
    - _new_nxdomain_response # empty response
    - _return
    - redis_cache # cache
    - main_sequence # run main query sequence
    - modify_ttl
  3. piyoki revised this gist Aug 24, 2022. 1 changed file with 353 additions and 33 deletions.
    386 changes: 353 additions & 33 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,354 @@
    #/etc/mosdns/config.json
    ---
    version: "3.4"
    services:
    redis:
    container_name: redis
    image: "redis:alpine"
    command: redis-server
    ports:
    - "6379:6379"
    volumes:
    - $PWD/redis-data:/var/lib/redis
    - $PWD/redis.conf:/usr/local/etc/redis/redis.conf
    environment:
    - REDIS_REPLICATION_MODE=master
    networks:
    node_net:
    ipv4_address: 172.28.1.4
    restart: unless-stopped

    watchtower:
    container_name: watchtower
    image: containrrr/watchtower
    restart: always
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    command: ["--cleanup", "--interval", "3600", "--debug"]

    # networking for the Redis container
    networks:
    node_net:
    ipam:
    driver: default
    config:
    - subnet: 172.28.0.0/16
    # log config
    log:
    level: info # ["debug", "info", "warn", and "error"], default is set to "info"
    file: "/var/log/mosdns.log"

    # data source config
    data_providers:
    - tag: cn
    file: "/etc/mosdns/cn.dat"
    auto_reload: false
    - tag: geoip
    file: "/etc/mosdns/geoip.dat"
    auto_reload: false
    - tag: geosite
    file: "/etc/mosdns/geosite.dat"
    auto_reload: false

    # api config
    api:
    http: ":8080"

    # server config
    servers:
    # main query sequence
    - exec: sequence_exec
    timeout: 5
    listeners:
    # --- local port binding --- #
    # local ipv6
    - protocol: udp
    addr: "[::1]:53"
    - protocol: tcp
    addr: "[::1]:53"
    # local ipv4
    - protocol: udp
    addr: "127.0.0.1:53"
    - protocol: tcp
    addr: "127.0.0.1:53"

    # --- interface binding --- #
    # lag group
    - protocol: udp
    addr: "10.178.0.3:53"
    - protocol: tcp
    addr: "10.178.0.3:53"
    # vlan 17
    - protocol: udp
    addr: "10.189.17.3:53"
    - protocol: tcp
    addr: "10.189.17.3:53"

    # plugin config
    plugins:
    # --- Excutable Plugins --- #
    # cache
    # - tag: "mem_cache"
    # type: "cache"
    # args:
    # size: 1024 # query max number
    # lazy_cache_ttl: 86400 # lazy cache ttl
    # lazy_cache_reply_ttl: 30 # timeout ttl
    # cache_everything: true

    - tag: "redis_cache"
    type: "cache"
    args:
    size: 1024 # query max number
    lazy_cache_ttl: 86400 # lazy cache ttl
    lazy_cache_reply_ttl: 30 # timeout ttl
    cache_everything: true
    # redis config
    redis: "redis://10.189.17.4:6379/1"
    redis_timeout: 50

    # ttl
    - tag: "modify_ttl"
    type: "ttl"
    args:
    minimal_ttl: 300
    maximum_ttl: 3600

    # --- Domestic DNS --- #
    # alidns
    - tag: ali_doh_dot
    type: forward
    args:
    upstream:
    - addr: "https://dns.alidns.com/dns-query" # DoH server address
    ip_addr: # server ip addresses
    - "2400:3200:baba::1"
    - "223.5.5.5"
    - "2400:3200::1"
    - "223.6.6.6"
    trusted: true
    - addr: "tls://dns.alidns.com" # DoT server address
    ip_addr: # server ip addresses
    - "2400:3200:baba::1"
    - "223.5.5.5"
    - "2400:3200::1"
    - "223.6.6.6"
    trusted: true

    bootstrap:
    - "tls://1.1.1.1"
    - "https://223.5.5.5/dns-query"
    timeout: 5 # default timeout

    # --- Local DNS --- #
    - tag: localdns
    type: forward
    args:
    upstream:
    - addr: "178.0.50.6:53"

    # --- Remote DNS --- #
    # google dns
    - tag: google_doh
    type: forward
    args:
    upstream:
    - addr: "https://dns.google/dns-query" # DoH server address
    ip_addr: # server ip addresses
    - "2001:4860:4860::8844"
    - "8.8.4.4"
    - "2001:4860:4860::8888"
    - "8.8.8.8"
    trusted: true
    - tag: google_dot
    type: fast_forward
    args:
    upstream:
    - addr: "tls://dns.google" # DoT server address
    dial_addr: "8.8.4.4"
    trusted: true
    enable_pipeline: true
    - addr: "tls://dns.google"
    dial_addr: "2001:4860:4860::8888"
    trusted: true
    enable_pipeline: true
    - addr: "tls://dns.google"
    dial_addr: "8.8.8.8"
    trusted: true
    enable_pipeline: true

    # cloudflare
    - tag: cloudflare_doh
    type: forward
    args:
    upstream:
    - addr: "https://cloudflare-dns.com/dns-query" # DoH server address
    ip_addr: # server ip addresses
    - "2606:4700:4700::1001"
    - "1.0.0.1"
    - "2606:4700:4700::1111"
    - "1.1.1.1"
    trusted: true
    - tag: cloudflare_dot
    type: fast_forward
    args:
    upstream:
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com" # DoT server address
    dial_addr: "2606:4700:4700::1001"
    trusted: true
    enable_pipeline: true
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "1.0.0.1"
    trusted: true
    enable_pipeline: true
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "2606:4700:4700::1111"
    trusted: true
    enable_pipeline: true
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "1.0.0.1"
    trusted: true
    enable_pipeline: true

    # h3 parallel
    - tag: google_h3
    type: "fast_forward"
    args:
    # upstream servers, at lease to configure one, send request in parallel to all servers
    upstream:
    - addr: "https://dns.google/dns-query"
    dial_addr: "2001:4860:4860::8844"
    trusted: true
    enable_http3: true
    - addr: "https://dns.google/dns-query"
    dial_addr: "8.8.4.4"
    trusted: true
    enable_http3: true
    - addr: "https://dns.google/dns-query"
    dial_addr: "2001:4860:4860::8888"
    trusted: true
    enable_http3: true
    - addr: "https://dns.google/dns-query"
    dial_addr: "8.8.8.8"
    trusted: true
    enable_http3: true
    - tag: cloudflare_h3
    type: "fast_forward"
    args:
    upstream:
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "2606:4700:4700::1001"
    trusted: true
    enable_http3: true
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "1.0.0.1"
    trusted: true
    enable_http3: true
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "2606:4700:4700::1111"
    trusted: true
    enable_http3: true
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "1.1.1.1"
    trusted: true
    enable_http3: true

    # doq backup resolver
    - tag: adguard
    type: forward
    args:
    upstream:
    - addr: "quic://dns-unfiltered.adguard.com" # DoQ server
    ip_addr: # server addresses
    - "2a10:50c0::1:ff"
    - "94.140.14.140"
    - "2a10:50c0::2:ff"
    - "94.140.14.141"
    trusted: true

    # --- query matcher --- #
    # query - CN domains
    - tag: query_cn
    type: query_matcher
    args:
    domain:
    - "provider:geosite:cn"

    # query - GFW domains
    - tag: query_gfw
    type: query_matcher
    args:
    domain:
    - "provider:geosite:gfw"

    # query - non-CN domains
    - tag: query_notcn
    type: query_matcher
    args:
    domain:
    - "provider:geosite:geolocation-!cn"

    # query - ad
    - tag: query_ad
    type: query_matcher
    args:
    domain:
    - "provider:geosite:category-ads-all"

    # query - CN IP
    - tag: response_cnip
    type: response_matcher
    args:
    ip:
    - "provider:geoip:cn"

    # --- Sequence --- #
    # local sequence
    - tag: local
    type: sequence
    args:
    exec:
    # - primary:
    - parallel:
    - - ali_doh_dot
    # secondary:
    # - localdns
    # fast_fallback: 600
    # always_standby: true

    # remote sequence
    - tag: remote
    type: sequence
    args:
    exec:
    # - primary:
    - parallel:
    - - google_doh
    - - cloudflare_doh
    - - google_dot
    - - cloudflare_dot
    - - adguard # secondary
    - - google_h3
    - - cloudflare_h3
    # secondary:
    # - adguard
    # fast_fallback: 600
    # always_standby: true

    # main_sequence
    - tag: main_sequence
    type: sequence
    args:
    exec:
    # CN domains
    - if: "query_cn"
    exec:
    - _prefer_ipv4 # ipv4 as priority
    - _pad_query
    - local # local ip as result
    - if: "response_cnip" # cnip as result
    exec:
    - _return # end

    # non-CN domains
    - if: query_notcn
    exec:
    - _prefer_ipv4 # ipv4 as priority
    - _pad_query
    - remote # uncontaminated ip
    - if: "!response_cnip" # non-CN ip as result
    exec:
    - _return # end

    # other condition
    - primary:
    - _prefer_ipv4
    - _pad_query
    - remote
    secondary:
    - _prefer_ipv4
    - _pad_query
    - local
    fast_fallback: 400
    always_standby: true

    # --- sequence execution --- #
    - tag: sequence_exec
    type: sequence
    args:
    exec:
    - _prefer_ipv4
    - if: query_ad # ad
    exec:
    - _new_nxdomain_response # empty response
    - _return
    - redis_cache # cache
    - main_sequence # run main query sequence
    - modify_ttl
  4. piyoki revised this gist Aug 24, 2022. 2 changed files with 5 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    # mosdns deployment
    ## mosdns deployment
    4 changes: 4 additions & 0 deletions config.yml
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,10 @@ data_providers:
    - tag: geosite
    file: "/etc/mosdns/geosite.dat"
    auto_reload: false

    # api config
    api:
    http: ":8080"

    # server config
    servers:
  5. piyoki revised this gist Aug 23, 2022. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion config.yml
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,15 @@ servers:
    plugins:
    # --- Excutable Plugins --- #
    # cache
    - tag: "mem_cache"
    # - tag: "mem_cache"
    # type: "cache"
    # args:
    # size: 1024 # query max number
    # lazy_cache_ttl: 86400 # lazy cache ttl
    # lazy_cache_reply_ttl: 30 # timeout ttl
    # cache_everything: true

    - tag: "redis_cache"
    type: "cache"
    args:
    size: 1024 # query max number
  6. piyoki renamed this gist Aug 23, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. piyoki renamed this gist Aug 23, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. piyoki revised this gist Aug 23, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # mosdns deployment
  9. piyoki revised this gist Aug 23, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion config.yml
    Original file line number Diff line number Diff line change
    @@ -333,7 +333,7 @@ plugins:
    args:
    exec:
    - _prefer_ipv4
    - if: query_ad
    - if: query_ad # ad
    exec:
    - _new_nxdomain_response # empty response
    - _return
  10. piyoki revised this gist Aug 23, 2022. 1 changed file with 12 additions and 11 deletions.
    23 changes: 12 additions & 11 deletions config.yml
    Original file line number Diff line number Diff line change
    @@ -58,6 +58,9 @@ plugins:
    lazy_cache_ttl: 86400 # lazy cache ttl
    lazy_cache_reply_ttl: 30 # timeout ttl
    cache_everything: true
    # redis config
    redis: "redis://10.189.17.4:6379/1"
    redis_timeout: 50

    # ttl
    - tag: "modify_ttl"
    @@ -292,12 +295,6 @@ plugins:
    type: sequence
    args:
    exec:
    # Ad
    - if: query_ad
    exec:
    - _new_nxdomain_response # empty response
    - _return

    # CN domains
    - if: "query_cn"
    exec:
    @@ -335,8 +332,12 @@ plugins:
    type: sequence
    args:
    exec:
    - parallel:
    - - mem_cache # cache
    - - main_sequence # run main query sequence
    - - modify_ttl

    - _prefer_ipv4
    - if: query_ad
    exec:
    - _new_nxdomain_response # empty response
    - _return
    - mem_cache # cache
    - main_sequence # run main query sequence
    - modify_ttl

  11. piyoki revised this gist Aug 23, 2022. 1 changed file with 34 additions and 0 deletions.
    34 changes: 34 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    ---
    version: "3.4"
    services:
    redis:
    container_name: redis
    image: "redis:alpine"
    command: redis-server
    ports:
    - "6379:6379"
    volumes:
    - $PWD/redis-data:/var/lib/redis
    - $PWD/redis.conf:/usr/local/etc/redis/redis.conf
    environment:
    - REDIS_REPLICATION_MODE=master
    networks:
    node_net:
    ipv4_address: 172.28.1.4
    restart: unless-stopped

    watchtower:
    container_name: watchtower
    image: containrrr/watchtower
    restart: always
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    command: ["--cleanup", "--interval", "3600", "--debug"]

    # networking for the Redis container
    networks:
    node_net:
    ipam:
    driver: default
    config:
    - subnet: 172.28.0.0/16
  12. piyoki revised this gist Aug 23, 2022. 2 changed files with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions deploy-mosdns.md
    Original file line number Diff line number Diff line change
    @@ -1,2 +0,0 @@
    ## mosdns

    Empty file added docker-compose.yml
    Empty file.
  13. piyoki revised this gist Aug 23, 2022. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions config.yml
    Original file line number Diff line number Diff line change
    @@ -335,7 +335,8 @@ plugins:
    type: sequence
    args:
    exec:
    - mem_cache # cache
    - main_sequence # run main query sequence
    - modify_ttl
    - parallel:
    - - mem_cache # cache
    - - main_sequence # run main query sequence
    - - modify_ttl

  14. piyoki revised this gist Aug 23, 2022. 1 changed file with 20 additions and 9 deletions.
    29 changes: 20 additions & 9 deletions config.yml
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    ---
    # log config
    log:
    level: debug # ["debug", "info", "warn", and "error"], default is set to "info"
    level: info # ["debug", "info", "warn", and "error"], default is set to "info"
    file: "/var/log/mosdns.log"

    # data source config
    @@ -19,6 +19,7 @@ data_providers:

    # server config
    servers:
    # main query sequence
    - exec: sequence_exec
    timeout: 5
    listeners:
    @@ -53,7 +54,7 @@ plugins:
    - tag: "mem_cache"
    type: "cache"
    args:
    size: 2048 # query max number
    size: 1024 # query max number
    lazy_cache_ttl: 86400 # lazy cache ttl
    lazy_cache_reply_ttl: 30 # timeout ttl
    cache_everything: true
    @@ -67,7 +68,7 @@ plugins:

    # --- Domestic DNS --- #
    # alidns
    - tag: ali
    - tag: ali_dos
    type: forward
    args:
    upstream:
    @@ -100,7 +101,7 @@ plugins:

    # --- Remote DNS --- #
    # google dns
    - tag: google
    - tag: google_dos
    type: forward
    args:
    upstream:
    @@ -129,7 +130,7 @@ plugins:
    enable_pipeline: true

    # cloudflare
    - tag: cloudflare
    - tag: cloudflare_dos
    type: forward
    args:
    upstream:
    @@ -261,7 +262,7 @@ plugins:
    exec:
    # - primary:
    - parallel:
    - - "ali"
    - - ali_dos
    # secondary:
    # - localdns
    # fast_fallback: 600
    @@ -274,8 +275,8 @@ plugins:
    exec:
    # - primary:
    - parallel:
    - - google
    - - cloudflare
    - - google_dos
    - - cloudflare_dos
    - - google_dot
    - - cloudflare_dot
    - - adguard # secondary
    @@ -287,7 +288,7 @@ plugins:
    # always_standby: true

    # main_sequence
    - tag: sequence_exec
    - tag: main_sequence
    type: sequence
    args:
    exec:
    @@ -328,3 +329,13 @@ plugins:
    - local
    fast_fallback: 400
    always_standby: true

    # --- sequence execution --- #
    - tag: sequence_exec
    type: sequence
    args:
    exec:
    - mem_cache # cache
    - main_sequence # run main query sequence
    - modify_ttl

  15. piyoki created this gist Aug 23, 2022.
    330 changes: 330 additions & 0 deletions config.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,330 @@
    #/etc/mosdns/config.json
    ---
    # log config
    log:
    level: debug # ["debug", "info", "warn", and "error"], default is set to "info"
    file: "/var/log/mosdns.log"

    # data source config
    data_providers:
    - tag: cn
    file: "/etc/mosdns/cn.dat"
    auto_reload: false
    - tag: geoip
    file: "/etc/mosdns/geoip.dat"
    auto_reload: false
    - tag: geosite
    file: "/etc/mosdns/geosite.dat"
    auto_reload: false

    # server config
    servers:
    - exec: sequence_exec
    timeout: 5
    listeners:
    # --- local port binding --- #
    # local ipv6
    - protocol: udp
    addr: "[::1]:53"
    - protocol: tcp
    addr: "[::1]:53"
    # local ipv4
    - protocol: udp
    addr: "127.0.0.1:53"
    - protocol: tcp
    addr: "127.0.0.1:53"

    # --- interface binding --- #
    # lag group
    - protocol: udp
    addr: "10.178.0.3:53"
    - protocol: tcp
    addr: "10.178.0.3:53"
    # vlan 17
    - protocol: udp
    addr: "10.189.17.3:53"
    - protocol: tcp
    addr: "10.189.17.3:53"

    # plugin config
    plugins:
    # --- Excutable Plugins --- #
    # cache
    - tag: "mem_cache"
    type: "cache"
    args:
    size: 2048 # query max number
    lazy_cache_ttl: 86400 # lazy cache ttl
    lazy_cache_reply_ttl: 30 # timeout ttl
    cache_everything: true

    # ttl
    - tag: "modify_ttl"
    type: "ttl"
    args:
    minimal_ttl: 300
    maximum_ttl: 3600

    # --- Domestic DNS --- #
    # alidns
    - tag: ali
    type: forward
    args:
    upstream:
    - addr: "https://dns.alidns.com/dns-query" # DoH server address
    ip_addr: # server ip addresses
    - "2400:3200:baba::1"
    - "223.5.5.5"
    - "2400:3200::1"
    - "223.6.6.6"
    trusted: true
    - addr: "tls://dns.alidns.com" # TLS server address
    ip_addr: # server ip addresses
    - "2400:3200:baba::1"
    - "223.5.5.5"
    - "2400:3200::1"
    - "223.6.6.6"
    trusted: true

    bootstrap:
    - "tls://1.1.1.1"
    - "https://223.5.5.5/dns-query"
    timeout: 5 # default timeout

    # --- Local DNS --- #
    - tag: localdns
    type: forward
    args:
    upstream:
    - addr: "178.0.50.6:53"

    # --- Remote DNS --- #
    # google dns
    - tag: google
    type: forward
    args:
    upstream:
    - addr: "https://dns.google/dns-query" # DoH server address
    ip_addr: # server ip addresses
    - "2001:4860:4860::8844"
    - "8.8.4.4"
    - "2001:4860:4860::8888"
    - "8.8.8.8"
    trusted: true
    - tag: google_dot
    type: fast_forward
    args:
    upstream:
    - addr: "tls://dns.google"
    dial_addr: "8.8.4.4"
    trusted: true
    enable_pipeline: true
    - addr: "tls://dns.google"
    dial_addr: "2001:4860:4860::8888"
    trusted: true
    enable_pipeline: true
    - addr: "tls://dns.google"
    dial_addr: "8.8.8.8"
    trusted: true
    enable_pipeline: true

    # cloudflare
    - tag: cloudflare
    type: forward
    args:
    upstream:
    - addr: "https://cloudflare-dns.com/dns-query" # DoH server address
    ip_addr: # server ip addresses
    - "2606:4700:4700::1001"
    - "1.0.0.1"
    - "2606:4700:4700::1111"
    - "1.1.1.1"
    trusted: true
    - tag: cloudflare_dot
    type: fast_forward
    args:
    upstream:
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "2606:4700:4700::1001"
    trusted: true
    enable_pipeline: true
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "1.0.0.1"
    trusted: true
    enable_pipeline: true
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "2606:4700:4700::1111"
    trusted: true
    enable_pipeline: true
    - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
    dial_addr: "1.0.0.1"
    trusted: true
    enable_pipeline: true

    # h3 parallel
    - tag: google_h3
    type: "fast_forward"
    args:
    # upstream servers, at lease to configure one, send request in parallel to all servers
    upstream:
    - addr: "https://dns.google/dns-query"
    dial_addr: "2001:4860:4860::8844"
    trusted: true
    enable_http3: true
    - addr: "https://dns.google/dns-query"
    dial_addr: "8.8.4.4"
    trusted: true
    enable_http3: true
    - addr: "https://dns.google/dns-query"
    dial_addr: "2001:4860:4860::8888"
    trusted: true
    enable_http3: true
    - addr: "https://dns.google/dns-query"
    dial_addr: "8.8.8.8"
    trusted: true
    enable_http3: true
    - tag: cloudflare_h3
    type: "fast_forward"
    args:
    upstream:
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "2606:4700:4700::1001"
    trusted: true
    enable_http3: true
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "1.0.0.1"
    trusted: true
    enable_http3: true
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "2606:4700:4700::1111"
    trusted: true
    enable_http3: true
    - addr: "https://cloudflare-dns.com/dns-query"
    dial_addr: "1.1.1.1"
    trusted: true
    enable_http3: true

    # doq backup resolver
    - tag: adguard
    type: forward
    args:
    upstream:
    - addr: "quic://dns-unfiltered.adguard.com" # DoQ server
    ip_addr: # server addresses
    - "2a10:50c0::1:ff"
    - "94.140.14.140"
    - "2a10:50c0::2:ff"
    - "94.140.14.141"
    trusted: true

    # --- query matcher --- #
    # query - CN domains
    - tag: query_cn
    type: query_matcher
    args:
    domain:
    - "provider:geosite:cn"

    # query - GFW domains
    - tag: query_gfw
    type: query_matcher
    args:
    domain:
    - "provider:geosite:gfw"

    # query - non-CN domains
    - tag: query_notcn
    type: query_matcher
    args:
    domain:
    - "provider:geosite:geolocation-!cn"

    # query - ad
    - tag: query_ad
    type: query_matcher
    args:
    domain:
    - "provider:geosite:category-ads-all"

    # query - CN IP
    - tag: response_cnip
    type: response_matcher
    args:
    ip:
    - "provider:geoip:cn"

    # --- Sequence --- #
    # local sequence
    - tag: local
    type: sequence
    args:
    exec:
    # - primary:
    - parallel:
    - - "ali"
    # secondary:
    # - localdns
    # fast_fallback: 600
    # always_standby: true

    # remote sequence
    - tag: remote
    type: sequence
    args:
    exec:
    # - primary:
    - parallel:
    - - google
    - - cloudflare
    - - google_dot
    - - cloudflare_dot
    - - adguard # secondary
    - - google_h3
    - - cloudflare_h3
    # secondary:
    # - adguard
    # fast_fallback: 600
    # always_standby: true

    # main_sequence
    - tag: sequence_exec
    type: sequence
    args:
    exec:
    # Ad
    - if: query_ad
    exec:
    - _new_nxdomain_response # empty response
    - _return

    # CN domains
    - if: "query_cn"
    exec:
    - _prefer_ipv4 # ipv4 as priority
    - _pad_query
    - local # local ip as result
    - if: "response_cnip" # cnip as result
    exec:
    - _return # end

    # non-CN domains
    - if: query_notcn
    exec:
    - _prefer_ipv4 # ipv4 as priority
    - _pad_query
    - remote # uncontaminated ip
    - if: "!response_cnip" # non-CN ip as result
    exec:
    - _return # end

    # other condition
    - primary:
    - _prefer_ipv4
    - _pad_query
    - remote
    secondary:
    - _prefer_ipv4
    - _pad_query
    - local
    fast_fallback: 400
    always_standby: true
    2 changes: 2 additions & 0 deletions deploy-mosdns.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    ## mosdns