Plesk

How to allow connections to a port from specific IP addresses only in Plesk

Question

How to allow connections to a port from specific IP addresses only?

Answer

  1. Log in to Plesk.

  2. Go to Tools & Settings > Firewall.

    Note: If Firewall is not available, install it using the instructions from this KB article.

  3. Enable Firewall Rules Management and click Modify Plesk Firewall Rules.

  4. Click on an existing rule to edit.

  5. Select Allow from selected sources, deny from others and add IP addresses from which connections will be allowed.

  6. Click OK.

  7. Click Apply Changes.

 

Alternatively, use the OS native tool to achieve that:

 

For Windows (Windows Firewall)

 

  1. Connect to the server via RDP.

  2. Go to Start > Windows Powershell.

  3. Run the following command:

    PS New-NetFirewallRule -DisplayName "Allow TCP:15555 from certain IPs" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 15555 -RemoteAddress (203.0.113.2)

    Note: Replace 203.0.113.2 and 15555 with the actual IP and network port to be allowed access from/to accordingly.

 

For Linux (iptables)

 

  1. Connect to the server via SSH.

  2. Run the following command:

    # iptables -I INPUT -p tcp ! -s 203.0.113.2 --dport 15555 -j DROP

    Note: Replace 203.0.113.2 and 15555 with the actual IP and network port to be allowed access from/to accordingly.

  3. (optional) For IP address range:

    # iptables -I INPUT -p tcp ! --src-range 203.0.113.2-203.0.113.35 --dport 15555 -j DROP

    Note: Replace 203.0.113.2-203.0.113.35 and 15555 with the actual IPs and network port to be allowed access from/to accordingly.

  4. Save the changes in iptables:

    # iptables-save > /etc/sysconfig/iptables