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