linux:apps:kvm:kvm-hardening
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:apps:kvm:kvm-hardening [2026/09/13 15:24] – oscar | linux:apps:kvm:kvm-hardening [2026/09/16 16:31] (current) – [Network containing] oscar | ||
|---|---|---|---|
| Line 67: | Line 67: | ||
| ------------------------------------------------------- | ------------------------------------------------------- | ||
| - | !/bin/bash | + | #!/bin/bash |
| set -euo pipefail | set -euo pipefail | ||
| - | VM_NAME=" | + | NFT="/ |
| - | VM_MAC=" | + | VM_NAME=" |
| + | VM_MAC=$(/ | ||
| LIBVIRT_BRIDGE=" | LIBVIRT_BRIDGE=" | ||
| - | ALLOWED_IPV4=" | + | HOST_INTERFACE="enp2s0" |
| - | + | BLOCKED_IPV4_RANGES=" | |
| - | NFT="/usr/sbin/nft" | + | BLOCKED_IPV6_RANGES="{ 2001: |
| TABLE=" | TABLE=" | ||
| CHAIN=" | CHAIN=" | ||
| Line 86: | Line 85: | ||
| " | " | ||
| " | " | ||
| - | " | + | " |
| - | | + | |
| + | # Allow established and related return traffic | ||
| + | " | ||
| # Allow only VM -> 192.168.178.1 | # Allow only VM -> 192.168.178.1 | ||
| - | | + | " |
| - | iifname | + | " |
| - | ether saddr " | + | |
| - | ip daddr "$ALLOWED_IPV4" | + | |
| - | accept | + | |
| - | # Drop everything else originating | + | # ALLOW remaining traffic |
| - | # This includes IPv4 and IPv6. | + | " |
| - | " | + | |
| - | iifname " | + | |
| - | | + | |
| - | drop | + | |
| } | } | ||
| + | |||
| remove_rules() | remove_rules() | ||
| { | { | ||
| Line 137: | Line 132: | ||
| Check if the firewall settings are created and removed with: | Check if the firewall settings are created and removed with: | ||
| # nft list ruleset | # nft list ruleset | ||
| + | The firewall settings will look something like: | ||
| + | ``` | ||
| + | table inet vm_filter { | ||
| + | chain vm_Debian13_ESP { | ||
| + | type filter hook forward priority raw; policy accept; | ||
| + | ct state established, | ||
| + | ether saddr 51: | ||
| + | ether saddr 51: | ||
| + | ether saddr 51: | ||
| + | } | ||
| + | } | ||
| + | ``` | ||
| ## Kernel Samepage Merging (KSM) | ## Kernel Samepage Merging (KSM) | ||
linux/apps/kvm/kvm-hardening.1789313095.txt.gz · Last modified: by oscar
