]> git.proxmox.com Git - pve-docs.git/blame - pve-firewall.adoc
Update index.adoc
[pve-docs.git] / pve-firewall.adoc
CommitLineData
c7eda5e6
DM
1include::attributes.txt[]
2ifdef::manvolnum[]
3PVE({manvolnum})
4================
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==============
25endif::manvolnum[]
26
27// Copied from pve wiki: Revision as of 08:45, 9 November 2015
28
29Proxmox VE Firewall provides an easy way to protect your IT
30infrastructure. You can easily setup firewall rules for all hosts
31inside a cluster, or define rules for virtual machines and
32containers. Features like firewall macros, security groups, IP sets
33and aliases help making that task easier.
34
35While all configuration is stored on the cluster file system, the
36iptables based firewall runs on each cluster node, and thus provides
37full isolation between virtual machines. The distributed nature of
38this system also provides much higher bandwidth than a central
39firewall solution.
40
41NOTE: If you enable the firewall, all traffic is blocked by default,
42except WebGUI(8006) and ssh(22) from your local network.
43
44
45Zones
46-----
47
48The Proxmox VE firewall groups the network into the following logical zones:
49
50Host::
51
52Traffic from/to a cluster node
53
54VM::
55
56Traffic from/to a specific VM
57
58For each zone, you can define firewall rules for incoming and/or
59outgoing traffic.
60
61
62Ports used by Proxmox VE
63------------------------
64
65* Web interface: 8006
66* VNC Web console: 5900-5999
67* SPICE proxy: 3128
68* sshd (used for cluster actions): 22
69* rpcbind: 111
70* corosync multicast (if you run a cluster): 5404, 5405 UDP
71
72
73Configuration
74-------------
75
76All firewall related configuration is stored on the proxmox cluster
77file system. So those files are automatically distributed to all
78cluster nodes, and the 'pve-firewall' service updates the underlying
79iptables rules automatically on any change. Any configuration can be
80done using the GUI (i.e. Datacenter -> Firewall -> Options tab (tabs
81at the bottom of the page), or on a Node -> Firewall), so the
82following configuration file snippets are just for completeness.
83
84Cluster wide configuration is stored at:
85
86 /etc/pve/firewall/cluster.fw
87
88The firewall is completely disabled by default, so you need to set the
89enable option here:
90
91----
92[OPTIONS]
93# enable firewall (cluster wide setting, default is disabled)
94enable: 1
95----
96
97The cluster wide configuration can contain the following data:
98
99* IP set definitions
100* Alias definitions
101* Security group definitions
102* Cluster wide firewall rules for all nodes
103
104VM firewall configuration is read from:
105
106 /etc/pve/firewall/<VMID>.fw
107
108and contains the following data:
109
110* IP set definitions
111* Alias definitions
112* Firewall rules for this VM
113* VM specific options
114
115And finally, any host related configuration is read from:
116
117 /etc/pve/nodes/<nodename>/host.fw
118
119This is useful if you want to overwrite rules from 'cluster.fw'
120config. You can also increase log verbosity, and set netfilter related
121options.
122
123Enabling Firewall for VMs and Containers
124~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125
126You need to enable the firewall on the virtual network interface configuration.
127
128Firewall Rules
129~~~~~~~~~~~~~~
130
131Any firewall rule consists of a direction (`IN` or `OUT`) and an
132action (`ACCEPT`, `DENY`, `REJECT`). Additional options can be used to
133refine rule matches. Here are some examples:
134
135----
136[RULES]
137
138#TYPE ACTION [OPTIONS]
139#TYPE MACRO(ACTION) [OPTIONS]
140
141# -i <INTERFACE>
142# -source <SOURCE>
143# -dest <DEST>
144# -p <PROTOCOL>
145# -dport <DESTINATION_PORT>
146# -sport <SOURCE_PORT>
147
148IN SSH(ACCEPT) -i net0
149IN SSH(ACCEPT) -i net0 # a comment
150IN SSH(ACCEPT) -i net0 -source 192.168.2.192 # only allow SSH from 192.168.2.192
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
153IN SSH(ACCEPT) -i net0 -source +mynetgroup # accept ssh for ipset mynetgroup
154IN SSH(ACCEPT) -i net0 -source myserveralias #accept ssh for alias myserveralias
155
156|IN SSH(ACCEPT) -i net0 # disabled rule
157----
158
159Security Groups
160~~~~~~~~~~~~~~~
161
162A security group is a group a rules, defined at cluster level, which
163can be used in all VMs rules. For example you can define a group named
164`webserver` with rules to open http and https ports.
165
166----
167# /etc/pve/firewall/cluster.fw
168
169[group webserver]
170IN ACCEPT -p tcp -dport 80
171IN ACCEPT -p tcp -dport 443
172----
173
174Then, you can add this group in a vm firewall
175
176----
177# /etc/pve/firewall/<VMID>.fw
178
179[RULES]
180GROUP webserver
181----
182
183
184IP Aliases
185~~~~~~~~~~
186
187IP Aliases allows you to associate IP addresses of Networks with a
188name. You can then refer to those names:
189
190* inside IP set definitions
191* in `source` and `dest` properties of firewall rules
192
193Standard IP alias `local_network`
194^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
195
196This alias is automatically defined. Please use the following command
197to see assigned values:
198
199----
200# pve-firewall localnet
201local hostname: example
202local IP address: 192.168.2.100
203network auto detect: 192.168.0.0/20
204using detected local_network: 192.168.0.0/20
205----
206
207The firewall automatically sets up rules to allow everything needed
208for cluster communication (corosync, API, SSH).
209
210The user can overwrite these values in the cluster.fw alias
211section. If you use a single host on a public network, it is better to
212explicitly assign the local IP address
213
214----
215# /etc/pve/firewall/cluster.fw
216[ALIASES]
217local_network 1.2.3.4 # use the single ip address
218----
219
220IP Sets
221~~~~~~~
222
223IP sets can be used to define groups of networks and hosts. You can
224refer to them with `+name` in firewall rules `source` and `dest`
225properties.
226
227The following example allows HTTP traffic from the `management` IP
228set.
229
230 IN HTTP(ACCEPT) -source +management
231
232Standard IP set `management`
233^^^^^^^^^^^^^^^^^^^^^^^^^^^^
234
235This IP set applies only to host firewalls (not VM firewalls). Those
236ips are allowed to do normal management tasks (PVE GUI, VNC, SPICE,
237SSH).
238
239The local cluster network is automatically added to this IP set (alias
240`cluster_network`), to enable inter-host cluster
241communication. (multicast,ssh,...)
242
243----
244# /etc/pve/firewall/cluster.fw
245
246[IPSET management]
247192.168.2.10
248192.168.2.10/24
249----
250
251Standard IP set 'blacklist'
252^^^^^^^^^^^^^^^^^^^^^^^^^^^
253
254Traffic from those ips is dropped in all hosts and VMs firewalls.
255
256----
257# /etc/pve/firewall/cluster.fw
258
259[IPSET blacklist]
26077.240.159.182
261213.87.123.0/24
262----
263
264Standard IP set 'ipfilter'
265^^^^^^^^^^^^^^^^^^^^^^^^^^
266
267This ipset is used to prevent ip spoofing
268
269----
270/etc/pve/firewall/<VMID>.fw
271
272[IPSET ipfilter-net0] # only allow specified IPs on net0
273192.168.2.10
274----
275
276Services and Commands
277~~~~~~~~~~~~~~~~~~~~~
278
279The firewall runs two service daemons on each node:
280
281* pvefw-logger: NFLOG daemon (ulogd replacement).
282* pve-firewall: updates iptables rules
283
284There is also a CLI command named 'pve-firewall', which can be used to
285start and stop the firewall service:
286
287 # pve-firewall start
288 # pve-firewall stop
289
290To get the status use:
291
292 # pve-firewall status
293
294The above command reads and compiles all firewall rules, so you will
295see warnings if your firewall configuration contains any errors.
296
297If you want to see the generated iptables rules you can use:
298
299 # iptables-save
300
301Tips and Tricks
302~~~~~~~~~~~~~~~
303
304How to allow FTP
305^^^^^^^^^^^^^^^^
306
307FTP is an old style protocol which uses port 21 and several other dynamic ports. So you
308need a rule to accept port 21. In addition, you need to load the 'ip_conntrack_ftp' module.
309So please run:
310
311 modprobe ip_conntrack_ftp
312
313and add `ip_conntrack_ftp` to '/etc/modules' (so that it works after a reboot) .
314
315Suricata IPS integration
316^^^^^^^^^^^^^^^^^^^^^^^^
317
318If you want to use the http://suricata-ids.org/[Suricata IPS]
319(Intrusion Prevention System), it's possible.
320
321Packets will be forwarded to the IPS only after the firewall ACCEPTed
322them.
323
324Rejected/Dropped firewall packets don't go to the IPS.
325
326Install suricata on proxmox host:
327
328----
329# apt-get install suricata
330# modprobe nfnetlink_queue
331----
332
333Don't forget to add `nfnetlink_queue` to '/etc/modules' for next reboot.
334
335Then, enable IPS for a specific VM with:
336
337----
338# /etc/pve/firewall/<VMID>.fw
339
340[OPTIONS]
341ips: 1
342ips_queues: 0
343----
344
345`ips_queues` will bind a specific cpu queue for this VM.
346
347Available queues are defined in
348
349----
350# /etc/default/suricata
351NFQUEUE=0
352----
353
354
355ifdef::manvolnum[]
356include::copyright.adoc[]
357endif::manvolnum[]
358