diff --git a/wsl/wsl_network_fix.ps1 b/wsl/wsl_network_fix.ps1 index 9497ad6b..e12ddca5 100644 --- a/wsl/wsl_network_fix.ps1 +++ b/wsl/wsl_network_fix.ps1 @@ -70,7 +70,7 @@ begin { } # instantiate string builder - $builder = [System.Text.StringBuilder]::new("# Generated by wsl_network_fix.ps1 on $((Get-Date).ToString('s'))") + $builder = [System.Text.StringBuilder]::new("# Generated by wsl_network_fix.ps1 on $((Get-Date).ToString('s'))`n") } process { @@ -113,20 +113,20 @@ process { $idx = -1 $selection = Read-Host -Prompt "Please select the interface for propagating DNS Servers:`n$($list | Format-Table | Out-String)" [bool]$returnedInt = [int]::TryParse($selection, [ref]$idx) - } until ($returnedInt -and $idx -ge 0 -and $idx -lt $netAdapters.Count) + } until ($returnedInt -and $idx -ge 0 -and $idx -lt $ipConfig.Count) $dnsServers = $ipConfig[$idx].DNSServer $dnsServers.ForEach({ $builder.AppendLine("nameserver $_") | Out-Null }) } - # get DNS suffix search list - $searchSuffix = (Get-DnsClientGlobalSetting).SuffixSearchList -join ',' - if ($searchSuffix) { - $builder.AppendLine("search $searchSuffix") | Out-Null - } # get distro default gateway $def_gtw = (wsl.exe -d $Distro -u root --exec sh -c 'ip route show default' | Select-String '(?<=via )[\d\.]+(?= dev)').Matches.Value if ($def_gtw) { $builder.AppendLine("nameserver $def_gtw") | Out-Null } + # get DNS suffix search list + $searchSuffix = (Get-DnsClientGlobalSetting).SuffixSearchList -join ',' + if ($searchSuffix) { + $builder.AppendLine("search $searchSuffix") | Out-Null + } $builder.AppendLine('options timeout:1 retries:1') | Out-Null $resolvConf = $builder.ToString().Replace("`r`n", "`n") # save resolv.conf file