nftables提供了防火墙支持和NAT(网络地址转换)。Debian操作系统默认安装nftables防火墙。这篇快速入门指南列出了一些关于nftables的常用命令,以便系统管理员快速掌握nftables的使用方法。
安装nftables:
# aptitude install nftables
启用nftables:
# systemctl enable nftables.service
列出当前规则:
# nft list ruleset
删除全部规则:
# nft flush ruleset
禁用nftables:
# systemctl mask nftables.service
卸载nftables:
# aptitude purge nftables
允许SSH、HTTP、HTTPS和ICMP,禁止其他流入流量。修改/etc/nftables.conf内容如下:
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
# accept any localhost traffic
iif lo accept
# accept traffic originated from us
ct state established,related accept
# drop invalid packets
ct state invalid counter drop
# accept ssh, http, and https
tcp dport { 22, 80, 443 } accept
# accept icmp
ip protocol icmp accept
# count and reject everything else
counter reject with icmpx type admin-prohibited
}
chain forward {
type filter hook forward priority 0; policy drop;
}
chain output {
type filter hook output priority 0; policy accept;
}
}
更多信息可参考nftables官方文档。