网站建站网站多少钱,wordpress怎么做的,罗定网站建设,景观小品设计网站推荐Iptables教程 1. iptables防火墙简介 Iptables也叫netfilter是Linux下自带的一款免费且优秀的基于包过滤的防火墙工具#xff0c;它的功能十分强大#xff0c;使用非常灵活#xff0c;可以对流入、流出、流经服务器的数据包进行精细的控制。iptables是Linux2.4及2.6内核中…
Iptables教程 1. iptables防火墙简介 Iptables也叫netfilter是Linux下自带的一款免费且优秀的基于包过滤的防火墙工具它的功能十分强大使用非常灵活可以对流入、流出、流经服务器的数据包进行精细的控制。iptables是Linux2.4及2.6内核中集成的模块。 2. Iptables服务相关命令 1.查看iptables状态 service iptables status 2.开启/关闭iptables service iptables start service iptables stop 3.查看iptables是否开机启动 chkconfig iptables –list 4.设置iptables开机启动/不启动 chkconfig iptables on chkconfig iptables off 3. iptables原理简介 3.1. iptables的结构 在iptables中有四张表分别是filter、nat、mangle和raw每一个表中都包含了各自不同的链最常用的是filter表。 filter表 filter是iptables默认使用的表负责对流入、流出本机的数据包进行过滤该表中定义了3个链 INPOUT 负责过滤所有目标地址是本机地址的数据包就是过滤进入主机的数据包。 FORWARD 负责转发流经本机但不进入本机的数据包起到转发的作用。 OUTPUT 负责处理所有源地址是本机地址的数据包就是处理从主机发出去的数据包。 #查看帮助
iptables -h
man iptables列出iptables规则
iptables -L -n
列出iptables规则并显示规则编号
iptables -L -n --line-numbers列出iptables nat表规则默认是filter表
iptables -L -n -t nat清除默认规则注意默认是filter表如果对nat表操作要加-t nat
#清楚所有规则
iptables -F #重启iptables发现规则依然存在因为没有保存
service iptables restart#保存配置
service iptables save#禁止ssh登陆若果服务器在机房一定要小心
iptables -A INPUT -p tcp --dport 22 -j DROP//静止22端口被访问
#删除规则
iptables -D INPUT -p tcp --dport 22 -j DROP-A, --append chain 追加到规则的最后一条
-D, --delete chain [rulenum] Delete rule rulenum (1 first) from chain 删除
-I, --insert chain [rulenum] Insert in chain as rulenum (default 1first) 添加到规则的第一条
-p, --proto proto protocol: by number or name, eg. tcp,常用协议有tcp、udp、icmp、all
-j, --jump target 常见的行为有ACCEPT、DROP和REJECT三种但一般不用REJECT会带来安全隐患注意INPUT和DROP这样的关键字需要大写#禁止192.168.33.0网段从eth0网卡接入
iptables -A INPUT -p tcp -i eth0 -s 192.168.33.0 -j DROP
iptables -A INPUT -p tcp --dport 22 -i eth0 -s 192.168.33.61 -j ACCEPT#禁止ip地址非192.168.10.10的所有类型数据接入
iptables -A INPUT ! -s 192.168.10.10 -j DROP#禁止ip地址非192.168.10.10的ping请求
iptables -I INPUT -p icmp --icmp-type 8 -s 192.168.50.100 -j DROP#扩展匹配1.隐式扩展 2.显示扩展#隐式扩展-p tcp--sport PORT 源端口--dport PORT 目标端口#显示扩展使用额外的匹配规则-m EXTENSTION --SUB-OPT-p tcp --dport 22 与 -p tcp -m tcp --dport 22功能相同state状态扩展接口ip_contrack追踪会话状态NEW新的连接请求ESTABLISHED已建立的连接请求INVALID非法连接RELATED相关联的连接#匹配端口范围
iptables -I INPUT -p tcp --dport 22:80 -j DROP#匹配多个端口
iptables -I INPUT -p tcp -m multiport --dport 22,80,3306 -j ACCEPT#不允许源端口为80的数据流出
iptables -I OUTPUT -p tcp --sport 80 -j DROP%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%