iptables添加IP访问限制和防火墙

临时封锁

iptables -D INPUT -s 115.205.205.104 -j DROP

iptables -I INPUT -s 115.205.205.104 -j DROP

查看哪些端口已经开放

vim /etc/sysconfig/iptables

服务器重启也不会消失的做法

vim /etc/sysconfig/iptables

-A INPUT -s 115.205.205.104/32 -j DROP

-A 添加在指定链表尾部 -I添加在指定链表前面

iptables添加规则

CentOS7的iptables保存问题

因为service iptables save错误,缺少了iptables 服务

  • systemctl stop firewalld
  • yum install iptables-services
  • systemctl enable iptables
  • systemctl start iptables
  • service iptables save
  • 此时在/etc/sysconfig文件夹下就有了iptables文件
  • systemctl start firewalld

防火墙命令

1
2
3
4
启动: systemctl start firewalld
查看状态: systemctl status firewalld
停止: systemctl disable firewalld
禁用: systemctl stop firewalld

开启防火墙之后端口无法访问

  • firewall-cmd --list-ports 防火墙开放的端口
  • firewall-cmd --zone=public --add-port=80/tcp --permanent 开放80端口
  • systemctl reload firewalld

docker启动报错 (iptables failed: iptables –wait -t nat -A DOCKER -p tcp -d 0/0 –dport

重启Docker

systemctl restart docker

赏个🍗吧
0%