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