今天主要是討論到對於 OS 而言我們可以如何限制外部的訪問,除了前面提到的密碼以及 sudoer 以外,
在網路層面也可以做限制
最常用的是透過 linux 中的 iptable 對 user 進行限制
# 查看所有規則
iptables -L
# 查看規則並顯示行號
iptables -L --line-numbers
# 查看 NAT 表
iptables -t nat -L
# 查看詳細資訊
iptables -L -v -n
# 情境:只允許特定 Pod CIDR 存取
iptables -A INPUT -s 10.244.0.0/16 -j ACCEPT
iptables -A INPUT -j DROP
# 情境:限制對外連線
iptables -A OUTPUT -d 169.254.169.254 -j DROP # 阻擋 metadata service
UFW (Uncomplicated Firewall) 實際上是 iptables 的前端工具,底層還是使用 iptables,不同的點是提供更簡化的語法。
apt-get update
apt-get install ufw
systemctl start ufw
ufw status
ufw default allow outgoing
ufw default deny incoming
ufw allow from 1.2.3.4 to any port 22 proto tcp
ufw allow from 1.2.3.4 to any port 80 proto tcp
ufw enable
ufw deny 8080
ufw deny 5
參考資料
https://linux.vbird.org/linux_server/centos6/0250simple_firewall.php