1
1
2
- ## Installing PFUI_Unbound and Unbound ( with Python Module support)
2
+ ## Installing PFUI_Firewall and PFUI_Unbound (Unbound with Python Module support)
3
3
4
- ### OpenBSD
4
+ PFUI_Firewall runs as a daemon instance on OpenBSD firewall(s) running PF.
5
+ PFUI_Firewall listens on the configured network port for messages from PFUI_Unbound (DNS).
6
+ Received messages are written directly into the configured PF temporary tables via IOCTL calls.
7
+ Messages are also saved into redis for state and expiry tracking, and into a files to be
8
+ read by PF at startup, making it reload safe.
9
+
10
+ /etc/pf.conf must also be configured with appropriate packet filtering rules.
11
+ PFUI_Firewall simply installs the IP addresses sent to it by PFUI_Unbound (DNS servers) into
12
+ the configured PF tables. PF must then filter against those tables as desired.
13
+
14
+ #### NOTE: For both the auto and manual methods;
15
+ If you want pfui_firewall to start at boot, disable unbound with ` rcctl restart pfui_firewall `
16
+ and edit ` /etc/rc.conf.local ` ensuring the following three lines exist.
17
+
18
+ ```
19
+ pfui_firewall=""
20
+ pfui_firewall_user="root"
21
+ pkg_scripts=redis pfui_firewall pfui_unbound
22
+ ```
5
23
24
+ NB; If you want a normal Unbound (for localhost) and a PFUI Unbound (for clients) on the same firewall,
25
+ either configure the default Unbound to only listen on lookback, or use different rdomain per lookup domain/daemon.
6
26
27
+ If your pkg_scripts already has other options, just add these three to your existing line
28
+ TODO: The root user is required only to talk to the /dev/pf IOCTL and to open the configured network listening port
29
+ for receiving messages from all instances of PFUI_Unbound. Set group permissions for _ pfui_firewall user, and run pfui_firewall as _ pfui_firewall user
30
+
31
+ ## Install
32
+ ```
7
33
export PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/%v/packages/%a/
8
34
pkg_add -i bash
35
+
36
+ # All edge OpenBSD Firewalls
9
37
install_pfui_firewall.sh
38
+
39
+ # All internal DNS Servers
10
40
install_pfui_unbound.sh
41
+ ```
11
42
43
+ ## Configure
44
+ ```
45
+ OpenBSD PF Firewall(s); Configure PFUI_Firewall `/etc/pfui_firewall.yml`
46
+ Unbound DNS Resolver(s); Configure PFUI_Unbound `/var/unbound/etc/pfui_unbound.yml`
47
+ ```
12
48
49
+ Warning; UDP mode (` SOCKET_PROTO: UDP ` ) is _ not_ recommended (experimental) as Unbound's Python Module executes every DNS lookup,
50
+ using a unique network socket to PFUI_Firewall for each lookup. With UDP's default timers, the socket
51
+ remains (5mins) after the connection/PFUI_Firewall is updated, thus blocking subsequent connections until timeout.
52
+ UDP therefore only supports ~ 213Qps (~ 64000ports / 5m / 60s).
13
53
54
+ Default TCP TIME_WAIT = 60; ** ~ 1,066Qps** (~ 64000 / 60) - per PFUI_Firewall\
55
+ TCP TW=10 (` sysctl net.inet.tcp.keepidle=10 ` ); ** ~ 6,400qps** (64000 / 10) - per PFUI_Firewall
14
56
15
- #### Install Packages
16
- ```
17
- export PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/%v/packages/%a/
57
+ Even if your use case is <200Qps, UDP is still not recommended as logic to handle high load has not been developed due to the socket
58
+ limitation above. One way to solve this could be a UDP proxy, to provide persistent sockets to PFUI_Firewall, however such userland UDP proxy which would negate
59
+ any speed advantages of UDP.
18
60
19
- pkg_add -i python%2
20
- pkg_add -i py-setuptools
21
- pkg_add -i py-pip
22
- ln -s /usr/local/bin/python2 /usr/local/bin/python
61
+ Instead, TCP has been optimised to perform within 20% of the theoretical minimum latency of UDP.
62
+ Eg, UDP messaging can unblock PFUI_Firewall in ~ 1000uS (1ms), and TCP can unblock PFUI_Firewall in ~ 1,200us (1.2ms).
63
+ Because PFUI leverages TCP signalling in the kernel network stack, at high load latency does not increase much. \
64
+ UDP latency increases more rapidly due to userland CPU contention as load increases.
23
65
24
- pkg_add -i python%3
66
+ # Manual Install
67
+ The above installation scripts are better maintained than this process below.
68
+ It is recommended to review the above install scripts as well.
69
+
70
+ ------------------------------
71
+
72
+ ### PFUI_Unbound - Dependencies
73
+ ```
74
+ export PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/%v/packages/%a/
75
+ pkg_add -i python%3.8
25
76
pkg_add -i py3-setuptools
26
77
pkg_add -i py3-pip
78
+ ln -s `which python3` /usr/local/bin/python
79
+ pkg_add -i swig git bash cmake libconfig libiconv bison gawk mawk
80
+ ```
27
81
28
- pkg_add -i swig
29
- pkg_add -i git
82
+ #### TODO: PFUI_Unbound Dependencies
83
+ python3 -m pip install -r ./requirements_unbound.txt
84
+
85
+ ### PFUI_Unbound - Download Unbound source
86
+ ```
87
+ git clone --depth 20 https://github.com/NLnetLabs/unbound.git /tmp/unbound
88
+ # --depth 20 helps with shallow clone errors
30
89
```
31
90
32
- #### Build Unbound with Python Module Support
91
+ #### Default Unbound build options in OpenBSD port, ` unbound -V ` (ref only);
92
+ ```
93
+ --enable-allsymbols
94
+ --with-ssl=/usr
95
+ --with-libevent=/usr
96
+ --with-libexpat=/usr
97
+ --without-pythonmodule
98
+ --with-chroot-dir=/var/unbound
99
+ --with-pidfile=
100
+ --with-rootkey-file=/var/unbound/db/root.key
101
+ --with-conf-file=/var/unbound/etc/unbound.conf
102
+ --with-username=_unbound
103
+ --disable-shared
104
+ --disable-explicit-port-randomisation
105
+ --without-pthreads
33
106
```
34
- git clone https://github.com/NLnetLabs/unbound.git /tmp/unbound
35
107
108
+ ### PFUI_Unbound - Build Unbound with Python Module Support enabled
109
+ ```
36
110
cd /tmp/unbound
37
111
./configure --enable-allsymbols \
38
- --with-ssl=/usr \
39
- --with-libevent=/usr \
40
- --with-libexpat=/usr \
41
- --with-pythonmodule \
42
- --with-chroot-dir=/var/unbound \
43
- --with-pidfile="" \
44
- --with-rootkey-file=/var/unbound/db/root.key \
45
- --with-conf-file=/var/unbound/etc/unbound.pfui.conf \
46
- --with-username=_unbound \
47
- --disable-shared
112
+ --with-ssl=/usr \
113
+ --with-libevent=/usr \
114
+ --with-libexpat=/usr \
115
+ --with-pythonmodule \
116
+ --with-chroot-dir=/var/unbound \
117
+ --with-pidfile="" \
118
+ --with-rootkey-file=/var/unbound/db/root.key \
119
+ --with-conf-file=/var/unbound/etc/pfui_unbound.conf \
120
+ --with-username=_unbound \
121
+ --disable-shared \
122
+ --disable-explicit-port-randomisation \
123
+ --without-pthreads
48
124
49
125
make && make install
126
+ ```
50
127
128
+ #### Copy PFUI_Firewall files
129
+ ```
130
+ cp -f "${DIR}/pfui_firewall.py" /usr/local/sbin/pfui_firewall.py
131
+ chmod 755 /usr/local/sbin/pfui_firewall.py
132
+
133
+ cp -f "${DIR}/pfui_firewall.yml" /etc/pfui_firewall.yml
134
+ chmod 644 /etc/pfui_firewall.yml
51
135
136
+ cp -f "${DIR}/rc.d/pfui_firewall" /etc/rc.d/pfui_firewall
137
+ chmod 555 /etc/rc.d/pfui_firewall
138
+
139
+ cp -f "${DIR}/examples/pf.conf" /etc/pf-pfui-example.conf
52
140
```
53
141
54
- #### TODO: Copy in all PFUI_Unbound files (/var/unbound/etc/)
55
- chmod 755 ./pfui_firewall.py
142
+ ### Install Python Libraries and Redis
143
+ ```
144
+ python3 -m pip install redis pyyaml service
145
+ pkg_add -i redis
146
+ rcctl enable redis
147
+ rcctl start redis
148
+ ```
149
+ ```
56
150
chmod 755 ./update_root_servers.sh
57
151
chmod 755 ./update_filtered_domains.sh
58
152
59
153
chmod 555 /etc/rc.d/pfui_unbound
60
154
61
155
chmod 755 ./update_root_servers.sh
62
156
chmod 755 ./update_filtered_domains.sh
63
-
64
- #### TODO: PFUI_Unbound Dependencies
65
- python3 -m pip install -r ./requirements.txt
157
+ ```
66
158
67
159
#### TODO: Section for Unbound service
68
160
69
- #### TODO: Section for Unbound config
161
+ #### TODO: Unbound config
162
+ A good tool for automatically downloading the latest bad-reputation domains into DNS Blocklists can be found here;
163
+ https://www.geoghegan.ca/unbound-adblock.html
70
164
71
165
#### TODO: Section for Unbound data sources
72
- ./update_root_servers.sh
73
- ./update_filtered_domains.sh
166
+ ./update_root_hints.sh
74
167
75
168
```
76
169
rcctl enable pfui_unbound
@@ -91,32 +184,26 @@ rcctl start pfui_unbound
91
184
92
185
### OpenBSD
93
186
94
- #### Install Packages
187
+ #### PFUI_Firewall - Dependencies
95
188
```
96
- pkg_add -i python%2
97
- pkg_add -i py-setuptools
98
- pkg_add -i py-pip
99
-
100
- ln -s /usr/local/bin/python2 /usr/local/bin/python
101
-
102
189
pkg_add -i python%3
103
190
pkg_add -i py3-setuptools
104
191
pkg_add -i py3-pip
105
-
192
+ ln -s `which python3` /usr/local/bin/python
106
193
pkg_add -i redis
107
194
rcctl enable redis
108
195
rcctl restart redis
109
196
```
110
197
111
- #### Copy Files (/etc/ & /usr/local/sbin/)
198
+ #### PFUI_Firewall - Copy Files (/etc/ & /usr/local/sbin/)
112
199
```
113
200
cp ./pfui_firewall.py /usr/local/sbin/pfui_firewall.py
114
201
chmod 755 /usr/local/sbin/pfui_firewall.py
115
202
cp ./pfui_firewall.yml /etc/pfui_firewall.yml
116
203
chmod 644 /etc/pfui_firewall.yml
117
204
```
118
205
119
- #### Enable PFUI_Firewall service
206
+ #### PFUI_Firewall - Enable Service
120
207
```
121
208
rcctl enable pfui_firewall
122
209
rcctl start pfui_firewall
0 commit comments