diff --git a/common/netutil/netutil.go b/common/netutil/netutil.go index c3c788b..de1842c 100644 --- a/common/netutil/netutil.go +++ b/common/netutil/netutil.go @@ -160,12 +160,7 @@ func ExecCmd(c string, args ...string) string { } func GetLinuxDefaultGateway() string { - gateway := ExecCmd("sh", "-c", "netstat -r | grep 'default' | awk '{print $2}'") - if net.ParseIP(gateway) != nil { - return gateway - } - nslookup := "nslookup " + gateway + " | awk '/^Address: / { print $2 ; exit }'" - return ExecCmd("sh", "-c", nslookup) + return ExecCmd("sh", "-c", "route -n | grep 'UG[ \t]' | awk '{print $2}'") } func GetMacDefaultGateway() string { diff --git a/tun/tun.go b/tun/tun.go index adcf9dc..ec51050 100644 --- a/tun/tun.go +++ b/tun/tun.go @@ -41,7 +41,6 @@ func configTun(config config.Config, iface *water.Interface) { netutil.ExecCmd("/sbin/ip", "route", "add", "128.0.0.0/1", "dev", iface.Name()) netutil.ExecCmd("/sbin/ip", "route", "add", "8.8.8.8/32", "via", config.DefaultGateway, "dev", physicalIface) netutil.ExecCmd("/sbin/ip", "route", "add", strings.Join([]string{serverIP, "32"}, "/"), "via", config.DefaultGateway, "dev", physicalIface) - //netutil.ExecCmd("/sbin/ip", "route", "add", strings.Join([]string{config.DefaultDNS, "32"}, "/"), "via", config.DefaultGateway, "dev", physicalIface) } } @@ -53,7 +52,6 @@ func configTun(config config.Config, iface *water.Interface) { serverIP := netutil.LookupIP(strings.Split(config.ServerAddr, ":")[0]) if physicalIface != "" && serverIP != "" { netutil.ExecCmd("route", "add", serverIP, config.DefaultGateway) - //netutil.ExecCmd("route", "add", config.DefaultDNS, config.DefaultGateway) netutil.ExecCmd("route", "add", "8.8.8.8", config.DefaultGateway) netutil.ExecCmd("route", "add", "0.0.0.0/1", "-interface", iface.Name()) netutil.ExecCmd("route", "add", "128.0.0.0/1", "-interface", iface.Name())