防火墙学习:iptables

添加链接描述

对应文章:
添加链接描述

添加链接描述

一.

  1. 现在常用的Linux网络防火墙就两种

     iptables  和  firewalld
    

二. iPtables

1.iPtables只是一个命令行工具,操作的底层软件是netfilter(位于Linux内核)

  1. iptables -L

  2. -L, --list [chain] 列出链 chain 上面的所有规则,如果没有指定链,列出表上所有链的所有规则。

三.

# 1、-s  源地址IP,多个逗号隔开(生成多条规则)
yunweixiaocai:~ # iptables -t filter -I INPUT -s 10.247.83.93,10.247.83.94 -j ACCEPT
yunweixiaocai:~ # iptables -L INPUT 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  10.247.83.94         anywhere            
ACCEPT     all  --  10.247.83.93         anywhere
# 可指定网段
yunweixiaocai:~ # iptables -t filter -I INPUT -s 10.247.83.0/24 -j ACCEPT 
yunweixiaocai:~ # iptables -L INPUT 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  10.247.83.0/24       anywhere
# !取反
yunweixiaocai:~ # iptables -t filter -I INPUT ! -s  10.247.83.0/24 -j ACCEPT 
yunweixiaocai:~ # iptables -L INPUT 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  -- !10.247.83.0/24       anywhere 

# 2、-d 目标IP地址,用法同-s
yunweixiaocai:~ # iptables -I INPUT ! -d 10.247.83.0/24 -j ACCEPT 
yunweixiaocai:~ # iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere            !10.247.83.0/24

# 3、-p 协议类型(tcp, udp, udplite, icmp, icmpv6,esp, ah, sctp, mh)
yunweixiaocai:~ # iptables -I INPUT -p tcp -j ACCEPT 
yunweixiaocai:~ # iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere 

# 4、-i 网卡接口
yunweixiaocai:~ # iptables -I INPUT -i eth0 -j ACCEPT        
yunweixiaocai:~ # iptables -vL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   53  4403 ACCEPT     all  --  eth0   any     anywhere             anywhere

target:代表进行的动作,ACCEPT 是放行,REJECT 是拒绝,DROP 则是丢弃数据包。
port:代表使用的协议,主要有 tcp、udp 和 icmp 三种。
opt:额外的选项说明。
source:规则针对的来源 IP。
destination:规则针对的目标 IP。
字段解释来源于: 添加链接描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值