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.
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.
<virtual_ip_name> — name of the virtual IP address;
<public_ip_address> — public IP address of the firewall you received in the ticket after ordering the service. For example, 203.0.113.2;
<eth_name> — firewall interface name, so that the IP address is accessible only through this interface. You can view the list of interfaces using the show system interface command. To make the IP address accessible through all interfaces, specify any;
<public_port> — an available port on the firewall. For example, 8080;
<private_ip_address> — private IP address of the server behind the firewall to which you want to configure SSH access. For example, 192.168.0.2;
<private_port> — port on which the SSH service is running on the server behind the firewall. By default, this is port 22.
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.
Graphical interface
CLI
FortiOS 6.x
FortiOS 7.x
In the FortiGate control panel, go to Policy & Objects → Virtual IPs.
Click Create New and select Virtual IP Group.
In the Type field, select IPv4.
In the Name field, enter a name for the virtual IP address group.
Optional: in the Comments field, enter a comment for the virtual IP address group.
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.
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.
Click OK.
In the FortiGate control panel, go to Policy & Objects → Virtual IPs.
Select Virtual IP Group and click Create New.
In the Name field, enter a name for the virtual IP address group.
Optional: in the Comments field, enter a comment for the virtual IP address group.
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.
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.
<group_name> — name of the virtual IP address group;
<eth_name> — firewall interface name, if all IP addresses in the group are bound to this interface. You can view the list of interfaces using the show system interface command. If IP addresses in the group are bound to different interfaces, specify any;
<virtual_ip_1>, <virtual_ip_2> — names of the virtual IP addresses. You can view the list of virtual IP addresses using the show firewall vip.
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.
Graphical interface
CLI
FortiOS 6.x
FortiOS 7.x
In the FortiGate control panel, go to Policy & Objects → IPv4 Policy.
Click Create New.
In the Name field, enter a name for the security policy.
In the Incoming Interface field, select the public firewall interface.
In the Outgoing Interface field, select the private firewall interface.
In the Source field, select all.
In the Destination field, select a destination address: