]> git.proxmox.com Git - pve-docs.git/blame - pve-firewall.adoc
firewall: more complete description of the ipfilter-net* sets
[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
a34d23e8
WB
266Standard IP set 'ipfilter-net*'
267^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
c7eda5e6 268
a34d23e8
WB
269These filters belong to a VM's network interface and are mainly used to prevent
270IP spoofing. If such a set exists for an interface then any outgoing traffic
271with a source IP not matching its interface's corresponding ipfilter set will
272be dropped.
273
274For containers with configured IP addresses these sets, if they exist (or are
275activated via the general `IP Filter` option in the VM's firewall's 'options'
276tab), implicitly contain the associated IP addresses.
277
278For both virtual machines and containers they also implicitly contain the
279standard MAC-derived IPv6 link-local address in order to allow the neighbor
280discovery protocol to work.
c7eda5e6
DM
281
282----
283/etc/pve/firewall/<VMID>.fw
284
285[IPSET ipfilter-net0] # only allow specified IPs on net0
286192.168.2.10
287----
288
289Services and Commands
290~~~~~~~~~~~~~~~~~~~~~
291
292The firewall runs two service daemons on each node:
293
294* pvefw-logger: NFLOG daemon (ulogd replacement).
295* pve-firewall: updates iptables rules
296
297There is also a CLI command named 'pve-firewall', which can be used to
298start and stop the firewall service:
299
300 # pve-firewall start
301 # pve-firewall stop
302
303To get the status use:
304
305 # pve-firewall status
306
307The above command reads and compiles all firewall rules, so you will
308see warnings if your firewall configuration contains any errors.
309
310If you want to see the generated iptables rules you can use:
311
312 # iptables-save
313
314Tips and Tricks
315~~~~~~~~~~~~~~~
316
317How to allow FTP
318^^^^^^^^^^^^^^^^
319
320FTP is an old style protocol which uses port 21 and several other dynamic ports. So you
321need a rule to accept port 21. In addition, you need to load the 'ip_conntrack_ftp' module.
322So please run:
323
324 modprobe ip_conntrack_ftp
325
326and add `ip_conntrack_ftp` to '/etc/modules' (so that it works after a reboot) .
327
328Suricata IPS integration
329^^^^^^^^^^^^^^^^^^^^^^^^
330
331If you want to use the http://suricata-ids.org/[Suricata IPS]
332(Intrusion Prevention System), it's possible.
333
334Packets will be forwarded to the IPS only after the firewall ACCEPTed
335them.
336
337Rejected/Dropped firewall packets don't go to the IPS.
338
339Install suricata on proxmox host:
340
341----
342# apt-get install suricata
343# modprobe nfnetlink_queue
344----
345
346Don't forget to add `nfnetlink_queue` to '/etc/modules' for next reboot.
347
348Then, enable IPS for a specific VM with:
349
350----
351# /etc/pve/firewall/<VMID>.fw
352
353[OPTIONS]
354ips: 1
355ips_queues: 0
356----
357
358`ips_queues` will bind a specific cpu queue for this VM.
359
360Available queues are defined in
361
362----
363# /etc/default/suricata
364NFQUEUE=0
365----
366
367
368ifdef::manvolnum[]
369include::copyright.adoc[]
370endif::manvolnum[]
371