]> git.proxmox.com Git - pve-docs.git/blame - pve-firewall.adoc
Fixed some typos and slight language improvements
[pve-docs.git] / pve-firewall.adoc
CommitLineData
80c0adcb 1[[chapter_pve_firewall]]
c7eda5e6 2ifdef::manvolnum[]
b2f242ab
DM
3pve-firewall(8)
4===============
5f09af76
DM
5:pve-toplevel:
6
c7eda5e6
DM
7NAME
8----
9
f5eb0727 10pve-firewall - PVE Firewall Daemon
c7eda5e6
DM
11
12
49a5e11c 13SYNOPSIS
c7eda5e6
DM
14--------
15
5f34196d 16include::pve-firewall.8-synopsis.adoc[]
c7eda5e6
DM
17
18
19DESCRIPTION
20-----------
21endif::manvolnum[]
c7eda5e6
DM
22ifndef::manvolnum[]
23{pve} Firewall
24==============
194d2f29 25:pve-toplevel:
c7eda5e6 26endif::manvolnum[]
5f09af76 27ifdef::wiki[]
cb84ed18 28:title: Firewall
5f09af76
DM
29endif::wiki[]
30
26ca7ff5 31{pve} Firewall provides an easy way to protect your IT
89a8b6c6 32infrastructure. You can setup firewall rules for all hosts
c7eda5e6
DM
33inside a cluster, or define rules for virtual machines and
34containers. Features like firewall macros, security groups, IP sets
5eba0743 35and aliases help to make that task easier.
c7eda5e6
DM
36
37While all configuration is stored on the cluster file system, the
d5621636 38`iptables`-based firewall service runs on each cluster node, and thus provides
c7eda5e6
DM
39full isolation between virtual machines. The distributed nature of
40this system also provides much higher bandwidth than a central
41firewall solution.
42
bd73a43e
DM
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
c7eda5e6
DM
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
79672214
DM
65Configuration Files
66-------------------
c7eda5e6
DM
67
68All firewall related configuration is stored on the proxmox cluster
69file system. So those files are automatically distributed to all
8c1189b6
FG
70cluster nodes, and the `pve-firewall` service updates the underlying
71`iptables` rules automatically on changes.
c7eda5e6 72
e300cf7d
FG
73You can configure anything using the GUI (i.e. *Datacenter* -> *Firewall*,
74or on a *Node* -> *Firewall*), or you can edit the configuration files
89a8b6c6
DM
75directly using your preferred editor.
76
d5621636 77Firewall configuration files contain sections of key-value
8c1189b6 78pairs. Lines beginning with a `#` and blank lines are considered
d5621636 79comments. Sections start with a header line containing the section
8c1189b6 80name enclosed in `[` and `]`.
79672214 81
89a8b6c6 82
80c0adcb 83[[pve_firewall_cluster_wide_setup]]
79672214
DM
84Cluster Wide Setup
85~~~~~~~~~~~~~~~~~~
86
87The cluster wide firewall configuration is stored at:
c7eda5e6
DM
88
89 /etc/pve/firewall/cluster.fw
90
79672214 91The configuration can contain the following sections:
c7eda5e6 92
8c1189b6 93`[OPTIONS]`::
79672214
DM
94
95This is used to set cluster wide firewall options.
96
c48819d1
DM
97include::pve-firewall-cluster-opts.adoc[]
98
8c1189b6 99`[RULES]`::
c7eda5e6 100
79672214
DM
101This sections contains cluster wide firewall rules for all nodes.
102
8c1189b6 103`[IPSET <name>]`::
79672214
DM
104
105Cluster wide IP set definitions.
106
8c1189b6 107`[GROUP <name>]`::
79672214
DM
108
109Cluster wide security group definitions.
110
8c1189b6 111`[ALIASES]`::
79672214
DM
112
113Cluster wide Alias definitions.
114
89a8b6c6
DM
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
8c1189b6 142``management'', and add all remote IPs there. This creates all required
89a8b6c6
DM
143firewall rules to access the GUI from remote.
144
145
80c0adcb 146[[pve_firewall_host_specific_configuration]]
5eba0743 147Host Specific Configuration
79672214
DM
148~~~~~~~~~~~~~~~~~~~~~~~~~~~
149
150Host related configuration is read from:
151
152 /etc/pve/nodes/<nodename>/host.fw
153
8c1189b6 154This is useful if you want to overwrite rules from `cluster.fw`
79672214 155config. You can also increase log verbosity, and set netfilter related
888c4116
DM
156options. The configuration can contain the following sections:
157
8c1189b6 158`[OPTIONS]`::
888c4116
DM
159
160This is used to set host related firewall options.
161
162include::pve-firewall-host-opts.adoc[]
163
8c1189b6 164`[RULES]`::
888c4116
DM
165
166This sections contains host specific firewall rules.
79672214 167
641cc419 168[[pve_firewall_vm_container_configuration]]
5eba0743 169VM/Container Configuration
79672214 170~~~~~~~~~~~~~~~~~~~~~~~~~~
c7eda5e6 171
a4922e12 172VM firewall configuration is read from:
c7eda5e6
DM
173
174 /etc/pve/firewall/<VMID>.fw
175
176and contains the following data:
177
8c1189b6 178`[OPTIONS]`::
78ef35dc
DM
179
180This is used to set VM/Container related firewall options.
181
182include::pve-firewall-vm-opts.adoc[]
183
8c1189b6 184`[RULES]`::
78ef35dc
DM
185
186This sections contains VM/Container firewall rules.
187
8c1189b6 188`[IPSET <name>]`::
78ef35dc
DM
189
190IP set definitions.
191
8c1189b6 192`[ALIASES]`::
78ef35dc
DM
193
194IP Alias definitions.
c7eda5e6 195
c7eda5e6 196
58b16f71 197Enabling the Firewall for VMs and Containers
79672214 198^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
c7eda5e6 199
89a8b6c6
DM
200Each virtual network device has its own firewall enable flag. So you
201can selectively enable the firewall for each interface. This is
8c1189b6 202required in addition to the general firewall `enable` option.
89a8b6c6 203
79672214 204
c7eda5e6 205Firewall Rules
79672214 206--------------
c7eda5e6 207
696fb448
DM
208Firewall rules consists of a direction (`IN` or `OUT`) and an
209action (`ACCEPT`, `DENY`, `REJECT`). You can also specify a macro
8c1189b6
FG
210name. Macros contain predefined sets of rules and options. Rules can be
211disabled by prefixing them with `|`.
c7eda5e6 212
696fb448 213.Firewall rules syntax
c7eda5e6
DM
214----
215[RULES]
216
696fb448
DM
217DIRECTION ACTION [OPTIONS]
218|DIRECTION ACTION [OPTIONS] # disabled rule
c7eda5e6 219
696fb448
DM
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:
c7eda5e6 228
696fb448
DM
229----
230[RULES]
c7eda5e6
DM
231IN SSH(ACCEPT) -i net0
232IN SSH(ACCEPT) -i net0 # a comment
696fb448 233IN SSH(ACCEPT) -i net0 -source 192.168.2.192 # only allow SSH from 192.168.2.192
b3234584
OB
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
696fb448
DM
236IN SSH(ACCEPT) -i net0 -source +mynetgroup # accept ssh for ipset mynetgroup
237IN SSH(ACCEPT) -i net0 -source myserveralias #accept ssh for alias myserveralias
c7eda5e6
DM
238
239|IN SSH(ACCEPT) -i net0 # disabled rule
696fb448
DM
240
241IN DROP # drop all incoming packages
242OUT ACCEPT # accept all outgoing packages
c7eda5e6
DM
243----
244
8c1189b6 245
80c0adcb 246[[pve_firewall_security_groups]]
c7eda5e6 247Security Groups
79672214 248---------------
c7eda5e6 249
58b16f71
WB
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
8c1189b6 252``webserver'' with rules to open the 'http' and 'https' ports.
c7eda5e6
DM
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
58b16f71 262Then, you can add this group to a VM's firewall
c7eda5e6
DM
263
264----
265# /etc/pve/firewall/<VMID>.fw
266
267[RULES]
268GROUP webserver
269----
270
641cc419 271[[pve_firewall_ip_aliases]]
c7eda5e6 272IP Aliases
79672214 273----------
c7eda5e6 274
58b16f71 275IP Aliases allow you to associate IP addresses of networks with a
c7eda5e6
DM
276name. You can then refer to those names:
277
278* inside IP set definitions
279* in `source` and `dest` properties of firewall rules
280
5eba0743
FG
281
282Standard IP Alias `local_network`
79672214 283~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c7eda5e6
DM
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
58b16f71 297for cluster communication (corosync, API, SSH) using this alias.
c7eda5e6 298
8c1189b6 299The user can overwrite these values in the `cluster.fw` alias
c7eda5e6
DM
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]
b3234584 306local_network 1.2.3.4 # use the single IP address
c7eda5e6
DM
307----
308
641cc419 309[[pve_firewall_ip_sets]]
c7eda5e6 310IP Sets
79672214 311-------
c7eda5e6
DM
312
313IP sets can be used to define groups of networks and hosts. You can
58b16f71 314refer to them with `+name` in the firewall rules' `source` and `dest`
c7eda5e6
DM
315properties.
316
317The following example allows HTTP traffic from the `management` IP
318set.
319
320 IN HTTP(ACCEPT) -source +management
321
5eba0743 322
c7eda5e6 323Standard IP set `management`
79672214 324~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c7eda5e6
DM
325
326This IP set applies only to host firewalls (not VM firewalls). Those
5eba0743 327IPs are allowed to do normal management tasks (PVE GUI, VNC, SPICE,
c7eda5e6
DM
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
8c1189b6
FG
342
343Standard IP set `blacklist`
79672214 344~~~~~~~~~~~~~~~~~~~~~~~~~~~
c7eda5e6 345
5eba0743 346Traffic from these IPs is dropped by every host's and VM's firewall.
c7eda5e6
DM
347
348----
349# /etc/pve/firewall/cluster.fw
350
351[IPSET blacklist]
35277.240.159.182
353213.87.123.0/24
354----
355
8c1189b6 356
80c0adcb 357[[pve_firewall_ipfilter_section]]
8c1189b6 358Standard IP set `ipfilter-net*`
79672214 359~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c7eda5e6 360
a34d23e8
WB
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
e300cf7d 367activated via the general `IP Filter` option in the VM's firewall's *options*
a34d23e8
WB
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.
c7eda5e6
DM
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
79672214 381
c7eda5e6 382Services and Commands
79672214 383---------------------
c7eda5e6
DM
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
8c1189b6 390There is also a CLI command named `pve-firewall`, which can be used to
c7eda5e6
DM
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
7d47064e
CE
407Logging of firewall rules
408-------------------------
409
410By default, logging of traffic filtered by the firewall rules is disabled. To
411enable logging for the default firewall rules, the log-level for incommig and
412outgoing traffic has to be set in the firewall `Options` tab for the host and/or
413the VM/CT firewall.
414Logging of dropped packets is rate limited to 1 packet per second in order to
415reduce output to the log file.
416Further, only some dropped or rejected packets are logged for the standard rules.
417
73b78e5e
TL
418// TODO: describe standard/default rules and note which of them get logged
419
7d47064e
CE
420In order to log packets filtered by user-defined firewall rules, it is possible
421to set a log-level parameter for each rule individually.
422This allows to log in a fine grained manner and independent of the log-level
73b78e5e 423defined for the standard rules in the firewall `Options`.
7d47064e
CE
424
425The log level for the rule can also be set via the firewall configuration file by
426appending a `-log <loglevel>` to the selected rule.
73b78e5e 427Here, `<loglevel>` is one of the following flags:
7d47064e
CE
428`nolog, emerg, alert, crit, err, warning, notice, info, debug`
429
73b78e5e 430For example, the following two are ident:
7d47064e
CE
431
432----
433IN REJECT -p icmp -log nolog
7d47064e
CE
434IN REJECT -p icmp
435----
436
437whereas
438
439----
440IN REJECT -p icmp -log debug
441----
442
443produces a log output flagged with the `debug` level.
444
79672214 445
c7eda5e6 446Tips and Tricks
79672214 447---------------
c7eda5e6
DM
448
449How to allow FTP
79672214 450~~~~~~~~~~~~~~~~
c7eda5e6
DM
451
452FTP is an old style protocol which uses port 21 and several other dynamic ports. So you
8c1189b6 453need a rule to accept port 21. In addition, you need to load the `ip_conntrack_ftp` module.
c7eda5e6
DM
454So please run:
455
456 modprobe ip_conntrack_ftp
457
8c1189b6 458and add `ip_conntrack_ftp` to `/etc/modules` (so that it works after a reboot).
c7eda5e6 459
79672214 460
c7eda5e6 461Suricata IPS integration
79672214 462~~~~~~~~~~~~~~~~~~~~~~~~
c7eda5e6
DM
463
464If you want to use the http://suricata-ids.org/[Suricata IPS]
465(Intrusion Prevention System), it's possible.
466
467Packets will be forwarded to the IPS only after the firewall ACCEPTed
468them.
469
470Rejected/Dropped firewall packets don't go to the IPS.
471
472Install suricata on proxmox host:
473
474----
475# apt-get install suricata
476# modprobe nfnetlink_queue
477----
478
8c1189b6 479Don't forget to add `nfnetlink_queue` to `/etc/modules` for next reboot.
c7eda5e6
DM
480
481Then, enable IPS for a specific VM with:
482
483----
484# /etc/pve/firewall/<VMID>.fw
485
486[OPTIONS]
487ips: 1
488ips_queues: 0
489----
490
491`ips_queues` will bind a specific cpu queue for this VM.
492
493Available queues are defined in
494
495----
496# /etc/default/suricata
497NFQUEUE=0
498----
499
8c1189b6 500
79672214
DM
501Notes on IPv6
502-------------
503
504The firewall contains a few IPv6 specific options. One thing to note is that
505IPv6 does not use the ARP protocol anymore, and instead uses NDP (Neighbor
506Discovery Protocol) which works on IP level and thus needs IP addresses to
507succeed. For this purpose link-local addresses derived from the interface's MAC
8c1189b6 508address are used. By default the `NDP` option is enabled on both host and VM
79672214
DM
509level to allow neighbor discovery (NDP) packets to be sent and received.
510
511Beside neighbor discovery NDP is also used for a couple of other things, like
b3234584 512auto-configuration and advertising routers.
79672214
DM
513
514By default VMs are allowed to send out router solicitation messages (to query
5eba0743 515for a router), and to receive router advertisement packets. This allows them to
79672214 516use stateless auto configuration. On the other hand VMs cannot advertise
8c1189b6 517themselves as routers unless the ``Allow Router Advertisement'' (`radv: 1`) option
79672214
DM
518is set.
519
8c1189b6 520As for the link local addresses required for NDP, there's also an ``IP Filter''
79672214
DM
521(`ipfilter: 1`) option which can be enabled which has the same effect as adding
522an `ipfilter-net*` ipset for each of the VM's network interfaces containing the
523corresponding link local addresses. (See the
80c0adcb 524<<pve_firewall_ipfilter_section,Standard IP set `ipfilter-net*`>> section for details.)
79672214
DM
525
526
26ca7ff5
FG
527Ports used by {pve}
528-------------------
224128ce
DM
529
530* Web interface: 8006
531* VNC Web console: 5900-5999
532* SPICE proxy: 3128
533* sshd (used for cluster actions): 22
534* rpcbind: 111
5eba0743 535* corosync multicast (if you run a cluster): 5404, 5405 UDP
224128ce 536
14c06023
DM
537
538ifdef::manvolnum[]
539
540Macro Definitions
541-----------------
542
543include::pve-firewall-macros.adoc[]
544
545
546include::pve-copyright.adoc[]
547
548endif::manvolnum[]