iptables 设置特定IP访问指定端口
一、添加规则:设置禁止所有IP访问指定端口8075
[root@zabbix_server ~]# iptables -I INPUT -p tcp --dport -j DROP
二、测试telnet
[root@zabbix_server ~]# telnet 127.0.0.1
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection timed out
三、删除规则:
1、查询规则编号
[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP packets, bytes)
num pkts bytes target prot opt in out source destination
DROP tcp -- * * 0.0.0.0/ 0.0.0.0/ tcp dpt:
144M 15G ACCEPT all -- * * 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
214K ACCEPT icmp -- * * 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
218K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
1169K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
264K 14M ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
443K 23M ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
4093K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
可以看到禁止访问8075的规则编号为1
2、删除指定规则编号的规则
[root@zabbix_server ~]# iptables -D INPUT
再查询
[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP packets, bytes)
num pkts bytes target prot opt in out source destination
144M 15G ACCEPT all -- * * 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
214K ACCEPT icmp -- * * 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
218K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
1169K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
264K 14M ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
443K 23M ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
4094K 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 dp
已经删除了,测试telnet
[root@zabbix_server ~]# telnet 127.0.0.1
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
四、设置指定IP访问指定端口8075
1、添加规则:禁止所有IP访问8075
[root@zabbix_server ~]# iptables -I INPUT -p tcp --dport -j DROP
[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP packets, bytes)
num pkts bytes target prot opt in out source destination
DROP tcp -- * * 0.0.0.0/ 0.0.0.0/ tcp dpt:
145M 15G ACCEPT all -- * * 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
214K ACCEPT icmp -- * * 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
219K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
1169K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
264K 14M ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
443K 23M ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
4095K 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 dp
2、添加规则:允许127.0.0.1访问8075
[root@zabbix_server ~]# iptables -I INPUT -s 127.0.0.1 -p tcp --dport -j ACCEPT
3、查询规则:
[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP packets, bytes)
num pkts bytes target prot opt in out source destination
ACCEPT tcp -- * * 127.0.0.1 0.0.0.0/ tcp dpt:
DROP tcp -- * * 0.0.0.0/ 0.0.0.0/ tcp dpt:
145M 15G ACCEPT all -- * * 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
214K ACCEPT icmp -- * * 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
219K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
1170K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
264K 14M ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
443K 23M ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
规则已经添加,测试
[root@zabbix_server ~]# telnet 127.0.0.1
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
本机可以访问8075,其他机器上不能访问8075
[root@localhost etc]# telnet 172.28.18.75 8075
Trying 172.28.18.75...
telnet: connect to address 172.28.18.75: Connection timed out
4、允许172.28.18.71可以访问8075,(172.28.18.71是需要访问8075的服务器)
[root@zabbix_server ~]# iptables -I INPUT -s 172.28.18.71 -p tcp --dport -j ACCEPT
查看规则
[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP packets, bytes)
num pkts bytes target prot opt in out source destination
ACCEPT tcp -- * * 172.28.18.71 0.0.0.0/ tcp dpt:
ACCEPT tcp -- * * 127.0.0.1 0.0.0.0/ tcp dpt:
DROP tcp -- * * 0.0.0.0/ 0.0.0.0/ tcp dpt:
145M 15G ACCEPT all -- * * 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
214K ACCEPT icmp -- * * 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
219K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
1171K ACCEPT tcp -- * * 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
在172.28.18.71上测试telnet 8075
[root@localhost etc]# telnet 172.28.18.75
Trying 172.28.18.75...
Connected to 172.28.18.75.
Escape character is '^]'.
访问成功,保存规则
[root@zabbix_server ~]# service iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:[确定]
重启服务
[root@zabbix_server ~]# service iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:[确定]
[root@zabbix_server ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则:[确定]
iptables:正在卸载模块:[确定]
iptables:应用防火墙规则:[确定]
iptables 设置特定IP访问指定端口的更多相关文章
- linux禁止特定ip访问某个端口
linux禁止特定ip访问某个端口 解决方法: 禁止特定ip访问8501端口的命令0:iptables -I INPUT -s 192.168.0.232 -ptcp --dport 8501 - ...
- 只允许指定IP访问指定端口 ufw
那天工作需要在服务器上指定ip才可以访问指定端口,配置命令如下: (服务器是ubuntu 14.04系统) apt-get install ufw ufw enable ufw default den ...
- windows防火墙安全设置指定ip访问指定端口
场景摘要: 1.我有三台腾讯云服务器 2.我日常办公网络的ip换了 3.我在腾讯云上面改了安全规则,也不能访问我A服务器的21,1433等端口 4.开始我以为是办公网络的安全设置问题 5.我进B服务器 ...
- linux下通过iptables只允许指定ip地址访问指定端口的设置方法
这篇文章主要介绍了linux下通过iptables只允许指定ip地址访问指定端口的设置方法,需要的朋友可以参考下. 首先,清除所有预设置 iptables -F#清除预设表filter中的所有规则链的 ...
- iptables只允许指定ip地址访问指定端口
首先,清除所有预设置 iptables -F#清除预设表filter中的所有规则链的规则 iptables -X#清除预设表filter中使用者自定链中的规则 其次,设置只允许指定ip地址访问指定端口 ...
- iptables 防火墙 只允许某IP访问某端口、访问特定网站
iptables 防火墙 只允许某IP访问某端口.访问特定网站 1.先备份iptables /var/tmp 需要开80端口,指定IP和局域网 下面三行的意思: 先关闭所有的80端口 开启ip段192 ...
- iptables/mysql设置指定主机访问指定端口
本周,运维告知部署的服务被扫描发现漏洞,涉及的软件分别为mysql,ZooKeeper与Elasticsearch. 因为最近任务繁重,人力资源紧张,因此无法抽出更多时间调整代码,添加权限认证. 与软 ...
- Apache中限制和允许特定IP访问
Apache中限制和允许特定IP访问<Directory "/var/www">Options AllAllowOverride NoneOrder Deny,Allo ...
- 网络基础 图解Windows系统下单网卡设置双IP访问不同网段的方法
图解Windows系统下单网卡设置双IP访问不同网段的方法 by:授客 QQ:1033553122 在Windows系统下即使只有一块网卡,同样可以实现双IP访问不同网段. 例: 外网信息: IP:1 ...
随机推荐
- Access denied for user XX
解决方法:将pom.xml中的mysql-connector-java降低版本(直接去maven仓库复制:https://mvnrepository.com/),比如: <!-- https:/ ...
- Python进阶学习之特殊方法实例详析
Python进阶学习之特殊方法实例详析 最近在学习python,学习到了一个之前没接触过的--特殊方法. 什么是特殊方法?当我们在设计一个类的时候,python中有一个用于初始化的方法$__init_ ...
- 【.NET】无法加载协定为“ServiceReference1.ReportWsSoap”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分。
前言 引用websevice时,有时会出现如下错误: 异常详细信息: System.InvalidOperationException: 无法加载协定为“ServiceReference1.Repor ...
- 对于MVVM的理解
MVVM 是Model-View-ViewModel的缩写. Model 代表数据模型,也可以在model中定义数据修改和操作的业务逻辑. View 代表UI组件,负责姜黄素局模型转化成UI展现出来. ...
- 常见IE6兼容问题总结
1.<!DOCTYPE HTML>文档类型的声明. 产生条件:IE6浏览器,当我们没有书写这个文档声明的时候,会触发IE6浏览器的怪异解析现象: 解决办法:书写文档声明. 2.不同浏览器当 ...
- Django的一些注意事项
不要使用 Python 或 Django 的组件名命名项目.具体而言,不要使用“django”(与 Django 冲 突)或“test”(与 Python 内置的一个包冲突)这样的名称. 在中文版中, ...
- 在phpStrom中安装php代码格式化插件Php-cs-fixer
由于phpStrom原来的插件不再开源,现在转为使用Php-cs-fixer格式化代码.以下为在phpStrom中安装Php-cs-fixer的具体步骤. 安装安装很简单,下载php-cs-fixer ...
- 【转贴】SQL Server中关于跟踪(Trace)那点事
SQL Server中关于跟踪(Trace)那点事 https://www.cnblogs.com/zhijianliutang/p/4113911.html 作者很牛B.. 前言 一提到跟踪俩字,很 ...
- 小白学习django第五站-简易案例
首先在setting.py文件中编写数据库配置内容 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': ' ...
- ps -ef
status, msg = commands.getstatusoutput("ps -ef | grep start.sh | grep -Fv grep | awk '{print $1 ...