
我想讓我的新網路伺服器上的防火牆盡可能安全。在研究了 iptables 之後,我發現了 UFW(簡單防火牆)。對我來說,這看起來是在 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
這一切對我來說似乎都很有意義。但這一切都是正確的嗎?我想用任何其他意見或建議來支援這一點,以確保我在我的伺服器上正確執行此操作。
非常感謝!
答案1
使用 ufw limit [PORT] 而不是 ufw allowed [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.
以下是我如何使用您的規則設定 ufw 防火牆。
首先更改 SSH 連接埠:/etc/ssh/sshd_config
然後重新載入配置:/etc/init.d/ssh reload
然後:ufw預設拒絕
然後:ufw 登入
然後:ufw限制5555
然後:ufw允許80/tcp
一旦你完成所有規則設置,啟用 ufw: ufw enable
答案2
在不確切知道你在做什麼的情況下,我會非常小心地關閉 SSH 防火牆 - 可能值得嘗試在某個網路上關閉 SSH 以進行測試。我不知道 LFW 生效的速度有多快,也不知道它是否會影響已建立的連接,但如果它立即生效,那麼您絕對應該在關閉目前用於連接的防火牆之前更改 SSH 連接埠號碼。