当前位置:网站首页>iptables只允许指定ip地址访问指定端口
iptables只允许指定ip地址访问指定端口
2022-07-07 14:01:00 【格格巫 MMQ!!】
首先,清除所有预设置
iptables -F#清除预设表filter中的所有规则链的规则 iptables -X#清除预设表filter中使用者自定链中的规则
1.
其次,设置只允许指定ip地址访问指定端口
iptables -A INPUT -s xxx.xxx.xxx.xxx -p tcp --dport 22 -j ACCEPT iptables -A OUTPUT -d xxx.xxx.xxx.xxx -p tcp --sport 22 -j ACCEPT iptables -A INPUT -s xxx.xxx.xxx.xxx -p tcp --dport 3306 -j ACCEPT iptables -A OUTPUT -d xxx.xxx.xxx.xxx -p tcp --sport 3306 -j ACCEPT
1.
上面这两条,请注意–dport为目标端口,当数据从外部进入服务器为目标端口;反之,数据从服务器出去则为数据源端口,使用 --sport
同理,-s是指定源地址,-d是指定目标地址。
然后,关闭所有的端口
iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -P FORWARD DROP
1.
最后,保存当前规则
/etc/rc.d/init.d/iptables save service iptables restart
1.
这种iptables的规则设定适用于只充当MySQL服务器的管理和维护,外部地址不提供任何服务。
如果你希望yum可以运行的话,还需要添加以下内容,允许DNS请求的53端口,允许下载随机产生的高端口
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -p udp --s
以开放8080端口为例:
方式一:
登录后复制
1、开启防火墙
systemctl start firewalld
2、开放指定端口
firewall-cmd --zone=public --add-port=1935/tcp --permanent
命令含义:
–zone #作用域
–add-port=1935/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
3、重启防火墙
firewall-cmd --reload
4、查看端口号
netstat -ntlp //查看当前所有tcp端口·
netstat -ntulp |grep 8080 //查看所有8080端口使用情况
方式二:
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
方式三:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
service iptables restart
边栏推荐
- L'application à l'échelle de la normalisation mature des produits ai des compagnies maritimes, cimc, leader mondial de l'intelligence artificielle portuaire et maritime / intelligence artificielle des
- numpy---基础学习笔记
- 无线传感器网络--ZigBee和6LoWPAN
- 招标公告:盘锦市人民医院盘锦医院数据库维保项目
- VS2005 strange breakpoint is invalid or member variable value cannot be viewed
- Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
- 神经网络c语言中的指针是怎么回事
- 航天宏图信息中标乌鲁木齐某单位数据库系统研发项目
- Three. JS introductory learning notes 03: perspective projection camera
- C4D learning notes 2- animation - timeline and time function
猜你喜欢

星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”

深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)

torch.numel作用

What about the pointer in neural network C language
通知Notification使用全解析

Whole process analysis of unity3d rendering pipeline

AB package details in unity (super detail, features, packaging, loading, manager)

Mesh merging under ue4/ue5 runtime

Streaming end, server end, player end

Three. JS introductory learning notes 15: threejs frame animation module
随机推荐
MySQL数据库基本操作-DQL-基本查询
Particle effect for ugui
There are many ways to realize the pause function in JS
通知Notification使用全解析
Three. JS introductory learning notes 05: external model import -c4d into JSON file for web pages
应用程序和matlab的通信方式
Use of SVN
C4D learning notes 2- animation - timeline and time function
神经网络c语言中的指针是怎么回事
20th anniversary of agile: a failed uprising
Shader Language
How does geojson data merge the boundaries of regions?
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
Three. JS introduction learning notes 12: the model moves along any trajectory line
torch.numel作用
Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform
2022第四届中国(济南)国际智慧养老产业展览会,山东老博会
hellogolang
讲师征集令 | Apache SeaTunnel(Incubating) Meetup 分享嘉宾火热招募中!
The "go to definition" in VS2010 does not respond or prompts the solution of "symbol not found"