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