Skip to main content

Configure port forwarding

For your information

This manual provides instructions for configuring port forwarding on a firewall to access servers via SSH.

To access a server behind a firewall, you can configure port forwarding (port forwarding). This allows you to connect to a server using the public IP address of the firewall without needing to know the private address of the server. Users will connect to the server only through the ports you specify in the settings.

The settings in this manual are relevant for FortiOS 6.x and 7.x versions. If you are using a different version of FortiOS, you can find the documentation for it in the FortiGate control panel in the upper right corner or on the official FortiGate website.

To configure port forwarding:

  1. Create a virtual IP address.
  2. Optional: create a virtual IP address group.
  3. Create a security policy.

1. Create a virtual IP address

A virtual IP address maps the public address of the firewall to a private address of a server behind the firewall. When a user tries to connect using the public address, FortiGate redirects the request to the required server.

  1. Connect to the firewall.

  2. Go to Policy & ObjectsVirtual IPs.

  3. Click Create New and select Virtual IP.

  4. In the VIP Type section, select IPv4.

  5. In the Name field, enter a name for the virtual IP address.

  6. Optional: in the Comments field, enter a comment for the virtual IP address.

  7. In the Interface field, specify the firewall interface through which the virtual IP address will be accessible:

    • to make the IP address accessible only through one interface, select that interface. For example, wan1;
    • to make the IP address accessible through all interfaces, select any.
  8. In the External IP Address/Range field, specify the public IP address of the firewall you received in the ticket after ordering the service.

  9. In the Mapped IP Address field, specify the private address of the server behind the firewall to which you want to configure SSH access.

  10. Enable the Port Forwarding toggle.

  11. In the Protocol field, select TCP.

  12. In the External Service Port field, specify an available port on the firewall. For example, 8080.

  13. In the Map to Port field, specify the port on which the SSH service is running on the server behind the firewall. By default, this is port 22.

  14. Click OK.

2. Optional: create a virtual IP address group

Virtual IP address groups simplify security policy management: a policy is applied to the entire group rather than to each IP address individually. For example, you can allow SSH connections to all IP addresses in a group at once.

  1. In the FortiGate control panel, go to Policy & ObjectsVirtual IPs.

  2. Click Create New and select Virtual IP Group.

  3. In the Type field, select IPv4.

  4. In the Name field, enter a name for the virtual IP address group.

  5. Optional: in the Comments field, enter a comment for the virtual IP address group.

  6. In the Interface field, specify the firewall interface through which the virtual IP address group will be accessible:

    • if all IP addresses in the group are bound to one interface, select that interface. For example, wan1;
    • if IP addresses in the group are bound to different interfaces, select any.
  7. In the Members field, select the virtual IP addresses you want to include in the group — the virtual IP address you created in step 1, and other IP addresses.

  8. Click OK.

3. Create a security policy

A security policy determines which traffic a firewall will allow between its interfaces. For example, using a policy, you can allow connections to servers behind the firewall from a specific IP address and on a specific port. If no security policies are created, all traffic is dropped.

  1. In the FortiGate control panel, go to Policy & ObjectsIPv4 Policy.

  2. Click Create New.

  3. In the Name field, enter a name for the security policy.

  4. In the Incoming Interface field, select the public firewall interface.

  5. In the Outgoing Interface field, select the private firewall interface.

  6. In the Source field, select all.

  7. In the Destination field, select a destination address:

  8. In the Schedule field, select always.

  9. In the Service field, select all.

  10. In the Action field, select Accept.

  11. Disable the NAT toggle. Servers behind the firewall will receive original connection IP addresses.

  12. Click OK.