Skip to content

Commit

Permalink
use system dns config as default
Browse files Browse the repository at this point in the history
  • Loading branch information
xjdrew committed Jan 5, 2024
1 parent 649d14c commit 9c896fd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 22 deletions.
29 changes: 16 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# 2023/12/26
- [x] feat: upgrade to surge like config
- [x] feat: support windows 10
- [x] tech: merge proxy code
- [x] feat: reload rule by manager: curl http://127.0.0.1:9200/reload

# plan
- [ ] feat: default hijack dns query
- [ ] feat: show process name of network
- [ ] bug: traffic will be endless loop if proxy's ip use proxy by rule
- [ ] feat: support ss protocol
- [ ] feat: support IPv6
- [ ] feat: update GEOIP database
# 2023/12/26
- [x] feat: upgrade to surge like config
- [x] feat: support windows 10
- [x] tech: merge proxy code
- [x] feat: reload rule by manager: curl http://127.0.0.1:9200/reload
- [x] tech: use system dns config as default

# plan
- [ ] feat: default hijack dns query
- [ ] feat: show process name of network
- [ ] bug: traffic will be endless loop if proxy's ip use proxy by rule
- [ ] feat: support ss protocol
- [ ] feat: support IPv6
- [ ] feat: update GEOIP database
- [ ] feat: record all dns query
- [ ] feat: support for internal domain name resolution
6 changes: 3 additions & 3 deletions cmd/kone/test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ network = 10.192.0.1/16
# dns-read-timeout = 5
# dns-write-timeout = 5

# upstream dns
# DEFAULT VALUE: 114.114.114.114,223.5.5.5
dns-server = 114.114.114.114,8.8.8.8
# set upstream dns
# DEFAULT VALUE: system dns config
# dns-server = 114.114.114.114,8.8.8.8

[Proxy]
# define a http proxy named "Proxy1"
Expand Down
12 changes: 11 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"unicode"

"github.com/xjdrew/dnsconfig"
"gopkg.in/ini.v1"
)

Expand Down Expand Up @@ -94,6 +95,15 @@ func (cfg *KoneConfig) check() (err error) {
return nil
}

func (cfg *KoneConfig) GetSystemDnsservers() (servers []string) {
config := dnsconfig.ReadDnsConfig()
if config.Err != nil {
logger.Warningf("read dns config failed: %v", config.Err)
return []string{"114.114.114.114", "8.8.8.8"} // default
}
return config.Servers
}

func ParseConfig(source interface{}) (*KoneConfig, error) {
cfg := new(KoneConfig)
cfg.source = source
Expand Down Expand Up @@ -150,7 +160,7 @@ func ParseConfig(source interface{}) (*KoneConfig, error) {

// set backend dns default value
if len(cfg.Core.DnsServer) == 0 {
cfg.Core.DnsServer = append(cfg.Core.DnsServer, "114.114.114.114", "223.5.5.5")
cfg.Core.DnsServer = cfg.GetSystemDnsservers()
}

// init rule
Expand Down
10 changes: 8 additions & 2 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ func NewDns(one *One, cfg CoreConfig) (*Dns, error) {
d := new(Dns)
d.one = one

dnsListenAddr := fmt.Sprintf("%s:%d", fixTunIP(one.ip), cfg.DnsListenPort)
server := &dns.Server{
Net: "udp",
Addr: fmt.Sprintf("%s:%d", fixTunIP(one.ip), cfg.DnsListenPort),
Addr: dnsListenAddr,
Handler: dns.HandlerFunc(d.ServeDNS),
UDPSize: int(cfg.DnsPacketSize),
ReadTimeout: time.Duration(cfg.DnsReadTimeout) * time.Second,
Expand All @@ -212,8 +213,13 @@ func NewDns(one *One, cfg CoreConfig) (*Dns, error) {

for _, addr := range cfg.DnsServer {
if !strings.Contains(addr, ":") {
d.nameservers = append(d.nameservers, addr+":53")
addr = addr + ":53"
}

if addr != dnsListenAddr { // don't add self
d.nameservers = append(d.nameservers, addr)
}
}
logger.Infof("[dns] updstream dns server: %v", d.nameservers)
return d, nil
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/xjdrew/kone

go 1.20
go 1.21.5

require (
github.com/miekg/dns v1.1.57
Expand All @@ -14,6 +14,7 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xjdrew/dnsconfig v0.0.0-20240104111907-3ab1a6f060b1
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/thecodeteam/goodbye v0.0.0-20170927022442-a83968bda2d3 h1:COy7ekr2jBEd34npP2LvMTqk9UtiLkuvkjiJFHihlTo=
github.com/thecodeteam/goodbye v0.0.0-20170927022442-a83968bda2d3/go.mod h1:ehwM4AFY4byYSorQbigh79cKUOUNL3pAOz5eCAQNlGI=
github.com/xjdrew/dnsconfig v0.0.0-20240104111907-3ab1a6f060b1 h1:8zrZIsWKgXLNQedGAPwaYK4OZ8EwWf/hWZhsvTD3MW4=
github.com/xjdrew/dnsconfig v0.0.0-20240104111907-3ab1a6f060b1/go.mod h1:/6pBv59OGlUWZwToHJ7Aj5jBuWZJJArx0fRDpHoYJtI=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
Expand Down
4 changes: 2 additions & 2 deletions misc/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## 预设条件
1. 安装 tap-windows (NDIS 6)

[tap-windows](https://community.openvpn.net/openvpn/wiki/GettingTapWindows)
[直接下载](https://build.openvpn.net/downloads/releases/tap-windows-9.21.0.exe)
* [tap-windows](https://community.openvpn.net/openvpn/wiki/GettingTapWindows)
* [直接下载](https://build.openvpn.net/downloads/releases/tap-windows-9.21.0.exe)

2. 配置防火墙,允许kone重定向连接
使用管理员权限启动 PowerShell,执行`update-firewall-rules.ps1`
Expand Down

0 comments on commit 9c896fd

Please sign in to comment.