我想让我的新Web服务器上的防火墙保持安全。 在我做了iptables的研究之后,我遇到了UFW(Uncomplicated FireWall)。 这看起来像是一个更好的方式,让我在Ubuntu Server 10 LTS上设置防火墙,看到它是安装的一部分,这似乎是有道理的。
我的服务器上会有Nginx,FastCGI和MySQL。 我也想要允许SSH访问(显然)。 所以我很想知道我应该如何设置UFW,还有什么我需要考虑的? 经过研究,我发现了一篇文章 ,这样解释:
# turn on ufw ufw enable # log all activity (you'll be glad you have this later) ufw logging on # allow port 80 for tcp (web stuff) ufw allow 80/tcp # allow our ssh port ufw allow 5555 # deny everything else ufw default deny # open the ssh config file and edit the port number from 22 to 5555, ctrl-x to exit nano /etc/ssh/sshd_config # restart ssh (don't forget to ssh with port 5555, not 22 from now on) /etc/init.d/ssh reload
这一切似乎对我有意义。 但是这一切是正确的吗? 我想支持任何其他意见或build议,以确保我在我的服务器上做到这一点。
非常感谢!
使用ufw限制[PORT]而不是ufw允许[PORT],这样可以防止暴力攻击。
ufw supports connection rate limiting, which is useful for protecting against brute-force login attacks. ufw will deny connections if an IP address has attempted to initiate 6 or more connections in the last 30 seconds.
以下是我将如何使用您的规则设置防火墙。
首先在/ etc / ssh / sshd_config中更改SSH端口
然后重新加载configuration:/etc/init.d/ssh重新加载
然后:ufw默认拒绝
然后:ufwlogin
然后:ufw限制5555
然后:ufw允许80 / tcp
一旦你有所有的规则设置启用ufw:ufw启用
我会非常小心防火墙的SSH不知道你在做什么 – 这可能是值得尝试SSH SSH它closures一个特定的networking开始testing。 我不知道LFW有多快生效,或者它影响已build立的连接,但是如果它立即生效,那么在防火墙closures当前连接的防火墙之前,一定要更改SSH的端口号。