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