]> git.proxmox.com Git - pve-docs.git/blame_incremental - pve-firewall.adoc
sysadmin: add section about NTP configuration
[pve-docs.git] / pve-firewall.adoc
... / ...
CommitLineData
1ifdef::manvolnum[]
2pve-firewall(8)
3===============
4include::attributes.txt[]
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[]
22
23ifndef::manvolnum[]
24{pve} Firewall
25==============
26include::attributes.txt[]
27endif::manvolnum[]
28ifdef::wiki[]
29:pve-toplevel:
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
85Cluster Wide Setup
86~~~~~~~~~~~~~~~~~~
87
88The cluster wide firewall configuration is stored at:
89
90 /etc/pve/firewall/cluster.fw
91
92The configuration can contain the following sections:
93
94`[OPTIONS]`::
95
96This is used to set cluster wide firewall options.
97
98include::pve-firewall-cluster-opts.adoc[]
99
100`[RULES]`::
101
102This sections contains cluster wide firewall rules for all nodes.
103
104`[IPSET <name>]`::
105
106Cluster wide IP set definitions.
107
108`[GROUP <name>]`::
109
110Cluster wide security group definitions.
111
112`[ALIASES]`::
113
114Cluster wide Alias definitions.
115
116
117Enabling the Firewall
118^^^^^^^^^^^^^^^^^^^^^
119
120The firewall is completely disabled by default, so you need to
121set the enable option here:
122
123----
124[OPTIONS]
125# enable firewall (cluster wide setting, default is disabled)
126enable: 1
127----
128
129IMPORTANT: If you enable the firewall, traffic to all hosts is blocked by
130default. Only exceptions is WebGUI(8006) and ssh(22) from your local
131network.
132
133If you want to administrate your {pve} hosts from remote, you
134need to create rules to allow traffic from those remote IPs to the web
135GUI (port 8006). You may also want to allow ssh (port 22), and maybe
136SPICE (port 3128).
137
138TIP: Please open a SSH connection to one of your {PVE} hosts before
139enabling the firewall. That way you still have access to the host if
140something goes wrong .
141
142To simplify that task, you can instead create an IPSet called
143``management'', and add all remote IPs there. This creates all required
144firewall rules to access the GUI from remote.
145
146
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
204The firewall requires a special network device setup, so you need to
205restart the VM/container after enabling the firewall on a network
206interface.
207
208
209Firewall Rules
210--------------
211
212Firewall rules consists of a direction (`IN` or `OUT`) and an
213action (`ACCEPT`, `DENY`, `REJECT`). You can also specify a macro
214name. Macros contain predefined sets of rules and options. Rules can be
215disabled by prefixing them with `|`.
216
217.Firewall rules syntax
218----
219[RULES]
220
221DIRECTION ACTION [OPTIONS]
222|DIRECTION ACTION [OPTIONS] # disabled rule
223
224DIRECTION MACRO(ACTION) [OPTIONS] # use predefined macro
225----
226
227The following options can be used to refine rule matches.
228
229include::pve-firewall-rules-opts.adoc[]
230
231Here are some examples:
232
233----
234[RULES]
235IN SSH(ACCEPT) -i net0
236IN SSH(ACCEPT) -i net0 # a comment
237IN SSH(ACCEPT) -i net0 -source 192.168.2.192 # only allow SSH from 192.168.2.192
238IN SSH(ACCEPT) -i net0 -source 10.0.0.1-10.0.0.10 # accept SSH for ip range
239IN SSH(ACCEPT) -i net0 -source 10.0.0.1,10.0.0.2,10.0.0.3 #accept ssh for ip list
240IN SSH(ACCEPT) -i net0 -source +mynetgroup # accept ssh for ipset mynetgroup
241IN SSH(ACCEPT) -i net0 -source myserveralias #accept ssh for alias myserveralias
242
243|IN SSH(ACCEPT) -i net0 # disabled rule
244
245IN DROP # drop all incoming packages
246OUT ACCEPT # accept all outgoing packages
247----
248
249
250Security Groups
251---------------
252
253A security group is a collection of rules, defined at cluster level, which
254can be used in all VMs' rules. For example you can define a group named
255``webserver'' with rules to open the 'http' and 'https' ports.
256
257----
258# /etc/pve/firewall/cluster.fw
259
260[group webserver]
261IN ACCEPT -p tcp -dport 80
262IN ACCEPT -p tcp -dport 443
263----
264
265Then, you can add this group to a VM's firewall
266
267----
268# /etc/pve/firewall/<VMID>.fw
269
270[RULES]
271GROUP webserver
272----
273
274[[pve_firewall_ip_aliases]]
275IP Aliases
276----------
277
278IP Aliases allow you to associate IP addresses of networks with a
279name. You can then refer to those names:
280
281* inside IP set definitions
282* in `source` and `dest` properties of firewall rules
283
284
285Standard IP Alias `local_network`
286~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287
288This alias is automatically defined. Please use the following command
289to see assigned values:
290
291----
292# pve-firewall localnet
293local hostname: example
294local IP address: 192.168.2.100
295network auto detect: 192.168.0.0/20
296using detected local_network: 192.168.0.0/20
297----
298
299The firewall automatically sets up rules to allow everything needed
300for cluster communication (corosync, API, SSH) using this alias.
301
302The user can overwrite these values in the `cluster.fw` alias
303section. If you use a single host on a public network, it is better to
304explicitly assign the local IP address
305
306----
307# /etc/pve/firewall/cluster.fw
308[ALIASES]
309local_network 1.2.3.4 # use the single ip address
310----
311
312[[pve_firewall_ip_sets]]
313IP Sets
314-------
315
316IP sets can be used to define groups of networks and hosts. You can
317refer to them with `+name` in the firewall rules' `source` and `dest`
318properties.
319
320The following example allows HTTP traffic from the `management` IP
321set.
322
323 IN HTTP(ACCEPT) -source +management
324
325
326Standard IP set `management`
327~~~~~~~~~~~~~~~~~~~~~~~~~~~~
328
329This IP set applies only to host firewalls (not VM firewalls). Those
330IPs are allowed to do normal management tasks (PVE GUI, VNC, SPICE,
331SSH).
332
333The local cluster network is automatically added to this IP set (alias
334`cluster_network`), to enable inter-host cluster
335communication. (multicast,ssh,...)
336
337----
338# /etc/pve/firewall/cluster.fw
339
340[IPSET management]
341192.168.2.10
342192.168.2.10/24
343----
344
345
346Standard IP set `blacklist`
347~~~~~~~~~~~~~~~~~~~~~~~~~~~
348
349Traffic from these IPs is dropped by every host's and VM's firewall.
350
351----
352# /etc/pve/firewall/cluster.fw
353
354[IPSET blacklist]
35577.240.159.182
356213.87.123.0/24
357----
358
359
360[[ipfilter-section]]
361Standard IP set `ipfilter-net*`
362~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
363
364These filters belong to a VM's network interface and are mainly used to prevent
365IP spoofing. If such a set exists for an interface then any outgoing traffic
366with a source IP not matching its interface's corresponding ipfilter set will
367be dropped.
368
369For containers with configured IP addresses these sets, if they exist (or are
370activated via the general `IP Filter` option in the VM's firewall's *options*
371tab), implicitly contain the associated IP addresses.
372
373For both virtual machines and containers they also implicitly contain the
374standard MAC-derived IPv6 link-local address in order to allow the neighbor
375discovery protocol to work.
376
377----
378/etc/pve/firewall/<VMID>.fw
379
380[IPSET ipfilter-net0] # only allow specified IPs on net0
381192.168.2.10
382----
383
384
385Services and Commands
386---------------------
387
388The firewall runs two service daemons on each node:
389
390* pvefw-logger: NFLOG daemon (ulogd replacement).
391* pve-firewall: updates iptables rules
392
393There is also a CLI command named `pve-firewall`, which can be used to
394start and stop the firewall service:
395
396 # pve-firewall start
397 # pve-firewall stop
398
399To get the status use:
400
401 # pve-firewall status
402
403The above command reads and compiles all firewall rules, so you will
404see warnings if your firewall configuration contains any errors.
405
406If you want to see the generated iptables rules you can use:
407
408 # iptables-save
409
410
411Tips and Tricks
412---------------
413
414How to allow FTP
415~~~~~~~~~~~~~~~~
416
417FTP is an old style protocol which uses port 21 and several other dynamic ports. So you
418need a rule to accept port 21. In addition, you need to load the `ip_conntrack_ftp` module.
419So please run:
420
421 modprobe ip_conntrack_ftp
422
423and add `ip_conntrack_ftp` to `/etc/modules` (so that it works after a reboot).
424
425
426Suricata IPS integration
427~~~~~~~~~~~~~~~~~~~~~~~~
428
429If you want to use the http://suricata-ids.org/[Suricata IPS]
430(Intrusion Prevention System), it's possible.
431
432Packets will be forwarded to the IPS only after the firewall ACCEPTed
433them.
434
435Rejected/Dropped firewall packets don't go to the IPS.
436
437Install suricata on proxmox host:
438
439----
440# apt-get install suricata
441# modprobe nfnetlink_queue
442----
443
444Don't forget to add `nfnetlink_queue` to `/etc/modules` for next reboot.
445
446Then, enable IPS for a specific VM with:
447
448----
449# /etc/pve/firewall/<VMID>.fw
450
451[OPTIONS]
452ips: 1
453ips_queues: 0
454----
455
456`ips_queues` will bind a specific cpu queue for this VM.
457
458Available queues are defined in
459
460----
461# /etc/default/suricata
462NFQUEUE=0
463----
464
465
466Notes on IPv6
467-------------
468
469The firewall contains a few IPv6 specific options. One thing to note is that
470IPv6 does not use the ARP protocol anymore, and instead uses NDP (Neighbor
471Discovery Protocol) which works on IP level and thus needs IP addresses to
472succeed. For this purpose link-local addresses derived from the interface's MAC
473address are used. By default the `NDP` option is enabled on both host and VM
474level to allow neighbor discovery (NDP) packets to be sent and received.
475
476Beside neighbor discovery NDP is also used for a couple of other things, like
477autoconfiguration and advertising routers.
478
479By default VMs are allowed to send out router solicitation messages (to query
480for a router), and to receive router advertisement packets. This allows them to
481use stateless auto configuration. On the other hand VMs cannot advertise
482themselves as routers unless the ``Allow Router Advertisement'' (`radv: 1`) option
483is set.
484
485As for the link local addresses required for NDP, there's also an ``IP Filter''
486(`ipfilter: 1`) option which can be enabled which has the same effect as adding
487an `ipfilter-net*` ipset for each of the VM's network interfaces containing the
488corresponding link local addresses. (See the
489<<ipfilter-section,Standard IP set `ipfilter-net*`>> section for details.)
490
491
492Ports used by {pve}
493-------------------
494
495* Web interface: 8006
496* VNC Web console: 5900-5999
497* SPICE proxy: 3128
498* sshd (used for cluster actions): 22
499* rpcbind: 111
500* corosync multicast (if you run a cluster): 5404, 5405 UDP
501
502
503ifdef::manvolnum[]
504
505Macro Definitions
506-----------------
507
508include::pve-firewall-macros.adoc[]
509
510
511include::pve-copyright.adoc[]
512
513endif::manvolnum[]