当前位置:网站首页>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
边栏推荐
- 企业级日志分析系统ELK
- 一个普通人除了去工厂上班赚钱,还能干什么工作?
- leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
- Shader_ Animation sequence frame
- SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术
- TS typescript type declaration special declaration field number is handled when the key key
- Bidding announcement: 2022 Yunnan Unicom gbase database maintenance public comparison and selection project (second) comparison and selection announcement
- Three. JS introductory learning notes 05: external model import -c4d into JSON file for web pages
- Regular expression string
- 95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
猜你喜欢

【花雕体验】15 尝试搭建Beetle ESP32 C3之Arduino开发环境
通知Notification使用全解析

Apache Doris刚“毕业”:为什么应关注这种SQL数据仓库?

AE learning 02: timeline

10 schemes to ensure interface data security

Continuous creation depends on it!

Enterprise log analysis system elk

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

Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"

企业级日志分析系统ELK
随机推荐
Particle effect for ugui
Vite path alias @ configuration
Iterator and for of.. loop
Introduction to pyGame games
Learn good-looking custom scroll bars in 1 minute
保证接口数据安全的10种方案
VS2005 strange breakpoint is invalid or member variable value cannot be viewed
招标公告:盘锦市人民医院盘锦医院数据库维保项目
山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
讲师征集令 | Apache SeaTunnel(Incubating) Meetup 分享嘉宾火热招募中!
20th anniversary of agile: a failed uprising
Enterprise log analysis system elk
The "go to definition" in VS2010 does not respond or prompts the solution of "symbol not found"
Use of SVN
持续创作,还得靠它!
无线传感器网络--ZigBee和6LoWPAN
融云斩获 2022 中国信创数字化办公门户卓越产品奖!
Mysql database backup script
121. 买卖股票的最佳时机
分步式监控平台zabbix