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