Linux 加固的另一种有效方法是保护内核参数。 您可以使用配置这些参数 系统控制 或者通过修改配置文件。 下面是一些常见的配置。
kernel.randomize_va_space=2 # randomnize address base for mmap, heap, and stack kernel.panic=10 # reboot after 10 sec following a kernel panic net.ipv4.icmp_ignore_bogus_error_responses # protects bad error messages net.ipv4.ip_forward=0 # disables IP forwarding net.ipv4.icmp_ignore_bogus_error_responses=1 # ignores ICP errors
这些只是一些基本配置。 您将通过经验学习不同的内核配置方式。
9.配置iptables
Linux 内核通过其 Netfilter API 为网络数据包提供强大的过滤方法。 您可以使用 iptables 与此 API 交互并为网络请求设置自定义过滤器。 下面是一些针对安全用户的基本 iptables 规则。
-A INPUT -j REJECT # reject all inbound requests -A FORWARD -j REJECT # reject traffic forwarding -A INPUT -i lo -j ACCEPT -A OUTPUT -o lo -j ACCEPT # allow traffic on localhost # allow ping requests -A OUTPUT -p icmp -j ACCEPT # allow outgoing pings # allow established/related connections -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # allow DNS lookups -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT # allow http/https requests -A OUTPUT -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT -A OUTPUT -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT # allow SSH access -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT
10. 监控日志
您可以利用日志更好地了解您的 Linux 机器。 您的系统为应用程序和服务存储了多个日志文件。 我们在这里概述了重要的内容。
/var/log/auth.log — 记录授权尝试
/var/log/daemon.log — 记录后台应用程序
/var/log/debug — 记录调试数据
/var/log/kern.log — 记录内核数据
/var/log/syslog — 记录系统数据
/var/log/faillog — 记录失败的登录
适合初学者的最佳 Linux 强化技巧
保护 Linux 系统并不像您想象的那么难。 您可以按照本指南中提到的一些提示来加强安全性。 随着经验的积累,您将掌握更多保护 Linux 的方法。
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.