Routing can be disabled by putting the following setting in /etc/sysctl.conf or a file in /etc/sysctl.d/
net.ipv4.ip_forward=0
It can also be disabled directly by issuing as root the command
echo 0 > /proc/sys/net/ipv4/ip_forward
It is also possible to do this in the bootloader on the kernel command line (see https://unix.stackexchange.com/a/593688/44864) with
sysctl.net.ipv4.ip_forward=0
My problem is that a bad actor that gains access can just as easily enable it again. I was disappointed that the kernel command-line argument can be overridden (tested on 5.10).
Am I right that probably the only way is to build my own kernel without ip routing compiled in or as a module with it being blacklisted?
If I'm right, which module(s) need to be disabled? Looking at my laptop's /boot/config, likely candidates are CONFIG_IP_ADVANCED_ROUTER, CONFIG_IP_ROUTE_MULTIPATH, CONFIG_IP_ROUTE_VERBOSE and CONFIG_IP_ROUTE_CLASSID.
Thanks for any help and insight.