mirror of
https://github.com/net-byte/vtun
synced 2024-03-14 10:50:03 +08:00
add dns
This commit is contained in:
parent
d986163492
commit
8245e4a8ce
@ -25,6 +25,8 @@ Usage of ./vtun:
|
||||
protocol ws/wss/udp (default "wss")
|
||||
-s string
|
||||
server address (default ":3001")
|
||||
-d string
|
||||
dns address (default "8.8.8.8:53")
|
||||
-P enable pporf server on :6060
|
||||
-S server mode
|
||||
-g client global mode
|
||||
|
@ -13,6 +13,7 @@ type Config struct {
|
||||
CIDR string
|
||||
Key string
|
||||
Protocol string
|
||||
DNS string
|
||||
ServerMode bool
|
||||
GlobalMode bool
|
||||
Obfuscate bool
|
||||
|
@ -40,6 +40,13 @@ func GetAddr(b []byte) (srcAddr string, dstAddr string) {
|
||||
}
|
||||
|
||||
func ConnectServer(config config.Config) net.Conn {
|
||||
net.DefaultResolver = &net.Resolver{
|
||||
PreferGo: true,
|
||||
Dial: func(ctx context.Context, network, _ string) (net.Conn, error) {
|
||||
var dialer net.Dialer
|
||||
return dialer.DialContext(ctx, network, config.DNS)
|
||||
},
|
||||
}
|
||||
scheme := "ws"
|
||||
if config.Protocol == "wss" {
|
||||
scheme = "wss"
|
||||
|
1
main.go
1
main.go
@ -17,6 +17,7 @@ func main() {
|
||||
flag.StringVar(&config.ServerAddr, "s", ":3001", "server address")
|
||||
flag.StringVar(&config.Key, "k", "6w9z$C&F)J@NcRfWjXn3r4u7x!A%D*G-", "key")
|
||||
flag.StringVar(&config.Protocol, "p", "wss", "protocol ws/wss/udp")
|
||||
flag.StringVar(&config.DNS, "d", "8.8.8.8:53", "dns address")
|
||||
flag.BoolVar(&config.ServerMode, "S", false, "server mode")
|
||||
flag.BoolVar(&config.GlobalMode, "g", false, "client global mode")
|
||||
flag.BoolVar(&config.Obfuscate, "o", false, "enable data obfuscation")
|
||||
|
@ -40,8 +40,8 @@ func configTun(config config.Config, iface *water.Interface) {
|
||||
if physicalIface != "" && serverIP != "" {
|
||||
execCmd("/sbin/ip", "route", "add", "0.0.0.0/1", "dev", iface.Name())
|
||||
execCmd("/sbin/ip", "route", "add", "128.0.0.0/1", "dev", iface.Name())
|
||||
execCmd("/sbin/ip", "route", "delete", strings.Join([]string{serverIP, "32"}, "/"), "via", gateway, "dev", physicalIface)
|
||||
execCmd("/sbin/ip", "route", "add", strings.Join([]string{serverIP, "32"}, "/"), "via", gateway, "dev", physicalIface)
|
||||
execCmd("/sbin/ip", "route", "add", strings.Join([]string{strings.Split(config.DNS, ":")[0], "32"}, "/"), "via", gateway, "dev", physicalIface)
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,7 @@ func configTun(config config.Config, iface *water.Interface) {
|
||||
serverIP := netutil.LookupIP(strings.Split(config.ServerAddr, ":")[0])
|
||||
if physicalIface != "" && serverIP != "" {
|
||||
execCmd("route", "add", serverIP, localGateway)
|
||||
execCmd("route", "add", strings.Split(config.DNS, ":")[0], localGateway)
|
||||
execCmd("route", "add", "0.0.0.0/1", "-interface", iface.Name())
|
||||
execCmd("route", "add", "128.0.0.0/1", "-interface", iface.Name())
|
||||
execCmd("route", "add", "default", gateway.String())
|
||||
|
Loading…
Reference in New Issue
Block a user