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