How can I make a white list for n (about 300 and plans to grow to 700) the number of ip addresses to port 80?
Server information: Ubuntu v16.04.1 (Linux v4.4.0-31) and Nginx v1.11.3
You need to add approximately the following lines to the virtual host configuration if you want to do this via NGINX
location / { allow 100.23.45.14; ## IP которому нужно разрешить доступ allow 100.23.45.15; ## IP которому нужно разрешить доступ deny all; }
If you want to do this through iptables, then you need to register the following lines:
iptables -I INPUT -s <allowed_ip> -p tcp --dport 80 -i eth0 -j ACCEPT iptables -A INPUT -j DROP -p tcp -i eth0 --dport 80
The first line must be repeated as many times as necessary to add IP to the list of allowed.
Consider the iptables options:
I will add as a separate answer, I have already given it in the comments to the previous answer, just the formatting is lost in the comments.
First of all, for nginx you need to allocate all the allow
in a separate file - in order not to clutter up the config file and improve readability.
location / { include whitelist.txt; }
File whitelist.txt
:
allow 100.23.45.14; allow 100.23.45.15; deny all;
Secondly, it slipped in the comments about a large number of hosts: do not forget that nginx
(unlike apache
, which still does not know how shameful!) Understands the subnet:
# Rostelecom provider, Belgorod allow 213.24.126.0/24; deny all;
For the white list I used ipset + iptables
Create 2 new listings:
ipset -N whitelist iphash # Для адресов ipset -N whitelist_net nethash # Для сетей
Add new addresses to whitelist:
ipset -A whitelist 100.23.45.14 ipset -A whitelist_net 100.23.45.0/24
A rule is created for using lists:
iptables -A INPUT -m set --match-set whitelist src -p tcp --dport 80 -j ACCEPT iptables -A INPUT -m set --match-set whitelist_net src -p tcp --dport 80 -j ACCEPT
and close 80:
iptables -A INPUT -j DROP -p tcp --dport 80
Additional Information:
Source: https://ru.stackoverflow.com/questions/552913/
All Articles