This commit is contained in:
netbyte 2022-05-10 21:31:21 +08:00
parent 1101ef030d
commit 4d5bfbb59e
2 changed files with 1 additions and 8 deletions

View File

@ -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 {

View File

@ -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())