您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
在 Linux 虚拟机中设置防火墙规则,通常需要使用 iptables
或 ufw
(Uncomplicated Firewall)这样的工具。以下是使用这两个工具的步骤:
安装 ufw(如果尚未安装):
sudo apt update
sudo apt install ufw
启用 ufw:
sudo ufw enable
查看当前的 ufw 状态:
sudo ufw status
添加防火墙规则:
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw deny from 192.168.1.100
删除防火墙规则:
sudo ufw delete allow ssh
删除所有规则并关闭 ufw:
sudo ufw disable
查看当前的 iptables 规则:
sudo iptables -L -v -n
添加防火墙规则:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
保存 iptables 规则(以便重启后仍然有效):
sudo apt install iptables-persistent
sudo netfilter-persistent save
删除防火墙规则:
sudo iptables -D INPUT -p tcp --dport 22 -j ACCEPT
删除所有规则并关闭 iptables(不推荐):
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -t nat -F
sudo iptables -t mangle -F
sudo iptables -F
sudo iptables -X
通过以上步骤,你可以在 Linux 虚拟机中设置和管理防火墙规则。根据你的具体需求选择合适的工具和方法。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。