当前位置:网站首页>iptables初探
iptables初探
2022-04-23 18:29:00 【喝醉酒的小白】
一、概念
iptables是Linux下功能强大的防火墙工具,由于它集成于Linux内核,所以效率极高。
二、分类
按照对数据包的操作类别分类,iptables可以分为4个表,按照不同的Hook点可区分为5个链。
其中4个表分别是filter表(用于一般的过滤)、nat表(地址或端口映射)、mangle表(对特定数据包的修改)、raw表,这里面最常用的是filter表;
5个链分别是PREROUTING链(数据包进入路由决策之前)、INPUT(路由决策为本机的数据包)、FORWARD(路由决策不是本机的数据包)、OUTPUT(由本机产生的向外发送的数据包)、POSTROUTING(发送给网卡之前的数据包),最常用的是INPUT、OUTPUT链。
三、工作策略
第一种是仅接受允许的数据,这种策略一般是设置防火墙的默认策略为拒绝所有数据包(也就是拒绝网卡上出入的数据包),然后有针对性地放开特定的访问;第二种是只防止不允许的数据访问请求,这种策略一般是设置防火墙的默认策略为允许所有数据包,只拒绝已知的非法访问数据。从安全效果而言,前一种防火墙策略表现更为优秀/
四、配置规则
#cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT #允许已经建立和相关的数据包进入 / 代表目前已经与本机建立连接的主机,依然保持连接状态
-A INPUT -p icmp -j ACCEPT #在INPUT规则链中添加允许ICMP流量进入
-A INPUT -i lo -j ACCEPT
-A INPUT -i bond0 -s x.x.x.x -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT #允许固定的IP能SSH到该服务器上
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT #允许访问80端口
-A INPUT -s x.x.x.x -p tcp -m multiport --dports 80,10011,3000,6379,9307 -j ACCEPT #允许固定的IP能访问该服务器某些端口
-A INPUT -p tcp --dport 3000 -d 127.0.0.1 -j ACCEPT
-A INPUT -p tcp --dport 3000 -j DROP #DROP(丢弃)
-A OUTPUT -p tcp --sport 5900:5930 -j DROP
-A INPUT -j REJECT --reject-with icmp-host-prohibited #REJECT(拒绝)
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
五、直接配置并保存规则
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT #添加
iptables -D INPUT -p tcp -m tcp --dport 80 -j ACCEPT #清理
iptables -L #查看
保存
service iptables save
重启后永久生效
service iptables restart
六、参考链接
版权声明
本文为[喝醉酒的小白]所创,转载请带上原文链接,感谢
https://blog.csdn.net/hezuijiudexiaobai/article/details/124359382
边栏推荐
- 【ACM】376. 摆动序列
- Vulnérabilité d'exécution de la commande de fond du panneau de commande JD - freefuck
- 软件测试总结
- In shell programming, the shell file with relative path is referenced
- 纠结
- Nodejs installation
- Setting up keil environment of GD single chip microcomputer
- Gst-launch-1.0 usage notes
- Gobang game based on pyGame Library
- 线上怎么确定期货账户安全的?
猜你喜欢
机器学习理论之(8):模型集成 Ensemble Learning
Resolves the interface method that allows annotation requests to be written in postman
Setting up keil environment of GD single chip microcomputer
Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
硬核解析Promise对象(这七个必会的常用API和七个关键问题你都了解吗?)
With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
Gobang game based on pyGame Library
【ACM】376. 摆动序列
C medium? This form of
Nodejs安装
随机推荐
Halo open source project learning (VII): caching mechanism
Keil RVMDK compiled data type
Rewrite four functions such as StrCmp in C language
Reptile efficiency improvement method
CISSP certified daily knowledge points (April 15, 2022)
Nodejs installation
函数递归以及趣味问题的解决
Win1远程出现“这可能是由于credssp加密oracle修正”解决办法
Robocode tutorial 8 - advanced robot
Spark performance optimization guide
CISSP certified daily knowledge points (April 18, 2022)
Const keyword, variable and function are decorated with const
线上怎么确定期货账户安全的?
【ACM】376. 摆动序列
硬核解析Promise对象(这七个必会的常用API和七个关键问题你都了解吗?)
Stm32mp157 wm8960 audio driver debugging notes
WIN1 remote "this may be due to credssp encryption Oracle correction" solution
What are the relationships and differences between threads and processes
Using transmittablethreadlocal to realize parameter cross thread transmission
Daily CISSP certification common mistakes (April 19, 2022)