iptables 设置指定IP客户端访问服务器redis端口
2024-10-19 09:35:30
一、需求描述
服务器172.28.18.75开放了6379redis端口,由于没有设置登录密码,所以需要防火墙设置只能指定的IP地址172.28.5.125客户端访问redis端口
二、查看172.28.18.75的防火墙规则
[root@zabbix_server ~]# iptables -nvL
Chain INPUT (policy DROP packets, bytes)
pkts bytes target prot opt in out source destination
230K 23M ACCEPT all -- * * 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
ACCEPT icmp -- * * 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
Chain INPUT (policy DROP 2 packets, 104 bytes)默认规则是禁止,那么只需要添加允许访问IP的规则即可
三、添加规则:指定127.0.0.1的IP可以访问redis6379
[root@zabbix_server ~]# iptables -A INPUT -s 127.0.0.1 -p tcp --dport -j ACCEPT
在172.28.18.75上测试
[root@zabbix_server ~]# redis-cli
127.0.0.1:> get keys
(nil)
四、添加规则:指定172.28.5.125P可以访问172.28.18.75的redis6379
[root@zabbix_server ~]# iptables -A INPUT -s 172.28.5.125 -p tcp --dport -j ACCEPT
查看规则
[root@zabbix_server ~]# iptables -nvL
Chain INPUT (policy DROP packets, bytes)
pkts bytes target prot opt in out source destination
466K 46M ACCEPT all -- * * 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
ACCEPT icmp -- * * 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- * * 127.0.0.1 0.0.0.0/ tcp dpt:
ACCEPT tcp -- * * 172.28.5.125 0.0.0.0/ tcp dpt:
在172.28.5.125上测试
[root@redis- ~]# redis-cli -h 172.28.18.75
172.28.18.75:> get keys
(nil)
访问成功
五、添加规则:指定IP地址段172.28.146.1-172.28.146.252可以访问redis6379
[root@zabbix_server ~]# iptables -A INPUT -s 172.28.146.1/ -p tcp --dport -j ACCEPT
六、保存规则
[root@zabbix_server ~]# service iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:[确定]
七、重启服务
[root@zabbix_server ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则:[确定]
iptables:正在卸载模块:[确定]
iptables:应用防火墙规则:[确定]
最新文章
- js正则表达式大全(4)
- 使用SQLAlchemy
- 转:Java实现几种常见排序方法
- Linux查看CPU信息
- [css]兼容性
- hdu 4602 Partition(快速幂)
- CODEVS 1638 修复公路
- emacs search, 讲的很清楚。
- anndroid 模糊引导界面
- 不可不知的表达式树(1)Expression初探
- Codeforces.765F.Souvenirs(主席树)
- Rewrite JSON project with Fetch
- 安卓使用TextView实现图片加文字说明
- jdk6使用WebSocket
- codevs 1082 线段树练习3 (线段树)
- 019-centos的yum用法
- ubuntu 16.04 kinetic 安装rosbridge
- 使用django发送邮件时的连接超时问题解决
- iOS语音播报文字
- 面向对象(基础oop)之初识继承
热门文章
- wmic查询ip
- Xcode真机报错clang: error: linker command failed with exit code 1 (use -v to see invocation)
- C基础知识(1):基本数据类型
- PJzhang:关闭wps小广告和快速关闭445端口
- 【神经网络与深度学习】YOLO windows 配置《Darknet配置》
- 【Spring AOP】Spring AOP的使用方式【Q】
- Elasticsearch-日期类型
- (5.3)mysql高可用系列——mysql复制(理论篇)【续写中】
- 深入理解Java中的Clone与深拷贝和浅拷贝
- kaggle笔记