nftables是Linux内核中的新一代防火墙系统,可以通过简单的命令行配置进行管理。以下是在Ubuntu上安装和配置nftables的步骤:
安装nftables:在终端中运行以下命令来安装nftables:sudo apt updatesudo apt install nftables启动nftables服务:运行以下命令来启动nftables服务:sudo systemctl start nftables配置nftables规则:创建一个nftables配置文件,例如/etc/nftables.conf,并在其中定义防火墙规则。以下是一个简单的nftables配置示例:table inet filter { chain input { type filter hook input priority 0; policy drop; # Allow loopback interface iifname lo accept # Allow established and related connections ct state established,related accept # Allow incoming SSH connections tcp dport ssh accept # Drop all other incoming connections drop } chain forward { type filter hook forward priority 0; policy drop; } chain output { type filter hook output priority 0; policy accept; }}保存并退出配置文件后,使用以下命令加载配置文件并应用规则:
sudo nft -f /etc/nftables.conf保存配置:如果需要在系统重新启动后保留nftables配置,可以运行以下命令来保存当前配置:sudo nft list ruleset > /etc/nftables.conf这样就完成了在Ubuntu上安装和配置nftables的步骤。可以根据具体需求修改nftables配置文件以实现更复杂的防火墙规则。


