Skip to content

Commit

Permalink
frpc: support specify default dns server, close fatedier#700
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier committed Apr 22, 2018
1 parent c47aad3 commit 00b9ba9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/frpc/sub/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package sub

import (
"context"
"fmt"
"io/ioutil"
"net"
"os"
"os/signal"
"strconv"
Expand Down Expand Up @@ -188,6 +190,19 @@ func runClient(cfgFilePath string) (err error) {

func startService(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]config.ProxyConf) (err error) {
log.InitLog(g.GlbClientCfg.LogWay, g.GlbClientCfg.LogFile, g.GlbClientCfg.LogLevel, g.GlbClientCfg.LogMaxDays)
if g.GlbClientCfg.DnsServer != "" {
s := g.GlbClientCfg.DnsServer
if !strings.Contains(s, ":") {
s += ":53"
}
// Change default dns server for frpc
net.DefaultResolver = &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
return net.Dial("udp", s)
},
}
}
svr := client.NewService(pxyCfgs, visitorCfgs)

// Capture the exit signal if we use kcp.
Expand Down
3 changes: 3 additions & 0 deletions conf/frpc_full.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ login_fail_exit = true
# now it supports tcp and kcp, default is tcp
protocol = tcp

# specify a dns server, so frpc will use this instead of default one
dns_server = 8.8.8.8

# proxy names you want to start divided by ','
# default is empty, means all proxies
# start = ssh,dns
Expand Down
6 changes: 6 additions & 0 deletions models/config/client_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ClientCommonConf struct {
PoolCount int `json:"pool_count"`
TcpMux bool `json:"tcp_mux"`
User string `json:"user"`
DnsServer string `json:"dns_server"`
LoginFailExit bool `json:"login_fail_exit"`
Start map[string]struct{} `json:"start"`
Protocol string `json:"protocol"`
Expand All @@ -64,6 +65,7 @@ func GetDefaultClientConf() *ClientCommonConf {
PoolCount: 1,
TcpMux: true,
User: "",
DnsServer: "",
LoginFailExit: true,
Start: make(map[string]struct{}),
Protocol: "tcp",
Expand Down Expand Up @@ -166,6 +168,10 @@ func UnmarshalClientConfFromIni(defaultCfg *ClientCommonConf, content string) (c
cfg.User = tmpStr
}

if tmpStr, ok = conf.Get("common", "dns_server"); ok {
cfg.DnsServer = tmpStr
}

if tmpStr, ok = conf.Get("common", "start"); ok {
proxyNames := strings.Split(tmpStr, ",")
for _, name := range proxyNames {
Expand Down

0 comments on commit 00b9ba9

Please sign in to comment.