]> git.proxmox.com Git - pve-docs.git/blob - pve-firewall.adoc
75e3624f020670f6ec937c931a3a1effb7d2394c
[pve-docs.git] / pve-firewall.adoc
1 ifdef::manvolnum[]
2 PVE(8)
3 ======
4 include::attributes.txt[]
5 :pve-toplevel:
6
7 NAME
8 ----
9
10 pve-firewall - PVE Firewall Daemon
11
12
13 SYNOPSIS
14 --------
15
16 include::pve-firewall.8-synopsis.adoc[]
17
18
19 DESCRIPTION
20 -----------
21 endif::manvolnum[]
22
23 ifndef::manvolnum[]
24 {pve} Firewall
25 ==============
26 include::attributes.txt[]
27 endif::manvolnum[]
28
29 ifdef::wiki[]
30 :pve-toplevel:
31 :title: Firewall
32 endif::wiki[]
33
34 {pve} Firewall provides an easy way to protect your IT
35 infrastructure. You can setup firewall rules for all hosts
36 inside a cluster, or define rules for virtual machines and
37 containers. Features like firewall macros, security groups, IP sets
38 and aliases help to make that task easier.
39
40 While all configuration is stored on the cluster file system, the
41 `iptables`-based firewall runs on each cluster node, and thus provides
42 full isolation between virtual machines. The distributed nature of
43 this system also provides much higher bandwidth than a central
44 firewall solution.
45
46 The firewall has full support for IPv4 and IPv6. IPv6 support is fully
47 transparent, and we filter traffic for both protocols by default. So
48 there is no need to maintain a different set of rules for IPv6.
49
50
51 Zones
52 -----
53
54 The Proxmox VE firewall groups the network into the following logical zones:
55
56 Host::
57
58 Traffic from/to a cluster node
59
60 VM::
61
62 Traffic from/to a specific VM
63
64 For each zone, you can define firewall rules for incoming and/or
65 outgoing traffic.
66
67
68 Configuration Files
69 -------------------
70
71 All firewall related configuration is stored on the proxmox cluster
72 file system. So those files are automatically distributed to all
73 cluster nodes, and the `pve-firewall` service updates the underlying
74 `iptables` rules automatically on changes.
75
76 You can configure anything using the GUI (i.e. *Datacenter* -> *Firewall*,
77 or on a *Node* -> *Firewall*), or you can edit the configuration files
78 directly using your preferred editor.
79
80 Firewall configuration files contains sections of key-value
81 pairs. Lines beginning with a `#` and blank lines are considered
82 comments. Sections starts with a header line containing the section
83 name enclosed in `[` and `]`.
84
85
86 Cluster Wide Setup
87 ~~~~~~~~~~~~~~~~~~
88
89 The cluster wide firewall configuration is stored at:
90
91 /etc/pve/firewall/cluster.fw
92
93 The configuration can contain the following sections:
94
95 `[OPTIONS]`::
96
97 This is used to set cluster wide firewall options.
98
99 include::pve-firewall-cluster-opts.adoc[]
100
101 `[RULES]`::
102
103 This sections contains cluster wide firewall rules for all nodes.
104
105 `[IPSET <name>]`::
106
107 Cluster wide IP set definitions.
108
109 `[GROUP <name>]`::
110
111 Cluster wide security group definitions.
112
113 `[ALIASES]`::
114
115 Cluster wide Alias definitions.
116
117
118 Enabling the Firewall
119 ^^^^^^^^^^^^^^^^^^^^^
120
121 The firewall is completely disabled by default, so you need to
122 set the enable option here:
123
124 ----
125 [OPTIONS]
126 # enable firewall (cluster wide setting, default is disabled)
127 enable: 1
128 ----
129
130 IMPORTANT: If you enable the firewall, traffic to all hosts is blocked by
131 default. Only exceptions is WebGUI(8006) and ssh(22) from your local
132 network.
133
134 If you want to administrate your {pve} hosts from remote, you
135 need to create rules to allow traffic from those remote IPs to the web
136 GUI (port 8006). You may also want to allow ssh (port 22), and maybe
137 SPICE (port 3128).
138
139 TIP: Please open a SSH connection to one of your {PVE} hosts before
140 enabling the firewall. That way you still have access to the host if
141 something goes wrong .
142
143 To simplify that task, you can instead create an IPSet called
144 ``management'', and add all remote IPs there. This creates all required
145 firewall rules to access the GUI from remote.
146
147
148 Host Specific Configuration
149 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
150
151 Host related configuration is read from:
152
153 /etc/pve/nodes/<nodename>/host.fw
154
155 This is useful if you want to overwrite rules from `cluster.fw`
156 config. You can also increase log verbosity, and set netfilter related
157 options. The configuration can contain the following sections:
158
159 `[OPTIONS]`::
160
161 This is used to set host related firewall options.
162
163 include::pve-firewall-host-opts.adoc[]
164
165 `[RULES]`::
166
167 This sections contains host specific firewall rules.
168
169
170 VM/Container Configuration
171 ~~~~~~~~~~~~~~~~~~~~~~~~~~
172
173 VM firewall configuration is read from:
174
175 /etc/pve/firewall/<VMID>.fw
176
177 and contains the following data:
178
179 `[OPTIONS]`::
180
181 This is used to set VM/Container related firewall options.
182
183 include::pve-firewall-vm-opts.adoc[]
184
185 `[RULES]`::
186
187 This sections contains VM/Container firewall rules.
188
189 `[IPSET <name>]`::
190
191 IP set definitions.
192
193 `[ALIASES]`::
194
195 IP Alias definitions.
196
197
198 Enabling the Firewall for VMs and Containers
199 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200
201 Each virtual network device has its own firewall enable flag. So you
202 can selectively enable the firewall for each interface. This is
203 required in addition to the general firewall `enable` option.
204
205 The firewall requires a special network device setup, so you need to
206 restart the VM/container after enabling the firewall on a network
207 interface.
208
209
210 Firewall Rules
211 --------------
212
213 Firewall rules consists of a direction (`IN` or `OUT`) and an
214 action (`ACCEPT`, `DENY`, `REJECT`). You can also specify a macro
215 name. Macros contain predefined sets of rules and options. Rules can be
216 disabled by prefixing them with `|`.
217
218 .Firewall rules syntax
219 ----
220 [RULES]
221
222 DIRECTION ACTION [OPTIONS]
223 |DIRECTION ACTION [OPTIONS] # disabled rule
224
225 DIRECTION MACRO(ACTION) [OPTIONS] # use predefined macro
226 ----
227
228 The following options can be used to refine rule matches.
229
230 include::pve-firewall-rules-opts.adoc[]
231
232 Here are some examples:
233
234 ----
235 [RULES]
236 IN SSH(ACCEPT) -i net0
237 IN SSH(ACCEPT) -i net0 # a comment
238 IN SSH(ACCEPT) -i net0 -source 192.168.2.192 # only allow SSH from 192.168.2.192
239 IN SSH(ACCEPT) -i net0 -source 10.0.0.1-10.0.0.10 # accept SSH for ip range
240 IN SSH(ACCEPT) -i net0 -source 10.0.0.1,10.0.0.2,10.0.0.3 #accept ssh for ip list
241 IN SSH(ACCEPT) -i net0 -source +mynetgroup # accept ssh for ipset mynetgroup
242 IN SSH(ACCEPT) -i net0 -source myserveralias #accept ssh for alias myserveralias
243
244 |IN SSH(ACCEPT) -i net0 # disabled rule
245
246 IN DROP # drop all incoming packages
247 OUT ACCEPT # accept all outgoing packages
248 ----
249
250
251 Security Groups
252 ---------------
253
254 A security group is a collection of rules, defined at cluster level, which
255 can be used in all VMs' rules. For example you can define a group named
256 ``webserver'' with rules to open the 'http' and 'https' ports.
257
258 ----
259 # /etc/pve/firewall/cluster.fw
260
261 [group webserver]
262 IN ACCEPT -p tcp -dport 80
263 IN ACCEPT -p tcp -dport 443
264 ----
265
266 Then, you can add this group to a VM's firewall
267
268 ----
269 # /etc/pve/firewall/<VMID>.fw
270
271 [RULES]
272 GROUP webserver
273 ----
274
275
276 IP Aliases
277 ----------
278
279 IP Aliases allow you to associate IP addresses of networks with a
280 name. You can then refer to those names:
281
282 * inside IP set definitions
283 * in `source` and `dest` properties of firewall rules
284
285
286 Standard IP Alias `local_network`
287 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
288
289 This alias is automatically defined. Please use the following command
290 to see assigned values:
291
292 ----
293 # pve-firewall localnet
294 local hostname: example
295 local IP address: 192.168.2.100
296 network auto detect: 192.168.0.0/20
297 using detected local_network: 192.168.0.0/20
298 ----
299
300 The firewall automatically sets up rules to allow everything needed
301 for cluster communication (corosync, API, SSH) using this alias.
302
303 The user can overwrite these values in the `cluster.fw` alias
304 section. If you use a single host on a public network, it is better to
305 explicitly assign the local IP address
306
307 ----
308 # /etc/pve/firewall/cluster.fw
309 [ALIASES]
310 local_network 1.2.3.4 # use the single ip address
311 ----
312
313
314 IP Sets
315 -------
316
317 IP sets can be used to define groups of networks and hosts. You can
318 refer to them with `+name` in the firewall rules' `source` and `dest`
319 properties.
320
321 The following example allows HTTP traffic from the `management` IP
322 set.
323
324 IN HTTP(ACCEPT) -source +management
325
326
327 Standard IP set `management`
328 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
329
330 This IP set applies only to host firewalls (not VM firewalls). Those
331 IPs are allowed to do normal management tasks (PVE GUI, VNC, SPICE,
332 SSH).
333
334 The local cluster network is automatically added to this IP set (alias
335 `cluster_network`), to enable inter-host cluster
336 communication. (multicast,ssh,...)
337
338 ----
339 # /etc/pve/firewall/cluster.fw
340
341 [IPSET management]
342 192.168.2.10
343 192.168.2.10/24
344 ----
345
346
347 Standard IP set `blacklist`
348 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
349
350 Traffic from these IPs is dropped by every host's and VM's firewall.
351
352 ----
353 # /etc/pve/firewall/cluster.fw
354
355 [IPSET blacklist]
356 77.240.159.182
357 213.87.123.0/24
358 ----
359
360
361 [[ipfilter-section]]
362 Standard IP set `ipfilter-net*`
363 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364
365 These filters belong to a VM's network interface and are mainly used to prevent
366 IP spoofing. If such a set exists for an interface then any outgoing traffic
367 with a source IP not matching its interface's corresponding ipfilter set will
368 be dropped.
369
370 For containers with configured IP addresses these sets, if they exist (or are
371 activated via the general `IP Filter` option in the VM's firewall's *options*
372 tab), implicitly contain the associated IP addresses.
373
374 For both virtual machines and containers they also implicitly contain the
375 standard MAC-derived IPv6 link-local address in order to allow the neighbor
376 discovery protocol to work.
377
378 ----
379 /etc/pve/firewall/<VMID>.fw
380
381 [IPSET ipfilter-net0] # only allow specified IPs on net0
382 192.168.2.10
383 ----
384
385
386 Services and Commands
387 ---------------------
388
389 The firewall runs two service daemons on each node:
390
391 * pvefw-logger: NFLOG daemon (ulogd replacement).
392 * pve-firewall: updates iptables rules
393
394 There is also a CLI command named `pve-firewall`, which can be used to
395 start and stop the firewall service:
396
397 # pve-firewall start
398 # pve-firewall stop
399
400 To get the status use:
401
402 # pve-firewall status
403
404 The above command reads and compiles all firewall rules, so you will
405 see warnings if your firewall configuration contains any errors.
406
407 If you want to see the generated iptables rules you can use:
408
409 # iptables-save
410
411
412 Tips and Tricks
413 ---------------
414
415 How to allow FTP
416 ~~~~~~~~~~~~~~~~
417
418 FTP is an old style protocol which uses port 21 and several other dynamic ports. So you
419 need a rule to accept port 21. In addition, you need to load the `ip_conntrack_ftp` module.
420 So please run:
421
422 modprobe ip_conntrack_ftp
423
424 and add `ip_conntrack_ftp` to `/etc/modules` (so that it works after a reboot).
425
426
427 Suricata IPS integration
428 ~~~~~~~~~~~~~~~~~~~~~~~~
429
430 If you want to use the http://suricata-ids.org/[Suricata IPS]
431 (Intrusion Prevention System), it's possible.
432
433 Packets will be forwarded to the IPS only after the firewall ACCEPTed
434 them.
435
436 Rejected/Dropped firewall packets don't go to the IPS.
437
438 Install suricata on proxmox host:
439
440 ----
441 # apt-get install suricata
442 # modprobe nfnetlink_queue
443 ----
444
445 Don't forget to add `nfnetlink_queue` to `/etc/modules` for next reboot.
446
447 Then, enable IPS for a specific VM with:
448
449 ----
450 # /etc/pve/firewall/<VMID>.fw
451
452 [OPTIONS]
453 ips: 1
454 ips_queues: 0
455 ----
456
457 `ips_queues` will bind a specific cpu queue for this VM.
458
459 Available queues are defined in
460
461 ----
462 # /etc/default/suricata
463 NFQUEUE=0
464 ----
465
466
467 Notes on IPv6
468 -------------
469
470 The firewall contains a few IPv6 specific options. One thing to note is that
471 IPv6 does not use the ARP protocol anymore, and instead uses NDP (Neighbor
472 Discovery Protocol) which works on IP level and thus needs IP addresses to
473 succeed. For this purpose link-local addresses derived from the interface's MAC
474 address are used. By default the `NDP` option is enabled on both host and VM
475 level to allow neighbor discovery (NDP) packets to be sent and received.
476
477 Beside neighbor discovery NDP is also used for a couple of other things, like
478 autoconfiguration and advertising routers.
479
480 By default VMs are allowed to send out router solicitation messages (to query
481 for a router), and to receive router advertisement packets. This allows them to
482 use stateless auto configuration. On the other hand VMs cannot advertise
483 themselves as routers unless the ``Allow Router Advertisement'' (`radv: 1`) option
484 is set.
485
486 As for the link local addresses required for NDP, there's also an ``IP Filter''
487 (`ipfilter: 1`) option which can be enabled which has the same effect as adding
488 an `ipfilter-net*` ipset for each of the VM's network interfaces containing the
489 corresponding link local addresses. (See the
490 <<ipfilter-section,Standard IP set `ipfilter-net*`>> section for details.)
491
492
493 Ports used by {pve}
494 -------------------
495
496 * Web interface: 8006
497 * VNC Web console: 5900-5999
498 * SPICE proxy: 3128
499 * sshd (used for cluster actions): 22
500 * rpcbind: 111
501 * corosync multicast (if you run a cluster): 5404, 5405 UDP
502
503
504 ifdef::manvolnum[]
505
506 Macro Definitions
507 -----------------
508
509 include::pve-firewall-macros.adoc[]
510
511
512 include::pve-copyright.adoc[]
513
514 endif::manvolnum[]