Port forwarding in Windows Server

shape
shape
shape
shape
shape
shape
shape
shape

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

  1. 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 bookmark Roteamento.
    • Follow the instructions to complete the installation.
  2. Configure Routing and Remote Access:
    • On Gerenciador do Servidor, go to Ferramentas and select Roteamento 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.
  3. Add the Port Redirection Rule:
    • In the console tree, right-click on NAT, under your server, and choose Novo Serviço.
    • In the wizard, provide the internal IP address of the service you are redirecting to and the port.
  4. 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.

  1. Open PowerShell as Administrator.
  2. 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.

  1. 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.

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest news

Latest news directly from our blog.