当前位置:网站首页>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
边栏推荐
- Odoo集成Plausible埋码监控平台
- Three. JS introductory learning notes 10:three JS grid
- AB package details in unity (super detail, features, packaging, loading, manager)
- 神经网络c语言中的指针是怎么回事
- AE learning 02: timeline
- nodejs package. JSON version number ^ and~
- C4D learning notes 3- animation - animation rendering process case
- When opening the system window under UE4 shipping, the problem of crash is attached with the plug-in download address
- A JS script can be directly put into the browser to perform operations
- LeetCode2_ Add two numbers
猜你喜欢

20th anniversary of agile: a failed uprising

无线传感器网络--ZigBee和6LoWPAN

Streaming end, server end, player end
![Unity drawing plug-in = = [support the update of the original atlas]](/img/b0/92114ffb1f168a1f27125db46c6797.jpg)
Unity drawing plug-in = = [support the update of the original atlas]

Syntax of generator function (state machine)

神经网络c语言中的指针是怎么回事

Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
通知Notification使用全解析

Use of SVN

融云斩获 2022 中国信创数字化办公门户卓越产品奖!
随机推荐
统计学习方法——感知机
Notification uses full resolution
LeetCode3_ Longest substring without duplicate characters
融云斩获 2022 中国信创数字化办公门户卓越产品奖!
Three. JS introductory learning notes 13: animation learning
通知Notification使用全解析
山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
After UE4 is packaged, mesh has no material problem
Asynchronous application of generator function
121. The best time to buy and sell stocks
Virtual memory, physical memory /ram what
Postman generate timestamp, future timestamp
js中复选框checkbox如何判定为被选中
Three. JS introductory learning notes 18: how to export JSON files with Blender
When opening the system window under UE4 shipping, the problem of crash is attached with the plug-in download address
Spin animation of Cocos performance optimization
Async and await
讲师征集令 | Apache SeaTunnel(Incubating) Meetup 分享嘉宾火热招募中!
[flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题