一、添加规则:设置禁止所有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访问指定端口的更多相关文章

  1. linux禁止特定ip访问某个端口

    linux禁止特定ip访问某个端口   解决方法: 禁止特定ip访问8501端口的命令0:iptables -I INPUT -s 192.168.0.232 -ptcp --dport 8501 - ...

  2. 只允许指定IP访问指定端口 ufw

    那天工作需要在服务器上指定ip才可以访问指定端口,配置命令如下: (服务器是ubuntu 14.04系统) apt-get install ufw ufw enable ufw default den ...

  3. windows防火墙安全设置指定ip访问指定端口

    场景摘要: 1.我有三台腾讯云服务器 2.我日常办公网络的ip换了 3.我在腾讯云上面改了安全规则,也不能访问我A服务器的21,1433等端口 4.开始我以为是办公网络的安全设置问题 5.我进B服务器 ...

  4. linux下通过iptables只允许指定ip地址访问指定端口的设置方法

    这篇文章主要介绍了linux下通过iptables只允许指定ip地址访问指定端口的设置方法,需要的朋友可以参考下. 首先,清除所有预设置 iptables -F#清除预设表filter中的所有规则链的 ...

  5. iptables只允许指定ip地址访问指定端口

    首先,清除所有预设置 iptables -F#清除预设表filter中的所有规则链的规则 iptables -X#清除预设表filter中使用者自定链中的规则 其次,设置只允许指定ip地址访问指定端口 ...

  6. iptables 防火墙 只允许某IP访问某端口、访问特定网站

    iptables 防火墙 只允许某IP访问某端口.访问特定网站 1.先备份iptables /var/tmp 需要开80端口,指定IP和局域网 下面三行的意思: 先关闭所有的80端口 开启ip段192 ...

  7. iptables/mysql设置指定主机访问指定端口

    本周,运维告知部署的服务被扫描发现漏洞,涉及的软件分别为mysql,ZooKeeper与Elasticsearch. 因为最近任务繁重,人力资源紧张,因此无法抽出更多时间调整代码,添加权限认证. 与软 ...

  8. Apache中限制和允许特定IP访问

    Apache中限制和允许特定IP访问<Directory "/var/www">Options AllAllowOverride NoneOrder Deny,Allo ...

  9. 网络基础 图解Windows系统下单网卡设置双IP访问不同网段的方法

    图解Windows系统下单网卡设置双IP访问不同网段的方法 by:授客 QQ:1033553122 在Windows系统下即使只有一块网卡,同样可以实现双IP访问不同网段. 例: 外网信息: IP:1 ...

随机推荐

  1. python 中 __dict__函数的使用

    class F: def __init__(self, name, age): self.name = name self.age = age obj = F('tom', 20)s = obj.__ ...

  2. 修改deploy location

    在MyEclipse,如果某Web Project重命名后,项目名称有可能仍然是之前的名称. 修改路径: 第一, 路径:右击某Web Project,Properties->MyEclipse- ...

  3. [LeetCode] 697. Degree of an Array 数组的度

    Given a non-empty array of non-negative integers nums, the degree of this array is defined as the ma ...

  4. C# 线程安全集合类

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/kang_xuan/article/de ...

  5. 03 vue项目结构

    上一篇已介绍根据vue-cli创建项目,本篇介绍根据vue-cli官方脚手架创建的项目的项目结构. 一.图看结构 build  [webpack配置]         webpack相关配置,都已经配 ...

  6. 基于OpenCV的循环行、列移动函数circShift()

    ///*12 在Matlab中有个circShift()函数,可以实现行.列的循环移动 /// 在返卷积运算中,会用到这个函数.所以,在Opencv中我也定义同样 /// 功能的函数 /// 该函数有 ...

  7. NOIp2016 D2T3 愤怒的小鸟【搜索】(网上题解正解是状压)

    题目传送门 没啥别的想法,感觉就是搜索,经过原点的抛物线已知两个点就可以求出解析式,在还没有被打下来的两个猪之间随意配对,确定解析式之后标记在这个抛物线下被打下来的猪. 猪也可以单独用一个抛物线打下来 ...

  8. kibana 查询例子

    1.数字比较和布尔查询 account_number:< AND balance:>

  9. 访问https接口报错 基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系

    详细错误信息如下 请求错误信息:发生一个或多个错误.System.Net.Http.HttpRequestException: An error occurred while sending the ...

  10. python学习笔记四 (运算符重载和命名空间、类)

    从以上代码中应该了解到: obj.attribute  查找的顺序: 从对象,类组成的树中,从下到上,从左到右到查找最近到attribute属性值,因为rec中存在name的属性,所以x.name可以 ...