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