linux开启防火墙

https://www.dafeiyu.cn/f/article/9.html
https://www.centos.bz/2018/01/iptables%E6%9F%A5%E7%9C%8B%E3%80%81%E5%BC%80%E6%94%BE%E3%80%81%E5%88%A0%E9%99%A4%E7%AB%AF%E5%8F%A3%E3%80%81%E4%BF%9D%E5%AD%98%E8%AE%BE%E7%BD%AE/

ip addr show | grep ‘inet’  #查看指定网卡信息
1、查看firewall服务状态
systemctl status firewalld

2、查看firewall的状态
firewall-cmd --state


# 开启

service firewalld start

# 重启
service firewalld restart

# 关闭
service firewalld stop

开启防火墙访问端口
添加 端口号
firewall-cmd --zone=public --add-port=9001/tcp --permanent

查看所有打开的端口: firewall-cmd --zone=public --list-ports

更新防火墙规则: firewall-cmd --reload

iptable规则
iptables -L -n -v

iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT               #允许本地回环接口(即运行本机访问本机)
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT    #允许已建立的或相关连的通行
iptables -A OUTPUT -j ACCEPT         #允许所有本机向外的访问
iptables -A INPUT -p tcp --dport 22 -j ACCEPT    #允许访问22端口
iptables -A INPUT -p tcp --dport 80 -j ACCEPT    #允许访问80端口
iptables -A INPUT -p tcp --dport 21 -j ACCEPT    #允许ftp服务的21端口
iptables -A INPUT -p tcp --dport 20 -j ACCEPT    #允许FTP服务的20端口
iptables -A INPUT -j reject       #禁止其他未允许的规则访问
iptables -A FORWARD -j REJECT     #禁止其他未允许的规则访问

删除

将所有iptables以序号标记显示,执行:
# iptables -L -n --line-numbers

比如要删除INPUT里序号为2的规则,执行:
# iptables -D INPUT 2

屏蔽ip

# iptables -I INPUT -s 123.45.6.7 -j DROP       #屏蔽单个IP的命令
# iptables -I INPUT -s 123.0.0.0/8 -j DROP      #封整个段即从123.0.0.1123.255.255.254的命令
# iptables -I INPUT -s 124.45.0.0/16 -j DROP    #封IP段即从123.45.0.1123.45.255.254的命令
# iptables -I INPUT -s 123.45.6.0/24 -j DROP    #封IP段即从123.45.6.1123.45.6.254的命令是
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值