q25-sysctl-kernel-parameters
Énoncé§
Solve this question on: terminal
- Enable IPv4 packet forwarding persistently.
- Disable IPv6 on all interfaces persistently.
- Set
vm.swappinessto10for the current session only. - Write the value of
kernel.hostnameinto/opt/course/25/hostname.
Solution§
Read current values§
sysctl kernel.hostname
sysctl -a # dump everything
sysctl -a 2>/dev/null | grep forward
cat /proc/sys/net/ipv4/ip_forward # equivalent direct read
Each kernel parameter maps to a file under /proc/sys/ — dots become slashes (net.ipv4.ip_forward ↔ /proc/sys/net/ipv4/ip_forward).
Step 1 — Persistent IP forwarding§
Create a drop-in file (preferred over editing /etc/sysctl.conf):
sudo tee /etc/sysctl.d/99-forwarding.conf <<'EOF'
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system # reload all .conf files
# or apply that file only:
sudo sysctl -p /etc/sysctl.d/99-forwarding.conf
Step 2 — Disable IPv6 persistently§
sudo tee /etc/sysctl.d/99-no-ipv6.conf <<'EOF'
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
EOF
sudo sysctl --system
Step 3 — Set a value only for this session§
sudo sysctl -w vm.swappiness=10
# equivalent:
echo 10 | sudo tee /proc/sys/vm/swappiness
Non-persistent changes are lost at reboot.
Step 4 — Write a single value§
sysctl -n kernel.hostname > /opt/course/25/hostname
Order of evaluation§
sysctl --system reads, in order:
/etc/sysctl.d/*.conf/run/sysctl.d/*.conf/usr/local/lib/sysctl.d/*.conf/usr/lib/sysctl.d/*.conf/lib/sysctl.d/*.conf/etc/sysctl.conf
Within a directory, files are sorted by name — use 99- prefix to override vendor defaults.
Common tunables to recognise§
| Key | Effect |
|---|---|
net.ipv4.ip_forward | enable IP routing |
net.ipv4.conf.all.rp_filter | reverse-path filtering (anti-spoof) |
net.ipv4.tcp_syncookies | SYN-flood protection |
vm.swappiness | swap aggressiveness (0–100) |
vm.overcommit_memory | memory overcommit policy |
kernel.pid_max | max PID |
fs.file-max | system-wide open file limit |
kernel.panic | seconds before reboot on panic |
—The Gardener