当前位置:网站首页>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
边栏推荐
- From source code to executable file
- Log4j2 cross thread print traceid
- CISSP certified daily knowledge points (April 11, 2022)
- Robocode tutorial 3 - Robo machine analysis
- Daily network security certification test questions (April 14, 2022)
- Cutting permission of logrotate file
- 串口调试工具cutecom和minicom
- 机器学习理论之(8):模型集成 Ensemble Learning
- QT error: no matching member function for call to ‘connect‘
- Installation du docker redis
猜你喜欢
C medium? This form of
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
How to restore MySQL database after win10 system is reinstalled (mysql-8.0.26-winx64. Zip)
Promote QT default control to custom control
Qt读写XML文件(含源码+注释)
Robocode tutorial 5 - enemy class
Quantexa CDI(场景决策智能)Syneo平台介绍
CANopen STM32 transplantation
Creation and use of QT dynamic link library
【ACM】70. 爬楼梯
随机推荐
Daily CISSP certification common mistakes (April 18, 2022)
From source code to executable file
ESP32 LVGL8. 1 - event (event 17)
SQL database syntax learning notes
Gson fastjason Jackson of object to JSON difference modifies the field name
C language to achieve 2048 small game direction merging logic
Cygwin64 right click to add menu, and open cygwin64 here
使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
ESP32 LVGL8. 1 - anim animation (anim 16)
QT notes on qmap container freeing memory
Deep learning classic network analysis and target detection (I): r-cnn
CISSP certified daily knowledge points (April 14, 2022)
Install the yapiupload plug-in in idea and upload the API interface to the Yapi document
What are the relationships and differences between threads and processes
深度学习经典网络解析目标检测篇(一):R-CNN
函数递归以及趣味问题的解决
C language simulates entering and leaving the stack, first in first out, first in first out, shared memory
Realization of consumer gray scale
JD-FreeFuck 京东薅羊毛控制面板 后台命令执行漏洞
Rust: the output information of println is displayed during the unit test