A robust IP whitelisting solution using iptables mangle table to secure your servers and prevent IP address leakage. This script implements early packet filtering at the PREROUTING chain level for enhanced security and performance.
- Early packet filtering using mangle table and PREROUTING chain
- Efficient handling of established connections
- Whitelist specific IP addresses for HTTP/HTTPS access
- Support for both IPv4 and IPv6
- Blocks all other incoming HTTP/HTTPS traffic
- Prevents IP address leakage
- Optional packet logging for security monitoring
- Simple and lightweight implementation
- Root access to your server
iptables
installedconntrack
module enabled- Understanding of firewall rules and netfilter
- Clone the repository:
git clone https://github.com/alosgg/alos-whitelist.git
cd alos-whitelist
- Make the script executable:
chmod +x whitelist.sh
Run the script with root privileges:
sudo ./whitelist.sh
The script operates in three main steps:
-
Connection Tracking: Allows established connections to maintain functionality
-
Whitelist Rules: Adds ACCEPT rules for specified IP addresses at the PREROUTING chain
-
Default Deny Rules: Blocks all other HTTP/HTTPS traffic early in the packet processing pipeline
- Keep the IP whitelist up to date
- Regularly audit access logs
- Maintain backups of your firewall rules
- Test the rules thoroughly before implementing in production
- Monitor the logs for dropped packets if logging is enabled
To verify that the rules are properly set:
# Check IPv4 mangle rules
sudo iptables -t mangle -L PREROUTING -n | grep -E "http|https"
# Check connection tracking rules
sudo iptables -t mangle -L PREROUTING -n | grep "RELATED,ESTABLISHED"
The impact on server performance is minimized as:
- Packets are filtered early in the netfilter chain
- Established connections are handled efficiently
- Unwanted traffic is dropped before reaching higher levels of processing
This project is licensed under the MIT License and it was inspired by "pixlrs/only-cf".
If you discover any security-related issues, please email your security team instead of using the issue tracker.
For support, please open an issue in the GitHub repository.