Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use New-NetNat instead of SharedAccess to make wi-fi hotspot work #18

Closed
kenvix opened this issue Jan 5, 2022 · 3 comments
Closed

Use New-NetNat instead of SharedAccess to make wi-fi hotspot work #18

kenvix opened this issue Jan 5, 2022 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@kenvix
Copy link

kenvix commented Jan 5, 2022

Recently I found that once wireguard server's NAT is enable, I will not able to create a wi-fi hotspot with Internet access.

Why should not use SharedAccess ?

This service is made for hotspot and can only support one NAT instance, meaning that, you will not able to set up a Wi-Fi hotspot with Internet access because SharedAccess services has been occupied by wireguard server's NAT

However, with New-NetNat command, you'll able to set up many NAT instances and keep wi-fi hotspot work.

How to set up NAT with New-NetNat?

Requirements:

  • Windows 10 Anniversary Update or later
  • Hyper-V is enabled (But you can set hypervisorlaunchtype to off in bcdedit if you dont want to use hyper-v!) There no is need for hyper-v installation

Disable Internet sharing first.
Snipaste_2022-01-05_11-07-48

Then, open powershell with admin permission

# First, get your interface index of wg_server interface
Get-NetAdapter
# Give a IP to wg_server interface
New-NetIPAddress -IPAddress 172.22.0.1 -PrefixLength 24 -InterfaceIndex 68 # Your interface index here
New-NetNat -Name wgservernat -InternalIPInterfaceAddressPrefix 172.22.0.0/24 # Your NAT name and interface CIDR here
Get-NetNat # 

Snipaste_2022-01-05_11-25-42

For test purpose, you can disable SharedAccess service and will find that NAT is working still .
Snipaste_2022-01-05_11-37-26

For more information, check this article

Please note New-NetIPAddress should be executed every time you reboot

@kenvix kenvix changed the title Use New-NetNat instead of SharedAccess Use New-NetNat instead of SharedAccess to make wi-fi hotspot work Jan 5, 2022
@micahmo
Copy link
Owner

micahmo commented Jan 5, 2022

Hey @kenvix, thanks for sharing this! There have been numerous issues with SharedAccess, including the limitation of only one shared network at a time, so I like the idea of New-NetNat. SharedAccess should still be supported for older versions of Windows.

I can't promise that this will be added any time soon, but I appreciate the suggestion.

@micahmo micahmo added the enhancement New feature or request label Jan 5, 2022
@micahmo micahmo added this to the v1.7.0 milestone Feb 5, 2022
@kenvix
Copy link
Author

kenvix commented Mar 8, 2022

Update: There no is need for hyper-v installation (Win10 10.0.19044)

Additionally, a powershell script for someone who want to execute New-NetIPAddress automatically at startup:

#Requires -RunAsAdministrator
$ifName = "wg_server" 
function Get-IfIndex() {
    return (Get-NetAdapter | Where -Property Status -eq 'Up' | Where -Property Name -Like $ifName | select -ExpandProperty ifIndex -first 1)
}
$ifIndex = Get-IfIndex
while ( $ifIndex -eq $null -Or $ifIndex  -eq "" ) {
    echo "Waiting interface $ifName up ..."
    sleep 3s   
    $ifIndex = Get-IfIndex
}
echo "$ifName Interface index is $ifIndex"
echo "Setting up IpAddr"
New-NetIPAddress -IPAddress 172.22.0.1 -PrefixLength 24 -InterfaceIndex $ifIndex
exit 0

@micahmo
Copy link
Owner

micahmo commented Mar 8, 2022

Thanks @kenvix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants