跳到主要内容

防火墙设置

UFW 是 Ubuntu 的默认防火墙,但是在 Debian 上没有默认安装。

ufw

  • 安装
apt-get update
apt-get install ufw
  • 开启防火墙
ufw enable
  • 放行指定端口

放行tcp或者udp端口:ufw allow 端口号/tcp 放行tcp与udp端口:ufw allow 端口号 删除指定端口:ufw delete allow 端口号

  • 重启防火墙
ufw reload

-查看防火墙现有规则

ufw status

ufw show added #查看刚添加的规则
  • 查看&关闭占用进程
ufw disable
  • 开启开机启动
ufw enable
  • 查看防火墙状态
ufw status verbose
  • 关闭防火墙
ufw disable
  • 重置防火墙配置
ufw reset

iptables

  • 安装
apt-get update
apt-get install iptables-persistent
  • 开启防火墙
service iptables start
  • 放行指定端口
iptables -A INPUT -p tcp --dport 端口号 -j ACCEPT
  • 重启防火墙
service iptables restart

-查看防火墙现有规则

iptables -L -n -v
  • 查看&关闭占用进程
kill -9 PID
#禁止开机启动
service iptables stop
  • 开启开机启动
service iptables save 
  • 查看防火墙状态
service iptables status
  • 关闭防火墙
service iptables stop

其他命令

  • 查看所有端口号
netstat -ntlp    #此命令如果无法运行请先安装:apt-get install net-tools -y
  • 查看指定端口是否被占用
lsof -i tcp:6666    #查看所有6666端口使用情况

netstat -ntulp |grep 6666 #查看所有6666端口使用情况,此命令也可以查出占用端口的进程