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