]> git.proxmox.com Git - pve-docs.git/blame_incremental - pve-firewall.adoc
totp: fix copy/paste mistake
[pve-docs.git] / pve-firewall.adoc
... / ...
CommitLineData
1[[chapter_pve_firewall]]
2ifdef::manvolnum[]
3pve-firewall(8)
4===============
5:pve-toplevel:
6
7NAME
8----
9
10pve-firewall - PVE Firewall Daemon
11
12
13SYNOPSIS
14--------
15
16include::pve-firewall.8-synopsis.adoc[]
17
18
19DESCRIPTION
20-----------
21endif::manvolnum[]
22ifndef::manvolnum[]
23{pve} Firewall
24==============
25:pve-toplevel:
26endif::manvolnum[]
27ifdef::wiki[]
28:title: Firewall
29endif::wiki[]
30
31{pve} Firewall provides an easy way to protect your IT
32infrastructure. You can setup firewall rules for all hosts
33inside a cluster, or define rules for virtual machines and
34containers. Features like firewall macros, security groups, IP sets
35and aliases help to make that task easier.
36
37While all configuration is stored on the cluster file system, the
38`iptables`-based firewall service runs on each cluster node, and thus provides
39full isolation between virtual machines. The distributed nature of
40this system also provides much higher bandwidth than a central
41firewall solution.
42
43The firewall has full support for IPv4 and IPv6. IPv6 support is fully
44transparent, and we filter traffic for both protocols by default. So
45there is no need to maintain a different set of rules for IPv6.
46
47
48Zones
49-----
50
51The Proxmox VE firewall groups the network into the following logical zones:
52
53Host::
54
55Traffic from/to a cluster node
56
57VM::
58
59Traffic from/to a specific VM
60
61For each zone, you can define firewall rules for incoming and/or
62outgoing traffic.
63
64
65Configuration Files
66-------------------
67
68All firewall related configuration is stored on the proxmox cluster
69file system. So those files are automatically distributed to all
70cluster nodes, and the `pve-firewall` service updates the underlying
71`iptables` rules automatically on changes.
72
73You can configure anything using the GUI (i.e. *Datacenter* -> *Firewall*,
74or on a *Node* -> *Firewall*), or you can edit the configuration files
75directly using your preferred editor.
76
77Firewall configuration files contain sections of key-value
78pairs. Lines beginning with a `#` and blank lines are considered
79comments. Sections start with a header line containing the section
80name enclosed in `[` and `]`.
81
82
83[[pve_firewall_cluster_wide_setup]]
84Cluster Wide Setup
85~~~~~~~~~~~~~~~~~~
86
87The cluster-wide firewall configuration is stored at:
88
89 /etc/pve/firewall/cluster.fw
90
91The configuration can contain the following sections:
92
93`[OPTIONS]`::
94
95This is used to set cluster-wide firewall options.
96
97include::pve-firewall-cluster-opts.adoc[]
98
99`[RULES]`::
100
101This sections contains cluster-wide firewall rules for all nodes.
102
103`[IPSET <name>]`::
104
105Cluster wide IP set definitions.
106
107`[GROUP <name>]`::
108
109Cluster wide security group definitions.
110
111`[ALIASES]`::
112
113Cluster wide Alias definitions.
114
115
116Enabling the Firewall
117^^^^^^^^^^^^^^^^^^^^^
118
119The firewall is completely disabled by default, so you need to
120set the enable option here:
121
122----
123[OPTIONS]
124# enable firewall (cluster-wide setting, default is disabled)
125enable: 1
126----
127
128IMPORTANT: If you enable the firewall, traffic to all hosts is blocked by
129default. Only exceptions is WebGUI(8006) and ssh(22) from your local
130network.
131
132If you want to administrate your {pve} hosts from remote, you
133need to create rules to allow traffic from those remote IPs to the web
134GUI (port 8006). You may also want to allow ssh (port 22), and maybe
135SPICE (port 3128).
136
137TIP: Please open a SSH connection to one of your {PVE} hosts before
138enabling the firewall. That way you still have access to the host if
139something goes wrong .
140
141To simplify that task, you can instead create an IPSet called
142``management'', and add all remote IPs there. This creates all required
143firewall rules to access the GUI from remote.
144
145
146[[pve_firewall_host_specific_configuration]]
147Host Specific Configuration
148~~~~~~~~~~~~~~~~~~~~~~~~~~~
149
150Host related configuration is read from:
151
152 /etc/pve/nodes/<nodename>/host.fw
153
154This is useful if you want to overwrite rules from `cluster.fw`
155config. You can also increase log verbosity, and set netfilter related
156options. The configuration can contain the following sections:
157
158`[OPTIONS]`::
159
160This is used to set host related firewall options.
161
162include::pve-firewall-host-opts.adoc[]
163
164`[RULES]`::
165
166This sections contains host specific firewall rules.
167
168[[pve_firewall_vm_container_configuration]]
169VM/Container Configuration
170~~~~~~~~~~~~~~~~~~~~~~~~~~
171
172VM firewall configuration is read from:
173
174 /etc/pve/firewall/<VMID>.fw
175
176and contains the following data:
177
178`[OPTIONS]`::
179
180This is used to set VM/Container related firewall options.
181
182include::pve-firewall-vm-opts.adoc[]
183
184`[RULES]`::
185
186This sections contains VM/Container firewall rules.
187
188`[IPSET <name>]`::
189
190IP set definitions.
191
192`[ALIASES]`::
193
194IP Alias definitions.
195
196
197Enabling the Firewall for VMs and Containers
198^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
199
200Each virtual network device has its own firewall enable flag. So you
201can selectively enable the firewall for each interface. This is
202required in addition to the general firewall `enable` option.
203
204
205Firewall Rules
206--------------
207
208Firewall rules consists of a direction (`IN` or `OUT`) and an
209action (`ACCEPT`, `DENY`, `REJECT`). You can also specify a macro
210name. Macros contain predefined sets of rules and options. Rules can be
211disabled by prefixing them with `|`.
212
213.Firewall rules syntax
214----
215[RULES]
216
217DIRECTION ACTION [OPTIONS]
218|DIRECTION ACTION [OPTIONS] # disabled rule
219
220DIRECTION MACRO(ACTION) [OPTIONS] # use predefined macro
221----
222
223The following options can be used to refine rule matches.
224
225include::pve-firewall-rules-opts.adoc[]
226
227Here are some examples:
228
229----
230[RULES]
231IN SSH(ACCEPT) -i net0
232IN SSH(ACCEPT) -i net0 # a comment
233IN SSH(ACCEPT) -i net0 -source 192.168.2.192 # only allow SSH from 192.168.2.192
234IN SSH(ACCEPT) -i net0 -source 10.0.0.1-10.0.0.10 # accept SSH for IP range
235IN SSH(ACCEPT) -i net0 -source 10.0.0.1,10.0.0.2,10.0.0.3 #accept ssh for IP list
236IN SSH(ACCEPT) -i net0 -source +mynetgroup # accept ssh for ipset mynetgroup
237IN SSH(ACCEPT) -i net0 -source myserveralias #accept ssh for alias myserveralias
238
239|IN SSH(ACCEPT) -i net0 # disabled rule
240
241IN DROP # drop all incoming packages
242OUT ACCEPT # accept all outgoing packages
243----
244
245
246[[pve_firewall_security_groups]]
247Security Groups
248---------------
249
250A security group is a collection of rules, defined at cluster level, which
251can be used in all VMs' rules. For example you can define a group named
252``webserver'' with rules to open the 'http' and 'https' ports.
253
254----
255# /etc/pve/firewall/cluster.fw
256
257[group webserver]
258IN ACCEPT -p tcp -dport 80
259IN ACCEPT -p tcp -dport 443
260----
261
262Then, you can add this group to a VM's firewall
263
264----
265# /etc/pve/firewall/<VMID>.fw
266
267[RULES]
268GROUP webserver
269----
270
271[[pve_firewall_ip_aliases]]
272IP Aliases
273----------
274
275IP Aliases allow you to associate IP addresses of networks with a
276name. You can then refer to those names:
277
278* inside IP set definitions
279* in `source` and `dest` properties of firewall rules
280
281
282Standard IP Alias `local_network`
283~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284
285This alias is automatically defined. Please use the following command
286to see assigned values:
287
288----
289# pve-firewall localnet
290local hostname: example
291local IP address: 192.168.2.100
292network auto detect: 192.168.0.0/20
293using detected local_network: 192.168.0.0/20
294----
295
296The firewall automatically sets up rules to allow everything needed
297for cluster communication (corosync, API, SSH) using this alias.
298
299The user can overwrite these values in the `cluster.fw` alias
300section. If you use a single host on a public network, it is better to
301explicitly assign the local IP address
302
303----
304# /etc/pve/firewall/cluster.fw
305[ALIASES]
306local_network 1.2.3.4 # use the single IP address
307----
308
309[[pve_firewall_ip_sets]]
310IP Sets
311-------
312
313IP sets can be used to define groups of networks and hosts. You can
314refer to them with `+name` in the firewall rules' `source` and `dest`
315properties.
316
317The following example allows HTTP traffic from the `management` IP
318set.
319
320 IN HTTP(ACCEPT) -source +management
321
322
323Standard IP set `management`
324~~~~~~~~~~~~~~~~~~~~~~~~~~~~
325
326This IP set applies only to host firewalls (not VM firewalls). Those
327IPs are allowed to do normal management tasks (PVE GUI, VNC, SPICE,
328SSH).
329
330The local cluster network is automatically added to this IP set (alias
331`cluster_network`), to enable inter-host cluster
332communication. (multicast,ssh,...)
333
334----
335# /etc/pve/firewall/cluster.fw
336
337[IPSET management]
338192.168.2.10
339192.168.2.10/24
340----
341
342
343Standard IP set `blacklist`
344~~~~~~~~~~~~~~~~~~~~~~~~~~~
345
346Traffic from these IPs is dropped by every host's and VM's firewall.
347
348----
349# /etc/pve/firewall/cluster.fw
350
351[IPSET blacklist]
35277.240.159.182
353213.87.123.0/24
354----
355
356
357[[pve_firewall_ipfilter_section]]
358Standard IP set `ipfilter-net*`
359~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
360
361These filters belong to a VM's network interface and are mainly used to prevent
362IP spoofing. If such a set exists for an interface then any outgoing traffic
363with a source IP not matching its interface's corresponding ipfilter set will
364be dropped.
365
366For containers with configured IP addresses these sets, if they exist (or are
367activated via the general `IP Filter` option in the VM's firewall's *options*
368tab), implicitly contain the associated IP addresses.
369
370For both virtual machines and containers they also implicitly contain the
371standard MAC-derived IPv6 link-local address in order to allow the neighbor
372discovery protocol to work.
373
374----
375/etc/pve/firewall/<VMID>.fw
376
377[IPSET ipfilter-net0] # only allow specified IPs on net0
378192.168.2.10
379----
380
381
382Services and Commands
383---------------------
384
385The firewall runs two service daemons on each node:
386
387* pvefw-logger: NFLOG daemon (ulogd replacement).
388* pve-firewall: updates iptables rules
389
390There is also a CLI command named `pve-firewall`, which can be used to
391start and stop the firewall service:
392
393 # pve-firewall start
394 # pve-firewall stop
395
396To get the status use:
397
398 # pve-firewall status
399
400The above command reads and compiles all firewall rules, so you will
401see warnings if your firewall configuration contains any errors.
402
403If you want to see the generated iptables rules you can use:
404
405 # iptables-save
406
407[[pve_firewall_default_rules]]
408Default firewall rules
409----------------------
410
411The following traffic is filtered by the default firewall configuration:
412
413Datacenter incoming/outgoing DROP/REJECT
414~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
415
416If the input or output policy for the firewall is set to DROP or REJECT, the
417following traffic is still allowed for all {pve} hosts in the cluster:
418
419* traffic over the loopback interface
420* already established connections
421* traffic using the IGMP protocol
422* TCP traffic from management hosts to port 8006 in order to allow access to
423 the web interface
424* TCP traffic from management hosts to the port range 5900 to 5999 allowing
425 traffic for the VNC web console
426* TCP traffic from management hosts to port 3128 for connections to the SPICE
427 proxy
428* TCP traffic from management hosts to port 22 to allow ssh access
429* UDP traffic in the cluster network to ports 5405-5412 for corosync
430* UDP multicast traffic in the cluster network
431* ICMP traffic type 3 (Destination Unreachable), 4 (congestion control) or 11
432 (Time Exceeded)
433
434The following traffic is dropped, but not logged even with logging enabled:
435
436* TCP connections with invalid connection state
437* Broadcast, multicast and anycast traffic not related to corosync, i.e., not
438 coming through ports 5405-5412
439* TCP traffic to port 43
440* UDP traffic to ports 135 and 445
441* UDP traffic to the port range 137 to 139
442* UDP traffic form source port 137 to port range 1024 to 65535
443* UDP traffic to port 1900
444* TCP traffic to port 135, 139 and 445
445* UDP traffic originating from source port 53
446
447The rest of the traffic is dropped or rejected, respectively, and also logged.
448This may vary depending on the additional options enabled in
449*Firewall* -> *Options*, such as NDP, SMURFS and TCP flag filtering.
450
451[[pve_firewall_iptables_inspect]]
452Please inspect the output of the
453
454----
455 # iptables-save
456----
457
458system command to see the firewall chains and rules active on your system.
459This output is also included in a `System Report`, accessible over a node's
460subscription tab in the web GUI, or through the `pvereport` command line tool.
461
462VM/CT incoming/outgoing DROP/REJECT
463~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
464
465This drops or rejects all the traffic to the VMs, with some exceptions for
466DHCP, NDP, Router Advertisement, MAC and IP filtering depending on the set
467configuration. The same rules for dropping/rejecting packets are inherited
468from the datacenter, while the exceptions for accepted incoming/outgoing
469traffic of the host do not apply.
470
471Again, you can use xref:pve_firewall_iptables_inspect[iptables-save (see above)]
472to inspect all rules and chains applied.
473
474Logging of firewall rules
475-------------------------
476
477By default, all logging of traffic filtered by the firewall rules is disabled.
478To enable logging, the `loglevel` for incoming and/or outgoing traffic has to be
479set in *Firewall* -> *Options*. This can be done for the host as well as for the
480VM/CT firewall individually. By this, logging of {PVE}'s standard firewall rules
481is enabled and the output can be observed in *Firewall* -> *Log*.
482Further, only some dropped or rejected packets are logged for the standard rules
483(see xref:pve_firewall_default_rules[default firewall rules]).
484
485`loglevel` does not affect how much of the filtered traffic is logged. It
486changes a `LOGID` appended as prefix to the log output for easier filtering and
487post-processing.
488
489`loglevel` is one of the following flags:
490
491[[pve_firewall_log_levels]]
492[width="25%", options="header"]
493|===================
494| loglevel | LOGID
495| nolog | --
496| emerg | 0
497| alert | 1
498| crit | 2
499| err | 3
500| warning | 4
501| notice | 5
502| info | 6
503| debug | 7
504|===================
505
506A typical firewall log output looks like this:
507
508----
509VMID LOGID CHAIN TIMESTAMP POLICY: PACKET_DETAILS
510----
511
512In case of the host firewall, `VMID` is equal to 0.
513
514
515Logging of user defined firewall rules
516~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
517
518In order to log packets filtered by user-defined firewall rules, it is possible
519to set a log-level parameter for each rule individually.
520This allows to log in a fine grained manner and independent of the log-level
521defined for the standard rules in *Firewall* -> *Options*.
522
523While the `loglevel` for each individual rule can be defined or changed easily
524in the WebUI during creation or modification of the rule, it is possible to set
525this also via the corresponding `pvesh` API calls.
526
527Further, the log-level can also be set via the firewall configuration file by
528appending a `-log <loglevel>` to the selected rule (see
529xref:pve_firewall_log_levels[possible log-levels]).
530
531For example, the following two are identical:
532
533----
534IN REJECT -p icmp -log nolog
535IN REJECT -p icmp
536----
537
538whereas
539
540----
541IN REJECT -p icmp -log debug
542----
543
544produces a log output flagged with the `debug` level.
545
546
547Tips and Tricks
548---------------
549
550How to allow FTP
551~~~~~~~~~~~~~~~~
552
553FTP is an old style protocol which uses port 21 and several other dynamic ports. So you
554need a rule to accept port 21. In addition, you need to load the `ip_conntrack_ftp` module.
555So please run:
556
557 modprobe ip_conntrack_ftp
558
559and add `ip_conntrack_ftp` to `/etc/modules` (so that it works after a reboot).
560
561
562Suricata IPS integration
563~~~~~~~~~~~~~~~~~~~~~~~~
564
565If you want to use the https://suricata-ids.org/[Suricata IPS]
566(Intrusion Prevention System), it's possible.
567
568Packets will be forwarded to the IPS only after the firewall ACCEPTed
569them.
570
571Rejected/Dropped firewall packets don't go to the IPS.
572
573Install suricata on proxmox host:
574
575----
576# apt-get install suricata
577# modprobe nfnetlink_queue
578----
579
580Don't forget to add `nfnetlink_queue` to `/etc/modules` for next reboot.
581
582Then, enable IPS for a specific VM with:
583
584----
585# /etc/pve/firewall/<VMID>.fw
586
587[OPTIONS]
588ips: 1
589ips_queues: 0
590----
591
592`ips_queues` will bind a specific cpu queue for this VM.
593
594Available queues are defined in
595
596----
597# /etc/default/suricata
598NFQUEUE=0
599----
600
601
602Notes on IPv6
603-------------
604
605The firewall contains a few IPv6 specific options. One thing to note is that
606IPv6 does not use the ARP protocol anymore, and instead uses NDP (Neighbor
607Discovery Protocol) which works on IP level and thus needs IP addresses to
608succeed. For this purpose link-local addresses derived from the interface's MAC
609address are used. By default the `NDP` option is enabled on both host and VM
610level to allow neighbor discovery (NDP) packets to be sent and received.
611
612Beside neighbor discovery NDP is also used for a couple of other things, like
613auto-configuration and advertising routers.
614
615By default VMs are allowed to send out router solicitation messages (to query
616for a router), and to receive router advertisement packets. This allows them to
617use stateless auto configuration. On the other hand VMs cannot advertise
618themselves as routers unless the ``Allow Router Advertisement'' (`radv: 1`) option
619is set.
620
621As for the link local addresses required for NDP, there's also an ``IP Filter''
622(`ipfilter: 1`) option which can be enabled which has the same effect as adding
623an `ipfilter-net*` ipset for each of the VM's network interfaces containing the
624corresponding link local addresses. (See the
625<<pve_firewall_ipfilter_section,Standard IP set `ipfilter-net*`>> section for details.)
626
627
628Ports used by {pve}
629-------------------
630
631* Web interface: 8006 (TCP, HTTP/1.1 over TLS)
632* VNC Web console: 5900-5999 (TCP, WebSocket)
633* SPICE proxy: 3128 (TCP)
634* sshd (used for cluster actions): 22 (TCP)
635* rpcbind: 111 (UDP)
636* sendmail: 25 (TCP, outgoing)
637* corosync cluster traffic: 5405-5412 UDP
638* live migration (VM memory and local-disk data): 60000-60050 (TCP)
639
640ifdef::manvolnum[]
641
642Macro Definitions
643-----------------
644
645include::pve-firewall-macros.adoc[]
646
647
648include::pve-copyright.adoc[]
649
650endif::manvolnum[]