一、添加规则:设置禁止所有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. c#/netcore/mvc视图中调用控制器方法

    1: public class HomeController : Controller     {         public ActionResult Index()         {     ...

  2. Linux 部署 Django 系统

    一:安装uwsgi pip3 install uwsgi 二:进入项目目录下,创建uwsgi.ini配置文件 [uwsgi] # 使用nginx连接时使用功能,上线时才使用socket,指定项目执行的 ...

  3. MySQL 5.7 中文全文检索

    MySQL 5.7 中文全文检索 在 MySQL 5.7.6 之前,全文索引只支持英文全文索引,不支持中文全文索引,需要利用分词器把中文段落预处理拆分成单词,然后存入数据库.从 MySQL 5.7.6 ...

  4. 利用Apache POI操作Excel

    最近在做接口,有个功能是利用Excel导入汽车发动机所需零件信息到线上系统中.简单回顾一下之前学过的用java操作Excel. 1.maven配置Apache POI pom.xml中配置POIjar ...

  5. python与正则

    想了解正则的使用,请点击:正则表达式.每种编程语言有一些独特的匹配方式,python也不例外: 语法 含义 表达实例 完整匹配匹配的字符串 \A 仅匹配字符串开头 \Aabc abc \Z 仅匹配字符 ...

  6. Windows 下关于转码的函数

    std::string& MsgFieldList::GBToUTF8(std::string& des,const char* str) { WCHAR *strSrc; TCHAR ...

  7. vue项目中使用组件化开发

    最近在使用vue-cli结合webpack打包工具开发一个后台管理系统,使用vue难免需要运用组件化思想,而这也正是vue的一大特点. 在之前做的vue项目中,稍微有一点组件化的思想,可能是对组件化不 ...

  8. Caused by: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.的几种原因

    环境:centos 7+ 1.查看用户是否存在 进入安装目录使用./sbin/rabbitmqctl list_users查看是否存在用户 比如:./usr/local/rabbitmq/rabbit ...

  9. 【C/C++】assert()函数用法总结

    assert()函数用法总结 assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h> ...

  10. 【DSP开发】HyperLink 编程和性能考量

    冯华亮/Brighton Feng---Communication Infrastructure 摘要 HyperLink 为两个 KeyStone 架构 DSP 之间提供了一种高速,低延迟,引脚数量 ...