]>
Commit | Line | Data |
---|---|---|
80c0adcb | 1 | [[chapter_pve_firewall]] |
c7eda5e6 | 2 | ifdef::manvolnum[] |
b2f242ab DM |
3 | pve-firewall(8) |
4 | =============== | |
38fd0958 | 5 | include::attributes.txt[] |
5f09af76 DM |
6 | :pve-toplevel: |
7 | ||
c7eda5e6 DM |
8 | NAME |
9 | ---- | |
10 | ||
f5eb0727 | 11 | pve-firewall - PVE Firewall Daemon |
c7eda5e6 DM |
12 | |
13 | ||
49a5e11c | 14 | SYNOPSIS |
c7eda5e6 DM |
15 | -------- |
16 | ||
5f34196d | 17 | include::pve-firewall.8-synopsis.adoc[] |
c7eda5e6 DM |
18 | |
19 | ||
20 | DESCRIPTION | |
21 | ----------- | |
22 | endif::manvolnum[] | |
c7eda5e6 DM |
23 | ifndef::manvolnum[] |
24 | {pve} Firewall | |
25 | ============== | |
38fd0958 | 26 | include::attributes.txt[] |
194d2f29 | 27 | :pve-toplevel: |
c7eda5e6 | 28 | endif::manvolnum[] |
5f09af76 | 29 | ifdef::wiki[] |
cb84ed18 | 30 | :title: Firewall |
5f09af76 DM |
31 | endif::wiki[] |
32 | ||
26ca7ff5 | 33 | {pve} Firewall provides an easy way to protect your IT |
89a8b6c6 | 34 | infrastructure. You can setup firewall rules for all hosts |
c7eda5e6 DM |
35 | inside a cluster, or define rules for virtual machines and |
36 | containers. Features like firewall macros, security groups, IP sets | |
5eba0743 | 37 | and aliases help to make that task easier. |
c7eda5e6 DM |
38 | |
39 | While all configuration is stored on the cluster file system, the | |
8c1189b6 | 40 | `iptables`-based firewall runs on each cluster node, and thus provides |
c7eda5e6 DM |
41 | full isolation between virtual machines. The distributed nature of |
42 | this system also provides much higher bandwidth than a central | |
43 | firewall solution. | |
44 | ||
bd73a43e DM |
45 | The firewall has full support for IPv4 and IPv6. IPv6 support is fully |
46 | transparent, and we filter traffic for both protocols by default. So | |
47 | there is no need to maintain a different set of rules for IPv6. | |
48 | ||
c7eda5e6 DM |
49 | |
50 | Zones | |
51 | ----- | |
52 | ||
53 | The Proxmox VE firewall groups the network into the following logical zones: | |
54 | ||
55 | Host:: | |
56 | ||
57 | Traffic from/to a cluster node | |
58 | ||
59 | VM:: | |
60 | ||
61 | Traffic from/to a specific VM | |
62 | ||
63 | For each zone, you can define firewall rules for incoming and/or | |
64 | outgoing traffic. | |
65 | ||
66 | ||
79672214 DM |
67 | Configuration Files |
68 | ------------------- | |
c7eda5e6 DM |
69 | |
70 | All firewall related configuration is stored on the proxmox cluster | |
71 | file system. So those files are automatically distributed to all | |
8c1189b6 FG |
72 | cluster nodes, and the `pve-firewall` service updates the underlying |
73 | `iptables` rules automatically on changes. | |
c7eda5e6 | 74 | |
e300cf7d FG |
75 | You can configure anything using the GUI (i.e. *Datacenter* -> *Firewall*, |
76 | or on a *Node* -> *Firewall*), or you can edit the configuration files | |
89a8b6c6 DM |
77 | directly using your preferred editor. |
78 | ||
79 | Firewall configuration files contains sections of key-value | |
8c1189b6 | 80 | pairs. Lines beginning with a `#` and blank lines are considered |
79672214 | 81 | comments. Sections starts with a header line containing the section |
8c1189b6 | 82 | name enclosed in `[` and `]`. |
79672214 | 83 | |
89a8b6c6 | 84 | |
80c0adcb | 85 | [[pve_firewall_cluster_wide_setup]] |
79672214 DM |
86 | Cluster Wide Setup |
87 | ~~~~~~~~~~~~~~~~~~ | |
88 | ||
89 | The cluster wide firewall configuration is stored at: | |
c7eda5e6 DM |
90 | |
91 | /etc/pve/firewall/cluster.fw | |
92 | ||
79672214 | 93 | The configuration can contain the following sections: |
c7eda5e6 | 94 | |
8c1189b6 | 95 | `[OPTIONS]`:: |
79672214 DM |
96 | |
97 | This is used to set cluster wide firewall options. | |
98 | ||
c48819d1 DM |
99 | include::pve-firewall-cluster-opts.adoc[] |
100 | ||
8c1189b6 | 101 | `[RULES]`:: |
c7eda5e6 | 102 | |
79672214 DM |
103 | This sections contains cluster wide firewall rules for all nodes. |
104 | ||
8c1189b6 | 105 | `[IPSET <name>]`:: |
79672214 DM |
106 | |
107 | Cluster wide IP set definitions. | |
108 | ||
8c1189b6 | 109 | `[GROUP <name>]`:: |
79672214 DM |
110 | |
111 | Cluster wide security group definitions. | |
112 | ||
8c1189b6 | 113 | `[ALIASES]`:: |
79672214 DM |
114 | |
115 | Cluster wide Alias definitions. | |
116 | ||
89a8b6c6 DM |
117 | |
118 | Enabling the Firewall | |
119 | ^^^^^^^^^^^^^^^^^^^^^ | |
120 | ||
121 | The firewall is completely disabled by default, so you need to | |
122 | set the enable option here: | |
123 | ||
124 | ---- | |
125 | [OPTIONS] | |
126 | # enable firewall (cluster wide setting, default is disabled) | |
127 | enable: 1 | |
128 | ---- | |
129 | ||
130 | IMPORTANT: If you enable the firewall, traffic to all hosts is blocked by | |
131 | default. Only exceptions is WebGUI(8006) and ssh(22) from your local | |
132 | network. | |
133 | ||
134 | If you want to administrate your {pve} hosts from remote, you | |
135 | need to create rules to allow traffic from those remote IPs to the web | |
136 | GUI (port 8006). You may also want to allow ssh (port 22), and maybe | |
137 | SPICE (port 3128). | |
138 | ||
139 | TIP: Please open a SSH connection to one of your {PVE} hosts before | |
140 | enabling the firewall. That way you still have access to the host if | |
141 | something goes wrong . | |
142 | ||
143 | To simplify that task, you can instead create an IPSet called | |
8c1189b6 | 144 | ``management'', and add all remote IPs there. This creates all required |
89a8b6c6 DM |
145 | firewall rules to access the GUI from remote. |
146 | ||
147 | ||
80c0adcb | 148 | [[pve_firewall_host_specific_configuration]] |
5eba0743 | 149 | Host Specific Configuration |
79672214 DM |
150 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
151 | ||
152 | Host related configuration is read from: | |
153 | ||
154 | /etc/pve/nodes/<nodename>/host.fw | |
155 | ||
8c1189b6 | 156 | This is useful if you want to overwrite rules from `cluster.fw` |
79672214 | 157 | config. You can also increase log verbosity, and set netfilter related |
888c4116 DM |
158 | options. The configuration can contain the following sections: |
159 | ||
8c1189b6 | 160 | `[OPTIONS]`:: |
888c4116 DM |
161 | |
162 | This is used to set host related firewall options. | |
163 | ||
164 | include::pve-firewall-host-opts.adoc[] | |
165 | ||
8c1189b6 | 166 | `[RULES]`:: |
888c4116 DM |
167 | |
168 | This sections contains host specific firewall rules. | |
79672214 | 169 | |
641cc419 | 170 | [[pve_firewall_vm_container_configuration]] |
5eba0743 | 171 | VM/Container Configuration |
79672214 | 172 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
c7eda5e6 | 173 | |
a4922e12 | 174 | VM firewall configuration is read from: |
c7eda5e6 DM |
175 | |
176 | /etc/pve/firewall/<VMID>.fw | |
177 | ||
178 | and contains the following data: | |
179 | ||
8c1189b6 | 180 | `[OPTIONS]`:: |
78ef35dc DM |
181 | |
182 | This is used to set VM/Container related firewall options. | |
183 | ||
184 | include::pve-firewall-vm-opts.adoc[] | |
185 | ||
8c1189b6 | 186 | `[RULES]`:: |
78ef35dc DM |
187 | |
188 | This sections contains VM/Container firewall rules. | |
189 | ||
8c1189b6 | 190 | `[IPSET <name>]`:: |
78ef35dc DM |
191 | |
192 | IP set definitions. | |
193 | ||
8c1189b6 | 194 | `[ALIASES]`:: |
78ef35dc DM |
195 | |
196 | IP Alias definitions. | |
c7eda5e6 | 197 | |
c7eda5e6 | 198 | |
58b16f71 | 199 | Enabling the Firewall for VMs and Containers |
79672214 | 200 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
c7eda5e6 | 201 | |
89a8b6c6 DM |
202 | Each virtual network device has its own firewall enable flag. So you |
203 | can selectively enable the firewall for each interface. This is | |
8c1189b6 | 204 | required in addition to the general firewall `enable` option. |
89a8b6c6 DM |
205 | |
206 | The firewall requires a special network device setup, so you need to | |
207 | restart the VM/container after enabling the firewall on a network | |
208 | interface. | |
c7eda5e6 | 209 | |
79672214 | 210 | |
c7eda5e6 | 211 | Firewall Rules |
79672214 | 212 | -------------- |
c7eda5e6 | 213 | |
696fb448 DM |
214 | Firewall rules consists of a direction (`IN` or `OUT`) and an |
215 | action (`ACCEPT`, `DENY`, `REJECT`). You can also specify a macro | |
8c1189b6 FG |
216 | name. Macros contain predefined sets of rules and options. Rules can be |
217 | disabled by prefixing them with `|`. | |
c7eda5e6 | 218 | |
696fb448 | 219 | .Firewall rules syntax |
c7eda5e6 DM |
220 | ---- |
221 | [RULES] | |
222 | ||
696fb448 DM |
223 | DIRECTION ACTION [OPTIONS] |
224 | |DIRECTION ACTION [OPTIONS] # disabled rule | |
c7eda5e6 | 225 | |
696fb448 DM |
226 | DIRECTION MACRO(ACTION) [OPTIONS] # use predefined macro |
227 | ---- | |
228 | ||
229 | The following options can be used to refine rule matches. | |
230 | ||
231 | include::pve-firewall-rules-opts.adoc[] | |
232 | ||
233 | Here are some examples: | |
c7eda5e6 | 234 | |
696fb448 DM |
235 | ---- |
236 | [RULES] | |
c7eda5e6 DM |
237 | IN SSH(ACCEPT) -i net0 |
238 | IN SSH(ACCEPT) -i net0 # a comment | |
696fb448 | 239 | IN SSH(ACCEPT) -i net0 -source 192.168.2.192 # only allow SSH from 192.168.2.192 |
c7eda5e6 DM |
240 | IN SSH(ACCEPT) -i net0 -source 10.0.0.1-10.0.0.10 # accept SSH for ip range |
241 | IN SSH(ACCEPT) -i net0 -source 10.0.0.1,10.0.0.2,10.0.0.3 #accept ssh for ip list | |
696fb448 DM |
242 | IN SSH(ACCEPT) -i net0 -source +mynetgroup # accept ssh for ipset mynetgroup |
243 | IN SSH(ACCEPT) -i net0 -source myserveralias #accept ssh for alias myserveralias | |
c7eda5e6 DM |
244 | |
245 | |IN SSH(ACCEPT) -i net0 # disabled rule | |
696fb448 DM |
246 | |
247 | IN DROP # drop all incoming packages | |
248 | OUT ACCEPT # accept all outgoing packages | |
c7eda5e6 DM |
249 | ---- |
250 | ||
8c1189b6 | 251 | |
80c0adcb | 252 | [[pve_firewall_security_groups]] |
c7eda5e6 | 253 | Security Groups |
79672214 | 254 | --------------- |
c7eda5e6 | 255 | |
58b16f71 WB |
256 | A security group is a collection of rules, defined at cluster level, which |
257 | can be used in all VMs' rules. For example you can define a group named | |
8c1189b6 | 258 | ``webserver'' with rules to open the 'http' and 'https' ports. |
c7eda5e6 DM |
259 | |
260 | ---- | |
261 | # /etc/pve/firewall/cluster.fw | |
262 | ||
263 | [group webserver] | |
264 | IN ACCEPT -p tcp -dport 80 | |
265 | IN ACCEPT -p tcp -dport 443 | |
266 | ---- | |
267 | ||
58b16f71 | 268 | Then, you can add this group to a VM's firewall |
c7eda5e6 DM |
269 | |
270 | ---- | |
271 | # /etc/pve/firewall/<VMID>.fw | |
272 | ||
273 | [RULES] | |
274 | GROUP webserver | |
275 | ---- | |
276 | ||
641cc419 | 277 | [[pve_firewall_ip_aliases]] |
c7eda5e6 | 278 | IP Aliases |
79672214 | 279 | ---------- |
c7eda5e6 | 280 | |
58b16f71 | 281 | IP Aliases allow you to associate IP addresses of networks with a |
c7eda5e6 DM |
282 | name. You can then refer to those names: |
283 | ||
284 | * inside IP set definitions | |
285 | * in `source` and `dest` properties of firewall rules | |
286 | ||
5eba0743 FG |
287 | |
288 | Standard IP Alias `local_network` | |
79672214 | 289 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
c7eda5e6 DM |
290 | |
291 | This alias is automatically defined. Please use the following command | |
292 | to see assigned values: | |
293 | ||
294 | ---- | |
295 | # pve-firewall localnet | |
296 | local hostname: example | |
297 | local IP address: 192.168.2.100 | |
298 | network auto detect: 192.168.0.0/20 | |
299 | using detected local_network: 192.168.0.0/20 | |
300 | ---- | |
301 | ||
302 | The firewall automatically sets up rules to allow everything needed | |
58b16f71 | 303 | for cluster communication (corosync, API, SSH) using this alias. |
c7eda5e6 | 304 | |
8c1189b6 | 305 | The user can overwrite these values in the `cluster.fw` alias |
c7eda5e6 DM |
306 | section. If you use a single host on a public network, it is better to |
307 | explicitly assign the local IP address | |
308 | ||
309 | ---- | |
310 | # /etc/pve/firewall/cluster.fw | |
311 | [ALIASES] | |
312 | local_network 1.2.3.4 # use the single ip address | |
313 | ---- | |
314 | ||
641cc419 | 315 | [[pve_firewall_ip_sets]] |
c7eda5e6 | 316 | IP Sets |
79672214 | 317 | ------- |
c7eda5e6 DM |
318 | |
319 | IP sets can be used to define groups of networks and hosts. You can | |
58b16f71 | 320 | refer to them with `+name` in the firewall rules' `source` and `dest` |
c7eda5e6 DM |
321 | properties. |
322 | ||
323 | The following example allows HTTP traffic from the `management` IP | |
324 | set. | |
325 | ||
326 | IN HTTP(ACCEPT) -source +management | |
327 | ||
5eba0743 | 328 | |
c7eda5e6 | 329 | Standard IP set `management` |
79672214 | 330 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
c7eda5e6 DM |
331 | |
332 | This IP set applies only to host firewalls (not VM firewalls). Those | |
5eba0743 | 333 | IPs are allowed to do normal management tasks (PVE GUI, VNC, SPICE, |
c7eda5e6 DM |
334 | SSH). |
335 | ||
336 | The local cluster network is automatically added to this IP set (alias | |
337 | `cluster_network`), to enable inter-host cluster | |
338 | communication. (multicast,ssh,...) | |
339 | ||
340 | ---- | |
341 | # /etc/pve/firewall/cluster.fw | |
342 | ||
343 | [IPSET management] | |
344 | 192.168.2.10 | |
345 | 192.168.2.10/24 | |
346 | ---- | |
347 | ||
8c1189b6 FG |
348 | |
349 | Standard IP set `blacklist` | |
79672214 | 350 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
c7eda5e6 | 351 | |
5eba0743 | 352 | Traffic from these IPs is dropped by every host's and VM's firewall. |
c7eda5e6 DM |
353 | |
354 | ---- | |
355 | # /etc/pve/firewall/cluster.fw | |
356 | ||
357 | [IPSET blacklist] | |
358 | 77.240.159.182 | |
359 | 213.87.123.0/24 | |
360 | ---- | |
361 | ||
8c1189b6 | 362 | |
80c0adcb | 363 | [[pve_firewall_ipfilter_section]] |
8c1189b6 | 364 | Standard IP set `ipfilter-net*` |
79672214 | 365 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
c7eda5e6 | 366 | |
a34d23e8 WB |
367 | These filters belong to a VM's network interface and are mainly used to prevent |
368 | IP spoofing. If such a set exists for an interface then any outgoing traffic | |
369 | with a source IP not matching its interface's corresponding ipfilter set will | |
370 | be dropped. | |
371 | ||
372 | For containers with configured IP addresses these sets, if they exist (or are | |
e300cf7d | 373 | activated via the general `IP Filter` option in the VM's firewall's *options* |
a34d23e8 WB |
374 | tab), implicitly contain the associated IP addresses. |
375 | ||
376 | For both virtual machines and containers they also implicitly contain the | |
377 | standard MAC-derived IPv6 link-local address in order to allow the neighbor | |
378 | discovery protocol to work. | |
c7eda5e6 DM |
379 | |
380 | ---- | |
381 | /etc/pve/firewall/<VMID>.fw | |
382 | ||
383 | [IPSET ipfilter-net0] # only allow specified IPs on net0 | |
384 | 192.168.2.10 | |
385 | ---- | |
386 | ||
79672214 | 387 | |
c7eda5e6 | 388 | Services and Commands |
79672214 | 389 | --------------------- |
c7eda5e6 DM |
390 | |
391 | The firewall runs two service daemons on each node: | |
392 | ||
393 | * pvefw-logger: NFLOG daemon (ulogd replacement). | |
394 | * pve-firewall: updates iptables rules | |
395 | ||
8c1189b6 | 396 | There is also a CLI command named `pve-firewall`, which can be used to |
c7eda5e6 DM |
397 | start and stop the firewall service: |
398 | ||
399 | # pve-firewall start | |
400 | # pve-firewall stop | |
401 | ||
402 | To get the status use: | |
403 | ||
404 | # pve-firewall status | |
405 | ||
406 | The above command reads and compiles all firewall rules, so you will | |
407 | see warnings if your firewall configuration contains any errors. | |
408 | ||
409 | If you want to see the generated iptables rules you can use: | |
410 | ||
411 | # iptables-save | |
412 | ||
79672214 | 413 | |
c7eda5e6 | 414 | Tips and Tricks |
79672214 | 415 | --------------- |
c7eda5e6 DM |
416 | |
417 | How to allow FTP | |
79672214 | 418 | ~~~~~~~~~~~~~~~~ |
c7eda5e6 DM |
419 | |
420 | FTP is an old style protocol which uses port 21 and several other dynamic ports. So you | |
8c1189b6 | 421 | need a rule to accept port 21. In addition, you need to load the `ip_conntrack_ftp` module. |
c7eda5e6 DM |
422 | So please run: |
423 | ||
424 | modprobe ip_conntrack_ftp | |
425 | ||
8c1189b6 | 426 | and add `ip_conntrack_ftp` to `/etc/modules` (so that it works after a reboot). |
c7eda5e6 | 427 | |
79672214 | 428 | |
c7eda5e6 | 429 | Suricata IPS integration |
79672214 | 430 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
c7eda5e6 DM |
431 | |
432 | If you want to use the http://suricata-ids.org/[Suricata IPS] | |
433 | (Intrusion Prevention System), it's possible. | |
434 | ||
435 | Packets will be forwarded to the IPS only after the firewall ACCEPTed | |
436 | them. | |
437 | ||
438 | Rejected/Dropped firewall packets don't go to the IPS. | |
439 | ||
440 | Install suricata on proxmox host: | |
441 | ||
442 | ---- | |
443 | # apt-get install suricata | |
444 | # modprobe nfnetlink_queue | |
445 | ---- | |
446 | ||
8c1189b6 | 447 | Don't forget to add `nfnetlink_queue` to `/etc/modules` for next reboot. |
c7eda5e6 DM |
448 | |
449 | Then, enable IPS for a specific VM with: | |
450 | ||
451 | ---- | |
452 | # /etc/pve/firewall/<VMID>.fw | |
453 | ||
454 | [OPTIONS] | |
455 | ips: 1 | |
456 | ips_queues: 0 | |
457 | ---- | |
458 | ||
459 | `ips_queues` will bind a specific cpu queue for this VM. | |
460 | ||
461 | Available queues are defined in | |
462 | ||
463 | ---- | |
464 | # /etc/default/suricata | |
465 | NFQUEUE=0 | |
466 | ---- | |
467 | ||
8c1189b6 | 468 | |
79672214 DM |
469 | Notes on IPv6 |
470 | ------------- | |
471 | ||
472 | The firewall contains a few IPv6 specific options. One thing to note is that | |
473 | IPv6 does not use the ARP protocol anymore, and instead uses NDP (Neighbor | |
474 | Discovery Protocol) which works on IP level and thus needs IP addresses to | |
475 | succeed. For this purpose link-local addresses derived from the interface's MAC | |
8c1189b6 | 476 | address are used. By default the `NDP` option is enabled on both host and VM |
79672214 DM |
477 | level to allow neighbor discovery (NDP) packets to be sent and received. |
478 | ||
479 | Beside neighbor discovery NDP is also used for a couple of other things, like | |
480 | autoconfiguration and advertising routers. | |
481 | ||
482 | By default VMs are allowed to send out router solicitation messages (to query | |
5eba0743 | 483 | for a router), and to receive router advertisement packets. This allows them to |
79672214 | 484 | use stateless auto configuration. On the other hand VMs cannot advertise |
8c1189b6 | 485 | themselves as routers unless the ``Allow Router Advertisement'' (`radv: 1`) option |
79672214 DM |
486 | is set. |
487 | ||
8c1189b6 | 488 | As for the link local addresses required for NDP, there's also an ``IP Filter'' |
79672214 DM |
489 | (`ipfilter: 1`) option which can be enabled which has the same effect as adding |
490 | an `ipfilter-net*` ipset for each of the VM's network interfaces containing the | |
491 | corresponding link local addresses. (See the | |
80c0adcb | 492 | <<pve_firewall_ipfilter_section,Standard IP set `ipfilter-net*`>> section for details.) |
79672214 DM |
493 | |
494 | ||
26ca7ff5 FG |
495 | Ports used by {pve} |
496 | ------------------- | |
224128ce DM |
497 | |
498 | * Web interface: 8006 | |
499 | * VNC Web console: 5900-5999 | |
500 | * SPICE proxy: 3128 | |
501 | * sshd (used for cluster actions): 22 | |
502 | * rpcbind: 111 | |
5eba0743 | 503 | * corosync multicast (if you run a cluster): 5404, 5405 UDP |
224128ce | 504 | |
14c06023 DM |
505 | |
506 | ifdef::manvolnum[] | |
507 | ||
508 | Macro Definitions | |
509 | ----------------- | |
510 | ||
511 | include::pve-firewall-macros.adoc[] | |
512 | ||
513 | ||
514 | include::pve-copyright.adoc[] | |
515 | ||
516 | endif::manvolnum[] |