dnsforwarder
一个简单的 DNS 转发代理
主要功能:
- 指定不同的域名使用不同的服务器(支持非标准端口)、不同的协议(UDP、TCP)进行查询;
- DNS 缓存及相关的控制(支持自定义 TTL);
- 屏蔽包含指定的 IP 的 DNS 数据包;
- Hosts 功能(支持通配符、CName 指定、网络 Hosts);
- 屏蔽指定的域名查询请求(广告屏蔽?);
- 跨平台(Windows、Linux);
安装和部署
参考 default.config
。
配置逻辑
host 匹配顺序:
DisabledList
, 行数据 < 512 字节。
- Hosts {
AppendHosts
(静态) -> hosts 文件(动态)}
类型:支持 IPv4、IPv6、@@
(跳过)、\ (GoodIPList
) 和 CName
- DNS 缓存。
- (ServerGroup =
GroupFile
+ UDPGroup
+ TCPGroup
) {
行数据 < 384 字节;
全被转为小写;
#
和;
后面为注释;
相同 domain 时后面的规则生效(Last In First Match);
GroupFile
路径语法: Win: ExpandEnvironmentStrings
, *nix: wordexp
。
}
- 无匹配时选择一组上级 DNS 转发查询。
DisabledList, GroupFile 的 domain 匹配:
- 无通配符: 全部 || 每一个
.
后面的部分;
- 有通配符: Win:
PathMatchSpec(,)
; *nix: fnmatch(,,)
。
Log 类型缩写
Alias |
Description |
B |
Bad |
C |
Cache |
H |
Hosts records |
INFO |
Information |
R |
Rejected |
S |
Tls |
T |
TCP |
U |
UDP |
A simple DNS forwarder
Main Fetures:
- Forwarding queries to customized domains (and their subdomains) to specified servers over a specified protocol (UDP or TCP). non-standard ports are supported;
- DNS cache and its controls (including modifying TTL for different domains);
- Ignoring DNS responses from upstream servers containing particular IPs;
- Loading hosts from file (including the support for wildcards, CName redirections and remote hosts files);
- Refusing queries to specified domains (for ads blocking?);
- Cross-platform (Windows, Linux);
Installation & Deployment
Read default.en.config
.
Configuring Logic
host matching order:
DisabledList
, line length < 512 chars
- Hosts {
AppendHosts
(StaticHosts) -> hosts-files (DynamicHosts)}
Types:supports IPv4, IPv6, @@
(skipping), \ (GoodIPList
) and CName
- DNS Cache
- (ServerGroup =
GroupFile
+ UDPGroup
+ TCPGroup
) {
line length < 384 chars;
converted to lower case before testing;
#
or ;
leads comments;
for the same domain rules, the last wins (Last In First Match);
GroupFile
path syntax: Win: ExpandEnvironmentStrings
, *nix: wordexp
.
}
- If none matches, forward it to 1 group of upstream DNS.
Domain Matching for DisabledList, GroupFile:
- No Wild Card: Full || Right part of each
.
;
- Wild Card: Win:
PathMatchSpec(,)
; *nix: fnmatch(,,)
。
Log Flags
Alias |
Description |
B |
Bad |
C |
Cache |
H |
Hosts records |
INFO |
Information |
R |
Rejected |
S |
Tls |
T |
TCP |
U |
UDP |
License :
GPL v3
Dependencies :
For Linux:
pthread;
libcurl (optional);
For Windows:
None.
Macros needed to be declared while compiling :
For Linux:
None.
For Windows x86 (at least Windows XP)
_WIN32
For Windows x86-64 (at least Windows Vista):
_WIN32
_WIN64
Build
CI.yml