@@ -22,17 +22,16 @@ Automatic CDN and bogon IP list updater for firewall and server configurations
22
22
* Install PHP-CLI with openssl extension if not installed (OS dependent)
23
23
24
24
* Install ip-list-updater.php to an appropriate location and give execute permission
25
-
25
+ ```
26
26
$ cd /usr/local/src/
27
-
28
27
$ git clone https://github.com/vkucukcakar/ip-list-updater.git
29
-
30
28
$ cp ip-list-updater/ip-list-updater.php /usr/local/bin/
31
-
32
- * Give execute permission if not cloned from github
29
+ ```
33
30
31
+ * Give execute permission if not cloned from github
32
+ ```
34
33
$ chmod +x /usr/local/bin/ip-list-updater.php
35
-
34
+ ```
36
35
37
36
## Usage
38
37
@@ -72,73 +71,75 @@ Available options:
72
71
### Examples (raw mode)
73
72
74
73
Short command syntax usage.
75
-
74
+ ```
76
75
$ ip-list-updater.php -u -m raw -x 4 -o "/etc/ip-list-updater.txt" -s "cloudflare" -c "/etc/myscript.sh"
77
-
76
+ ```
78
77
Long command syntax usage.
79
-
78
+ ```
80
79
$ ip-list-updater.php --update --mode="raw" --ipv=4 --output="/etc/ip-list-updater.txt" --sources="https://www.cloudflare.com/ips-v4" --success="/etc/myscript.sh"
81
-
80
+ ```
82
81
83
82
Doing some magic with bash and raw list. /etc/myscript.sh contents:
84
-
83
+ ```
85
84
#!/usr/bin/env bash
86
85
for IP in $(cat /etc/ip-list-updater.txt); do
87
86
echo $IP
88
87
done
88
+ ```
89
89
90
90
### Examples (ipset mode)
91
91
92
92
This example demonstrates how to allow your CDN/reverse proxy IP range through ipset and iptables.
93
93
94
94
Create a proxylist set, create iptables rule to accept proxylist set for http/https ports, add Cloudflare IPv4 range to proxylist set.
95
-
95
+ ```
96
96
$ ipset create proxylist hash:net family inet hashsize 1024 maxelem 131072
97
97
$ iptables -I INPUT -p tcp -m multiport --dports 80,443 -m set --match-set proxylist src -j ACCEPT
98
98
$ ip-list-updater.php --update --mode="ipset" --setname="proxylist" --ipv=4 --output="/etc/proxylist.txt" --sources="cloudflare"
99
-
99
+ ```
100
100
This example demonstrates how to block a bogonlist through ipset and iptables.
101
101
102
102
Create a bogonlist set, create iptables rule to drop bogonlist set, add Spamhaus IPv4 list to bogonlist set.
103
-
103
+ ```
104
104
$ ipset create bogonlist hash:net family inet hashsize 1024 maxelem 131072
105
105
$ iptables -I INPUT -m set --match-set bogonlist src -j DROP
106
106
$ ip-list-updater.php --update --mode="ipset" --setname="bogonlist" --ipv=4 --output="/etc/bogonlist.txt" --sources="spamhaus"
107
-
107
+ ```
108
108
### Examples (nginx mode)
109
109
110
110
This example demonstrates how to make Nginx show correct connnecting IP via ngx_http_realip_module on a reverse proxy/CDN setup.
111
111
112
112
Add the following to Nginx main configuration file.
113
-
113
+ ```
114
114
#real_ip_header X-Real-IP;
115
115
#real_ip_header X-Forwarded-For;
116
116
real_ip_header CF-Connecting-IP;
117
117
include /etc/nginx-cloudflare.conf;
118
-
118
+ ```
119
119
Update ip list and create Nginx (module ngx_http_realip_module) configuration file to be included.
120
120
Success command will make Nginx reload configuration files without interruption. Make sure nginx path is correct at the success command.
121
-
121
+ ```
122
122
$ ip-list-updater.php --update --mode="nginx" --ipv=4 --output="/etc/nginx-cloudflare.conf" --sources="cloudflare" --success="/usr/bin/nginx -s reload"
123
-
123
+ ```
124
124
For Cloudflare, both CF-Connecting-IP and X-Forwarded-For can be used. Please refer to your CDN's documentation for the correct header.
125
125
126
126
### Examples (apache mode)
127
127
128
128
This example demonstrates how to make Apache show correct connnecting IP via mod_remoteip on a reverse proxy/CDN setup.
129
129
130
130
Modify the relevant section in Apache configuration file.
131
-
131
+ ```
132
132
<IfModule mod_remoteip.c>
133
133
#RemoteIPHeader X-Forwarded-For
134
134
RemoteIPHeader CF-Connecting-IP
135
135
RemoteIPInternalProxyList /etc/apache-cloudflare.lst
136
136
</IfModule>
137
-
137
+ ```
138
138
Update ip list and create Apache (module mod_remoteip) trusted proxy list file to be included.
139
139
Make sure Apache reload success command is correct which may be OS specific.
140
-
140
+ ```
141
141
$ ip-list-updater.php --update --mode="apache" --ipv=4 --output="/etc/apache-cloudflare.lst" --sources="cloudflare" --success="apachectl -k graceful"
142
+ ```
142
143
143
144
### Examples (A real world example !!!)
144
145
@@ -148,9 +149,11 @@ The second line downloads the Cloudflare IPv4 range, updates Ipset named "proxyl
148
149
149
150
The third line downloads the Cloudflare IP range, updates the server configuration and reloads Nginx with zero downtime by sending a HUP signal to the container by Docker.
150
151
152
+ ```
151
153
15 3 * * * root /usr/local/bin/ip-list-updater.php --update --mode="ipset" --setname="bogonlist" --ipv=4 --output="/etc/bogonlist.txt" --sources="spamhaus" --success="ipset save bogonlist -f /etc/sptables/data/bogonlist.save" >/dev/null 2>/var/log/ip-list-updater.log
152
154
45 3 * * * root /usr/local/bin/ip-list-updater.php --update --mode="ipset" --setname="proxylist" --ipv=4 --output="/etc/proxylist.txt" --sources="cloudflare" --success="ipset save proxylist -f /etc/sptables/data/proxylist.save" >/dev/null 2>/var/log/ip-list-updater.log
153
155
30 3 * * * root /usr/local/bin/ip-list-updater.php --update --mode="nginx" --ipv=all --output="/lemp/configurations/cdn.conf" --sources="cloudflare" --success="docker kill --signal=HUP server-proxy" >/dev/null 2>/var/log/ip-list-updater.log
156
+ ```
154
157
155
158
## Caveats
156
159
0 commit comments