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