diff --git a/app/app.go b/app/app.go index 1d93902b9..66982fa28 100644 --- a/app/app.go +++ b/app/app.go @@ -123,7 +123,7 @@ func runWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoint str if opts.Tun { // Create a new tun interface - tunDev, err := newNormalTun() + tunDev, err := newNormalTun([]netip.Addr{opts.DnsAddr}) if err != nil { return err } @@ -224,7 +224,7 @@ func runWarpInWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoi if opts.Tun { // Create a new tun interface - tunDev, err := newNormalTun() + tunDev, err := newNormalTun([]netip.Addr{opts.DnsAddr}) if err != nil { return err } diff --git a/app/tun_others.go b/app/tun_others.go index 0985ab72a..78e5f1703 100644 --- a/app/tun_others.go +++ b/app/tun_others.go @@ -3,17 +3,18 @@ package app import ( + "net/netip" + "github.com/bepass-org/warp-plus/wireguard/device" wgtun "github.com/bepass-org/warp-plus/wireguard/tun" ) -func newNormalTun() (wgtun.Device, error) { +func newNormalTun(_ []netip.Addr) (wgtun.Device, error) { tunDev, err := wgtun.CreateTUN("warp0", 1280) if err != nil { return nil, err } return tunDev, nil - } func bindToIface(_ *device.Device) error { diff --git a/app/tun_windows.go b/app/tun_windows.go index e4e94457c..a9d972cdc 100644 --- a/app/tun_windows.go +++ b/app/tun_windows.go @@ -18,7 +18,7 @@ const wintunGUID = "c33d325f-20cd-44e5-998c-19b0c15b4df1" const family4 = winipcfg.AddressFamily(windows.AF_INET) const family6 = winipcfg.AddressFamily(windows.AF_INET6) -func newNormalTun() (wgtun.Device, error) { +func newNormalTun(dns []netip.Addr) (wgtun.Device, error) { guid, _ := windows.GUIDFromString(wintunGUID) tunDev, err := wgtun.CreateTUNWithRequestedGUID("warp0", &guid, 1280) if err != nil { @@ -96,6 +96,11 @@ tryAgain6: return nil, fmt.Errorf("unable to set metric and MTU: %w", err) } + err = luid.SetDNS(family4, dns, nil) + if err != nil { + return nil, fmt.Errorf("unable to set DNS: %w", err) + } + return tunDev, nil }