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.

Для доступа к серверу за межсетевым экраном можно настроить переадресацию портов (port forwarding). Это позволяет подключаться к серверу по публичному IP-адресу межсетевого экрана без необходимости знать приватный адрес сервера. Пользователи будут подключаться к серверу только по тем портам, которые вы укажете в настройках.

The settings in the instructions are relevant for FortiOS versions 6.x and 7.x. If you have a different FortiOS version, you can find documentation for it in the top right corner of the FortiGate control panel 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 & Objects → Virtual IPs.

  3. Click Create New and select Virtual IP.

  4. In the VIP Type section, select IPv4.

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

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

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

    • to make the IP address accessible only through one interface, select this 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 that 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 SSH access needs to be configured.

  10. Turn on the Port Forwarding toggle switch.

  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, it 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 the group at once.

  1. In the FortiGate control panel, go to Policy & Objects → Virtual IPs.

  2. Click Create New and select Virtual IP Group.

  3. In the Type field, select IPv4.

  4. In the Name field, enter the name of 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 which firewall interface the virtual IP address group will be accessible through:

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

  8. Click OK.

3. Create a security policy

A security policy defines what traffic a firewall will permit between its interfaces. For example, you can use a policy to allow connections to servers behind a 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 & Objects → IPv4 Policy.

  2. Click Create New.

  3. In the Name field, enter the name of the security policy.

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

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

  6. In the Source field, select all.

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

  8. In the Schedule field, select always.

  9. In the Service field, select all.

  10. In the Action field, select Accept.

  11. Turn off the NAT toggle switch. The servers behind the firewall will receive original source IP addresses of connections.

  12. Click OK.