当前位置:网站首页>iptables基础及Samba配置举例
iptables基础及Samba配置举例
2022-07-04 12:34:00 【星哥玩云】
- iptable基本概念
- Iptables表链规则
- iptables传输数据包的过程
- iptables命令格式
- iptables常用选项OPTIONS解释
- 常用命令COMMANDS解释
- 常用参数PARAMETERS解释
- 使用MATCH EXTENSIONS扩展模块
- 其他
- 举例搭建samba服务器
iptable基本概念
iptables防火墙包含两部分,即位于用户空间的iptables模块和位于内核空间netfilter模块。用户空间模块提供插入、修改和除去包过滤表中规则,内核模块进行实际的过滤,所以更准确的名称应该是 iptables/netfilter。
- 表(tables):提供特定的功能,iptables内置了4个表,即filter表、nat表、mangle表和raw表,分别用于实现包过滤,网络地址转换、包重构(修改)和数据跟踪处理。
- 规则(rules):其实就是网络管理员预定义的条件。
- 链(chains):是数据包传播的路径,每一条链其实就是众多规则中的一个检查清单,每一条链中可以有一条或数条规则。当一个数据包到达一个链时,iptables就会从链中第一条规则开始检查,看该数据包是否满足规则所定义的条件。共5个链,即INPUT、OUTPUT、FORWARD、PREROUTING和POSTROUTING。
Iptables表、链、规则:
iptables传输数据包的过程
iptables命令格式
iptables常用选项OPTIONS解释
常用命令COMMANDS解释:
- -A, –append chain:增加一条规则到链的末端
- -D, –delete chain: 删除一条规则
- -I, –insert chain [rulenum]:以给定的rule编号,在选定的链上插入规则
- -R, –replace chain rulenum:替换某条规则
- -L, –list [chain]:查看指定表和指定链的规则列表
- -F, –flush [chain]:删除[指定]表中所有规则
常用参数PARAMETERS解释:
- -p 协议类型:可以指定规则应用的协议,即TCP、UDP和ICMP等
- -s 源地址:地址可以是hostname,也可以是IP等
- -d 目标IP地址
- -j 动作
- –line-numbers:和-L一起使用,显示规则的rulenum编号
- -n:以数字形式输出IP地址和端口
使用MATCH EXTENSIONS扩展模块
- -m, –match module_name: 启用扩展模块,如state、tcp 、udp、multiport 、string 、addrtype 、mac 等
- iptables -m module_name -h: 查看扩展模块的帮助信息;如:
iptables -m mac -h
其他
- 假如没有 -t 选项,则默认的table为filter表
- 默认的保存在/etc/sysconfig/iptables文件中
- service iptables save:保存更改的iptables
举例搭建samba服务器
配置samba服务器
修改/etc/samba/smb.conf
文件,首先添加要共享的目录:
[workspace] writable = yes path = /root/
如果打算使符号链接也可以访问,则在smb.conf的[global] 部分,添加如下配置:
follow symlinks = yes wide links = yes unix extensions = no
添加samba账户
smbpasswd -a smbpasswd -e
关闭SELinux防火墙
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config # setenforce 0 # reboot
配置iptables
首先查看当前的规则:
[[email protected] ~]# iptables -L --line-number Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- anywhere anywhere 2 ACCEPT icmp -- anywhere anywhere 3 ACCEPT tcp -- anywhere anywhere tcp dpt:ssh 4 ACCEPT tcp -- anywhere anywhere tcp dpt:http 5 ACCEPT tcp -- anywhere anywhere tcp dpt:https 6 ACCEPT udp -- anywhere anywhere udp dpt:bootpc 7 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED 8 DROP all -- anywhere anywhere
添加规则以启用samba所使用的端口
经查看,要添加到8号规则的前面,否则samba不起作用:
iptables -I INPUT 8 -p udp -m multiport --dport 137,138 -j ACCEPT iptables -I INPUT 8 -p tcp -m state --state NEW -m multiport --dport 139,445 -j ACCEPT
查看添加的规则
[[email protected] ~]# iptables -L --line-number -n Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 6 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:68 7 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 8 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW multiport dports 139,445 9 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 multiport dports 137,138 10 DROP all -- 0.0.0.0/0 0.0.0.0/0
保存当前规则并启用samba:
#保存规则 service iptables save #启用smb: service smb restart #使smb随机器启动 chkconfig smb on
也可以使用iptables -F
完全删除规则
边栏推荐
- Paper notes ACL 2020 improving event detection via open domain trigger knowledge
- Peak detection of measured signal
- Fastlane one click package / release app - usage record and stepping on pit
- AI 绘画极简教程
- C language: find the palindrome number whose 100-999 is a multiple of 7
- Global and Chinese markets of NOx analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- runc hang 导致 Kubernetes 节点 NotReady
- Will the concept of "being integrated" become a new inflection point of the information and innovation industry?
- R语言--readr包读写数据
- Global and Chinese markets for soluble suture 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
vim 出现 Another program may be editing the same file. If this is the case 的解决方法
Master the use of auto analyze in data warehouse
PostgreSQL 9.1 飞升之路
8个扩展子包!RecBole推出2.0!
昨天的事情想说一下
Full arrangement (medium difficulty)
ArgMiner:一个用于对论点挖掘数据集进行处理、增强、训练和推理的 PyTorch 的包
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
Understand bloomfilter in one article
Paper notes ACL 2020 improving event detection via open domain trigger knowledge
随机推荐
Alibaba cloud award winning experience: build a highly available system with polardb-x
MDK在头文件中使用预编译器时,#ifdef 无效的问题
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
golang 设置goproxy代理的小细节,适用于go module下载超时,阿里云镜像go module下载超时
[Android kotlin] lambda return statement and anonymous function
C语言函数
eclipse链接数据库中测试SQL语句删除出现SQL语句语法错误
Why can the implementation class of abstractdispatcherservletinitializer be called when initializing the web container
Backgroundworker usage example
Transformer principle and code elaboration (tensorflow)
AI painting minimalist tutorial
ArcGis利用栅格处理工具进行影像裁剪
Fundamentals of container technology
Dry goods sorting! How about the development trend of ERP in the manufacturing industry? It's enough to read this article
BackgroundWorker用法示例
敏捷开发/敏捷测试感受
A treasure open source software, cross platform terminal artifact tabby
C语言:求100-999是7的倍数的回文数
C语言:求字符串的长度
DC-5 target