对应文章:
添加链接描述
一.
-
现在常用的Linux网络防火墙就两种
iptables 和 firewalld
二. iPtables
1.iPtables只是一个命令行工具,操作的底层软件是netfilter(位于Linux内核)
-
iptables -L
-
-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。
字段解释来源于: 添加链接描述