Installing and configuring Advanced Policy Firewall
Installing and Configuring Advanced Policy Firewall (APF)
Section titled “Installing and Configuring Advanced Policy Firewall (APF)”Learn how to install and configure the Advanced Policy Firewall (APF), which allows you to grant or deny access to selected IP addresses and services running on your server.
About Advanced Policy Firewall (APF)
Section titled “About Advanced Policy Firewall (APF)”APF is designed for unmanaged VPS servers to help secure your system. It allows you to:
- Explicitly grant or deny access to selected IP addresses
- Control access to specific services running on the server
- Protect against brute-force login attempts
Installing Advanced Policy Firewall
Section titled “Installing Advanced Policy Firewall”- Log in to your server via SSH.
- Download APF to your server:
wget http://www.rfxn.com/downloads/apf-current.tar.gz- Extract the files:
tar xvzf apf-current.tar.gz- Enter the extracted directory (version number may vary):
cd apf-9.7-2- Run the installation script:
./install.shConfiguring Advanced Policy Firewall
Section titled “Configuring Advanced Policy Firewall”Basic Configuration
Section titled “Basic Configuration”- Open the configuration file:
nano /etc/apf/conf.apf- Locate the following settings:
IFACE_IN="eth0"IFACE_OUT="eth0"SET_MONOKERN="0"HELPER_SSH_PORT="22"IG_TCP_CPORTS="22"- Modify them as follows (adjust to your server settings):
IFACE_IN="venet0"IFACE_OUT="venet0"SET_MONOKERN="1"HELPER_SSH_PORT="7822"IG_TCP_CPORTS="80,7822,8000"You can add other ports to
IG_TCP_CPORTSas needed.
List of TCP/UDP ports
- Save changes and start APF in development mode:
apf --startDevelopment mode automatically drops all firewall rules after 5 minutes to prevent accidental lockouts.
- Test your allowed connections (SSH, HTTP, etc.) before disabling development mode.
- Disable development mode by editing the line:
DEVEL_MODE="0"- Save and restart the system. APF is now active.
Granting Access
Section titled “Granting Access”APF uses a whitelist (/etc/apf/allow_hosts.rules) and a blacklist (/etc/apf/deny_hosts.rules) to regulate traffic.
Add your IP to the whitelist
Section titled “Add your IP to the whitelist”# Comment describing the ruletcp:in:d=7822:s=xxx.xxx.xxx.xxxReplace
xxx.xxx.xxx.xxxwith your IP address. Add a comment for clarity.
Find your IP
- Add multiple IPs on separate lines.
- Restart APF to apply changes:
apf --restartDenying Access
Section titled “Denying Access”Block a specific IP
Section titled “Block a specific IP”apf --deny xxx.xxx.xxx.xxx commentReplace
xxx.xxx.xxx.xxxwith the IP you want to block. Add an optional comment.
- To block an entire network, use CIDR notation:
192.168.100.0/24- To unblock an IP, remove or comment out the line in
/etc/apf/deny_hosts.rulesand restart APF:
apf --restartMore Information
Section titled “More Information”For full APF documentation, visit: Advanced Policy Firewall