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