当前位置:网站首页>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
边栏推荐
- 2022山东智慧养老展,适老穿戴设备展,养老展,山东老博会
- Postman generate timestamp, future timestamp
- 持续创作,还得靠它!
- XMIND frame drawing tool
- Three. JS introductory learning notes 15: threejs frame animation module
- Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
- Mysql database basic operation DQL basic query
- asyncio 概念和用法
- Numpy -- epidemic data analysis case
- Asynchronous application of generator function
猜你喜欢

融云斩获 2022 中国信创数字化办公门户卓越产品奖!

Use of SVN

Three. JS introductory learning notes 19: how to import FBX static model
![[flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3](/img/8f/ca9ab042916f68de7994d9f2124da9.jpg)
[flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3

C4D learning notes 2- animation - timeline and time function

Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation

Unity3D_ Class fishing project, bullet rebound effect is achieved

TS as a general cache method

SPI master RX time out interrupt

LeetCode2_ Add two numbers
随机推荐
The unity vector rotates at a point
Introduction to pyGame games
numpy--数据清洗
深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
There are many ways to realize the pause function in JS
Migration and reprint
无线传感器网络--ZigBee和6LoWPAN
Limit of total fields [1000] in index has been exceeded
asyncio 概念和用法
持续创作,还得靠它!
C Alibaba cloud OSS file upload, download and other operations (unity is available)
LeetCode2_ Add two numbers
通知Notification使用全解析
Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
torch.numel作用
Numpy -- epidemic data analysis case
A wave of open source notebooks is coming
Spin animation of Cocos performance optimization
The "go to definition" in VS2010 does not respond or prompts the solution of "symbol not found"
Eye of depth (VII) -- Elementary Transformation of matrix (attachment: explanation of some mathematical models)