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