1 [[chapter_pve_firewall]]
10 pve-firewall - PVE Firewall Daemon
16 include::pve-firewall.8-synopsis.adoc[]
31 {pve} Firewall provides an easy way to protect your IT
32 infrastructure. You can setup firewall rules for all hosts
33 inside a cluster, or define rules for virtual machines and
34 containers. Features like firewall macros, security groups, IP sets
35 and aliases help to make that task easier.
37 While all configuration is stored on the cluster file system, the
38 `iptables`-based firewall service runs on each cluster node, and thus provides
39 full isolation between virtual machines. The distributed nature of
40 this system also provides much higher bandwidth than a central
43 The firewall has full support for IPv4 and IPv6. IPv6 support is fully
44 transparent, and we filter traffic for both protocols by default. So
45 there is no need to maintain a different set of rules for IPv6.
51 The Proxmox VE firewall groups the network into the following logical zones:
55 Traffic from/to a cluster node
59 Traffic from/to a specific VM
61 For each zone, you can define firewall rules for incoming and/or
68 All firewall related configuration is stored on the proxmox cluster
69 file system. So those files are automatically distributed to all
70 cluster nodes, and the `pve-firewall` service updates the underlying
71 `iptables` rules automatically on changes.
73 You can configure anything using the GUI (i.e. *Datacenter* -> *Firewall*,
74 or on a *Node* -> *Firewall*), or you can edit the configuration files
75 directly using your preferred editor.
77 Firewall configuration files contain sections of key-value
78 pairs. Lines beginning with a `#` and blank lines are considered
79 comments. Sections start with a header line containing the section
80 name enclosed in `[` and `]`.
83 [[pve_firewall_cluster_wide_setup]]
87 The cluster wide firewall configuration is stored at:
89 /etc/pve/firewall/cluster.fw
91 The configuration can contain the following sections:
95 This is used to set cluster wide firewall options.
97 include::pve-firewall-cluster-opts.adoc[]
101 This sections contains cluster wide firewall rules for all nodes.
105 Cluster wide IP set definitions.
109 Cluster wide security group definitions.
113 Cluster wide Alias definitions.
116 Enabling the Firewall
117 ^^^^^^^^^^^^^^^^^^^^^
119 The firewall is completely disabled by default, so you need to
120 set the enable option here:
124 # enable firewall (cluster wide setting, default is disabled)
128 IMPORTANT: If you enable the firewall, traffic to all hosts is blocked by
129 default. Only exceptions is WebGUI(8006) and ssh(22) from your local
132 If you want to administrate your {pve} hosts from remote, you
133 need to create rules to allow traffic from those remote IPs to the web
134 GUI (port 8006). You may also want to allow ssh (port 22), and maybe
137 TIP: Please open a SSH connection to one of your {PVE} hosts before
138 enabling the firewall. That way you still have access to the host if
139 something goes wrong .
141 To simplify that task, you can instead create an IPSet called
142 ``management'', and add all remote IPs there. This creates all required
143 firewall rules to access the GUI from remote.
146 [[pve_firewall_host_specific_configuration]]
147 Host Specific Configuration
148 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
150 Host related configuration is read from:
152 /etc/pve/nodes/<nodename>/host.fw
154 This is useful if you want to overwrite rules from `cluster.fw`
155 config. You can also increase log verbosity, and set netfilter related
156 options. The configuration can contain the following sections:
160 This is used to set host related firewall options.
162 include::pve-firewall-host-opts.adoc[]
166 This sections contains host specific firewall rules.
168 [[pve_firewall_vm_container_configuration]]
169 VM/Container Configuration
170 ~~~~~~~~~~~~~~~~~~~~~~~~~~
172 VM firewall configuration is read from:
174 /etc/pve/firewall/<VMID>.fw
176 and contains the following data:
180 This is used to set VM/Container related firewall options.
182 include::pve-firewall-vm-opts.adoc[]
186 This sections contains VM/Container firewall rules.
194 IP Alias definitions.
197 Enabling the Firewall for VMs and Containers
198 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200 Each virtual network device has its own firewall enable flag. So you
201 can selectively enable the firewall for each interface. This is
202 required in addition to the general firewall `enable` option.
208 Firewall rules consists of a direction (`IN` or `OUT`) and an
209 action (`ACCEPT`, `DENY`, `REJECT`). You can also specify a macro
210 name. Macros contain predefined sets of rules and options. Rules can be
211 disabled by prefixing them with `|`.
213 .Firewall rules syntax
217 DIRECTION ACTION [OPTIONS]
218 |DIRECTION ACTION [OPTIONS] # disabled rule
220 DIRECTION MACRO(ACTION) [OPTIONS] # use predefined macro
223 The following options can be used to refine rule matches.
225 include::pve-firewall-rules-opts.adoc[]
227 Here are some examples:
231 IN SSH(ACCEPT) -i net0
232 IN SSH(ACCEPT) -i net0 # a comment
233 IN SSH(ACCEPT) -i net0 -source 192.168.2.192 # only allow SSH from 192.168.2.192
234 IN SSH(ACCEPT) -i net0 -source 10.0.0.1-10.0.0.10 # accept SSH for IP range
235 IN SSH(ACCEPT) -i net0 -source 10.0.0.1,10.0.0.2,10.0.0.3 #accept ssh for IP list
236 IN SSH(ACCEPT) -i net0 -source +mynetgroup # accept ssh for ipset mynetgroup
237 IN SSH(ACCEPT) -i net0 -source myserveralias #accept ssh for alias myserveralias
239 |IN SSH(ACCEPT) -i net0 # disabled rule
241 IN DROP # drop all incoming packages
242 OUT ACCEPT # accept all outgoing packages
246 [[pve_firewall_security_groups]]
250 A security group is a collection of rules, defined at cluster level, which
251 can be used in all VMs' rules. For example you can define a group named
252 ``webserver'' with rules to open the 'http' and 'https' ports.
255 # /etc/pve/firewall/cluster.fw
258 IN ACCEPT -p tcp -dport 80
259 IN ACCEPT -p tcp -dport 443
262 Then, you can add this group to a VM's firewall
265 # /etc/pve/firewall/<VMID>.fw
271 [[pve_firewall_ip_aliases]]
275 IP Aliases allow you to associate IP addresses of networks with a
276 name. You can then refer to those names:
278 * inside IP set definitions
279 * in `source` and `dest` properties of firewall rules
282 Standard IP Alias `local_network`
283 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285 This alias is automatically defined. Please use the following command
286 to see assigned values:
289 # pve-firewall localnet
290 local hostname: example
291 local IP address: 192.168.2.100
292 network auto detect: 192.168.0.0/20
293 using detected local_network: 192.168.0.0/20
296 The firewall automatically sets up rules to allow everything needed
297 for cluster communication (corosync, API, SSH) using this alias.
299 The user can overwrite these values in the `cluster.fw` alias
300 section. If you use a single host on a public network, it is better to
301 explicitly assign the local IP address
304 # /etc/pve/firewall/cluster.fw
306 local_network 1.2.3.4 # use the single IP address
309 [[pve_firewall_ip_sets]]
313 IP sets can be used to define groups of networks and hosts. You can
314 refer to them with `+name` in the firewall rules' `source` and `dest`
317 The following example allows HTTP traffic from the `management` IP
320 IN HTTP(ACCEPT) -source +management
323 Standard IP set `management`
324 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
326 This IP set applies only to host firewalls (not VM firewalls). Those
327 IPs are allowed to do normal management tasks (PVE GUI, VNC, SPICE,
330 The local cluster network is automatically added to this IP set (alias
331 `cluster_network`), to enable inter-host cluster
332 communication. (multicast,ssh,...)
335 # /etc/pve/firewall/cluster.fw
343 Standard IP set `blacklist`
344 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
346 Traffic from these IPs is dropped by every host's and VM's firewall.
349 # /etc/pve/firewall/cluster.fw
357 [[pve_firewall_ipfilter_section]]
358 Standard IP set `ipfilter-net*`
359 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
361 These filters belong to a VM's network interface and are mainly used to prevent
362 IP spoofing. If such a set exists for an interface then any outgoing traffic
363 with a source IP not matching its interface's corresponding ipfilter set will
366 For containers with configured IP addresses these sets, if they exist (or are
367 activated via the general `IP Filter` option in the VM's firewall's *options*
368 tab), implicitly contain the associated IP addresses.
370 For both virtual machines and containers they also implicitly contain the
371 standard MAC-derived IPv6 link-local address in order to allow the neighbor
372 discovery protocol to work.
375 /etc/pve/firewall/<VMID>.fw
377 [IPSET ipfilter-net0] # only allow specified IPs on net0
382 Services and Commands
383 ---------------------
385 The firewall runs two service daemons on each node:
387 * pvefw-logger: NFLOG daemon (ulogd replacement).
388 * pve-firewall: updates iptables rules
390 There is also a CLI command named `pve-firewall`, which can be used to
391 start and stop the firewall service:
396 To get the status use:
398 # pve-firewall status
400 The above command reads and compiles all firewall rules, so you will
401 see warnings if your firewall configuration contains any errors.
403 If you want to see the generated iptables rules you can use:
407 [[pve_firewall_default_rules]]
408 Default firewall rules
409 ----------------------
411 The following traffic is filtered by the default firewall configuration:
413 Datacenter incomming/outgoing DROP/REJECT
414 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
416 If the input/output policy for the firewall is set to DROP/REJECT, the following
417 traffic is still allowed for the host:
419 * traffic over the loopback interface
420 * already established connections
421 * traffic using the igmp protocol
422 * tcp traffic from management hosts to port 8006 in order to allow access to
424 * tcp traffic from management hosts to the port range 5900 to 5999 allowing
425 traffic for the VNC web console
426 * tcp traffic from management hosts to port 3128 for connections to the SPICE
428 * tcp traffic from management hosts to port 22 to allow ssh access
429 * udp traffic in the cluster network to port 5404 and 5405 for corosync
430 * udp multicast traffic in the cluster network
431 * icmp traffic type 3,4 or 11
433 The following traffic is dropped, but not logged even with logging enabled:
435 * tcp connections with invalid connection state
436 * Broad-, multi- and anycast traffic not related to corosync
437 * tcp traffic to port 43
438 * udp traffic to ports 135 and 445
439 * udp traffic to the port range 137 to 139
440 * udp traffic form source port 137 to port range 1024 to 65535
441 * udp traffic to port 1900
442 * tcp traffic to port 135, 139 and 445
443 * udp traffic originating from source port 53
445 The rest of the traffic is dropped/rejected and logged.
446 This may vary depending on the additional options enabled in
447 *Firewall* -> *Options*, such as NDP, SMURFS and TCP flag filtering.
449 Please inspect the output of
453 to see the firewall chains and rules active on your system.
455 VM/CT incomming/outgoing DROP/REJECT
456 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
458 This drops/rejects all the traffic to the VMs, with some exceptions for DHCP, NDP,
459 Router Advertisement, MAC and IP filtering depending on the set configuration.
460 The same rules for dropping/rejecting packets are inherited from the datacenter,
461 while the exceptions for accepted incomming/outgoing traffic of the host do not
464 Again, please inspect the output of
468 to see in detail the firewall chains and rules active for the VMs/CTs.
470 Logging of firewall rules
471 -------------------------
473 By default, all logging of traffic filtered by the firewall rules is disabled.
474 To enable logging, the `loglevel` for incommig and/or outgoing traffic has to be
475 set in *Firewall* -> *Options*. This can be done for the host as well as for the
476 VM/CT firewall individually. By this, logging of {PVE}'s standard firewall rules
477 is enabled and the output can be observed in *Firewall* -> *Log*.
478 Further, only some dropped or rejected packets are logged for the standard rules
479 (see xref:pve_firewall_default_rules[default firewall rules]).
481 `loglevel` does not affect how much of the filtered traffic is logged. It
482 changes a `LOGID` appended as prefix to the log output for easier filtering and
485 `loglevel` is one of the following flags:
487 [[pve_firewall_log_levels]]
488 [width="25%", options="header"]
502 A typical firewall log output looks like this:
505 VMID LOGID CHAIN TIMESTAMP POLICY: PACKET_DETAILS
508 In case of the host firewall, `VMID` is equal to 0.
511 Logging of user defined firewall rules
512 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
514 In order to log packets filtered by user-defined firewall rules, it is possible
515 to set a log-level parameter for each rule individually.
516 This allows to log in a fine grained manner and independent of the log-level
517 defined for the standard rules in *Firewall* -> *Options*.
519 While the `loglevel` for each individual rule can be defined or changed easily
520 in the WebUI during creation or modification of the rule, it is possible to set
521 this also via the corresponding `pvesh` API calls.
523 Further, the log-level can also be set via the firewall configuration file by
524 appending a `-log <loglevel>` to the selected rule (see
525 xref:pve_firewall_log_levels[possible log-levels]).
527 For example, the following two are ident:
530 IN REJECT -p icmp -log nolog
537 IN REJECT -p icmp -log debug
540 produces a log output flagged with the `debug` level.
549 FTP is an old style protocol which uses port 21 and several other dynamic ports. So you
550 need a rule to accept port 21. In addition, you need to load the `ip_conntrack_ftp` module.
553 modprobe ip_conntrack_ftp
555 and add `ip_conntrack_ftp` to `/etc/modules` (so that it works after a reboot).
558 Suricata IPS integration
559 ~~~~~~~~~~~~~~~~~~~~~~~~
561 If you want to use the http://suricata-ids.org/[Suricata IPS]
562 (Intrusion Prevention System), it's possible.
564 Packets will be forwarded to the IPS only after the firewall ACCEPTed
567 Rejected/Dropped firewall packets don't go to the IPS.
569 Install suricata on proxmox host:
572 # apt-get install suricata
573 # modprobe nfnetlink_queue
576 Don't forget to add `nfnetlink_queue` to `/etc/modules` for next reboot.
578 Then, enable IPS for a specific VM with:
581 # /etc/pve/firewall/<VMID>.fw
588 `ips_queues` will bind a specific cpu queue for this VM.
590 Available queues are defined in
593 # /etc/default/suricata
601 The firewall contains a few IPv6 specific options. One thing to note is that
602 IPv6 does not use the ARP protocol anymore, and instead uses NDP (Neighbor
603 Discovery Protocol) which works on IP level and thus needs IP addresses to
604 succeed. For this purpose link-local addresses derived from the interface's MAC
605 address are used. By default the `NDP` option is enabled on both host and VM
606 level to allow neighbor discovery (NDP) packets to be sent and received.
608 Beside neighbor discovery NDP is also used for a couple of other things, like
609 auto-configuration and advertising routers.
611 By default VMs are allowed to send out router solicitation messages (to query
612 for a router), and to receive router advertisement packets. This allows them to
613 use stateless auto configuration. On the other hand VMs cannot advertise
614 themselves as routers unless the ``Allow Router Advertisement'' (`radv: 1`) option
617 As for the link local addresses required for NDP, there's also an ``IP Filter''
618 (`ipfilter: 1`) option which can be enabled which has the same effect as adding
619 an `ipfilter-net*` ipset for each of the VM's network interfaces containing the
620 corresponding link local addresses. (See the
621 <<pve_firewall_ipfilter_section,Standard IP set `ipfilter-net*`>> section for details.)
627 * Web interface: 8006
628 * VNC Web console: 5900-5999
630 * sshd (used for cluster actions): 22
632 * corosync multicast (if you run a cluster): 5404, 5405 UDP
640 include::pve-firewall-macros.adoc[]
643 include::pve-copyright.adoc[]