Port forwarding is a technique used to allow external devices to access services on a private network via a public IP address. In Windows Server, this is usually done via the Routing and Remote Access feature or using PowerShell. Here is a step-by-step tutorial using both methods:
Using Routing and Remote Access for Port Forwarding
- Install the Routing and Remote Access Service:
- Open
Gerenciador do Servidor
. - Click on
Adicionar funções e recursos
. - Go to
Serviços de Acesso e Política de Rede
and bookmarkRoteamento
. - Follow the instructions to complete the installation.
- Open
- Configure Routing and Remote Access:
- On
Gerenciador do Servidor
, go toFerramentas
and selectRoteamento e Acesso Remoto
. - Right-click on the server and choose
Configurar e Habilitar Roteamento e Acesso Remoto
. - Follow the wizard, selecting
Acesso à rede privada virtual (VPN) e NAT
when prompted.
- On
- Add the Port Redirection Rule:
- In the console tree, right-click on
NAT
, under your server, and chooseNovo Serviço
. - In the wizard, provide the internal IP address of the service you are redirecting to and the port.
- In the console tree, right-click on
- Finish and Test:
- Complete the configuration and test the port forwarding by accessing the service externally using the server’s public IP address and the configured port.
Using PowerShell for Port Forwarding
For advanced users, PowerShell can be a powerful tool for configuring port forwarding.
- Open PowerShell as Administrator.
- Use the command
New-NetNat
to create a NAT instance, if there isn’t one already:
New-NetNat –Name NATNetwork –InternalIPInterfaceAddressPrefix "192.168.0.0/24"
Replace 192.168.0.0/24
with your local IP address range.
- Add a port forwarding rule using
Add-NetNatStaticMapping
:
Add-NetNatStaticMapping -NatName NATNetwork -Protocol TCP -ExternalIPAddress 0.0.0.0 -InternalIPAddress 192.168.0.100 -InternalPort 80 -ExternalPort 8080
In this example, traffic on external port 8080 is directed to port 80 of the device with IP address 192.168.0.100. Adjust the parameters as required for your configuration.
- Check the configuration with
Get-NetNatStaticMapping
:
Get-NetNatStaticMapping
This will list all the static mapping rules configured.
Final Notes
- Make sure that the firewall rules on the Windows Server allow traffic on the configured ports.
- Test port forwarding internally and externally to ensure that it is working as expected.
- Using PowerShell offers more flexibility and may be more suitable for automated environments or for users with advanced requirements.
This tutorial covers the basics of port forwarding in Windows Server. Depending on your specific environment and Windows Server version, some steps may vary.