参考博文:

iptables防火墙只允许指定ip连接指定端口、访问指定网站

一、配置防火墙

打开配置文件

  1. [root@localhost ~]# vi /etc/sysconfig/iptables

正确的配置文件

  1. # Firewall configuration written by system-config-firewall
  2. # Manual customization of this file is not recommended.
  3. *filter
  4. :INPUT ACCEPT [:]
  5. :FORWARD ACCEPT [:]
  6. :OUTPUT ACCEPT [:]
  7. -A INPUT -m state state ESTABLISHED,RELATED -j ACCEPT
  8. -A INPUT -p icmp -j ACCEPT
  9. -A INPUT -i lo -j ACCEPT
  10. -A INPUT -m state state NEW -m tcp -p tcp dport -j ACCEPT
  11. -A INPUT -m state state NEW -m tcp -p tcp dport -j ACCEPT
  12. -A INPUT -j REJECT reject-with icmp-host-prohibited
  13. -A FORWARD -j REJECT reject-with icmp-host-prohibited
  14. COMMIT
  1. -A INPUT -m state state NEW -m tcp -p tcp dport * -j ACCEPT

注意点:新开放的端口一定要在端口22后面

在配置pgAdmin远程访问虚拟机postgresql时发现出问题了,改了半天才发现是因为 防火墙端口开放文件中顺序没放对!汗!
重启防火墙使配置生效

  1. [root@localhost ~]# service iptables restart

其它

查看开放端口

  1. [root@localhost ~]# /etc/init.d/iptables status

关闭防火墙

  1. [root@localhost ~]# /etc/init.d/iptables stop

、配置防火墙允许指定ip访问端口

下面三行的意思:

先关闭所有的80端口

开启ip段192.168.1.0/24端的80口

开启ip段211.123.16.123/24端ip段的80口

  1. # iptables -I INPUT -p tcp --dport 80 -j DROP
  2. # iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT
  3. # iptables -I INPUT -s 211.123.16.123/24 -p tcp --dport 80 -j ACCEPT

开放一个IP的一些端口,其它都封闭

  1. iptables -A Filter -p tcp --dport 80 -s 192.168.100.200 -d www.pconline.com.cn -j ACCEPT
  2. iptables -A Filter -p tcp --dport 25 -s 192.168.100.200 -j ACCEPT
  3. iptables -A Filter -p tcp --dport 109 -s 192.168.100.200 -j ACCEPT
  4. iptables -A Filter -p tcp --dport 110 -s 192.168.100.200 -j ACCEPT
  5. iptables -A Filter -p tcp --dport 53 -j ACCEPT
  6. iptables -A Filter -p udp --dport 53 -j ACCEPT
  7. iptables -A Filter -j DROP

多个端口

  1. iptables -A Filter -p tcp -m multiport --destination-port 22,53,80,110 -s 192.168.20.3 -j REJECT

指定时间上网

  1. iptables -A Filter -s 10.10.10.253 -m time --timestart 6:00 --timestop 11:00 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j DROP
  2. iptables -A Filter -m time --timestart 12:00 --timestop 13:00 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT
  3. iptables -A Filter -m time --timestart 17:30 --timestop 8:30 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT

最经用的这个起作用:2017-8-16

  1. ptables 限制ip访问
  2. 通过iptables限制9889端口的访问(只允许192.168.1.201192.168.1.202192.168.1.203),其他ip都禁止访问
  3. iptables -I INPUT -p tcp --dport 9889 -j DROP
  4. iptables -I INPUT -s 192.168.1.201 -p tcp --dport 9889 -j ACCEPT
  5. iptables -I INPUT -s 192.168.1.202 -p tcp --dport 9889 -j ACCEPT
  6. iptables -I INPUT -s 192.168.1.203 -p tcp --dport 9889 -j ACCEPT
  7.  
  8. 注意命令的顺序不能反了。

  

CentOS6.5 配置防火墙+允许指定ip访问端口的更多相关文章

  1. centos7 firewall指定IP与端口访问(常用)

    1.启动防火墙 systemctl start firewalld.service 2.指定IP与端口 firewall-cmd --permanent --add-rich-rule="r ...

  2. centos7 firewall指定IP与端口、端段访问(常用)

    https://blog.csdn.net/yipianfuyunsm/article/details/99998332 https://www.cnblogs.com/co10rway/p/8268 ...

  3. 通过ASP禁止指定IP和只允许指定IP访问网站的代码

    过ASP禁止指定IP和只允许指定IP访问网站的代码,需要的朋友可以参考下. 一.禁止指定IP防问网站,并执行相应操作: 代码如下: <% Dim IP,IPString,VisitIP '设置I ...

  4. Nginx 拒绝指定IP访问

    来源 : http://www.ttlsa.com/nginx/nginx-deny-ip-access/   闲来无事,登陆服务器,发现有个IP不断的猜测路径.试图往服务器上传文件(木马).于是查看 ...

  5. 授权指定ip访问mysql 服务器

      授权指定ip访问访问 授权ROOT使用密码1234从应用服务器主机连接到mysql服务器 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'xxx. ...

  6. pycharm中指定ip和端口

    pycharm中指定ip和端口 环境: 系统:win7 本机ip:192.168.0.100 1.建立工程请参照:https://www.cnblogs.com/effortsing/p/103945 ...

  7. MySQL指定ip和端口连接数据库,并修改数据库密码

    一.指定ip和端口连接数据库 命令 mysql -u root -h (ip) -P (端口)-p 假设ip是:127.0.0.1:端口是:13326,连接的命令: mysql -u root -h ...

  8. 配置tomcat限制指定IP地址访问后端应用

    1. 场景后端存在N个tomcat实例,前端通过nginx反向代理和负载均衡. tomcat1      tomcatN         |                 |        |    ...

  9. nginx安全:配置allow/deny控制ip访问(ngx_http_access_module)

    一,nginx中allow/deny指令的用途 1, Nginx的deny和allow指令是由ngx_http_access_module模块提供, Nginx安装默认内置了该模块 2, nginx访 ...

随机推荐

  1. BZOJ2440(全然平方数)二分+莫比乌斯容斥

    题意:全然平方数是指含有平方数因子的数.求第ki个非全然平方数. 解法:比較明显的二分,getsum(int middle)求1-middle有多少个非全然平方数,然后二分.求1-middle的非全然 ...

  2. C++学习之虚继承

    http://blog.csdn.net/wangxingbao4227/article/details/6772579 C++中虚拟继承的概念 为了解决从不同途径继承来的同名的数据成员在内存中有不同 ...

  3. 菜鸟初识UML

    首当其冲的就是:什么是UML呢? 首先,UML 是一种可视化的面向对象的建模语言.它是一个支持模型化和软件系统开发的图形化语言,为软件开发的所有阶段提供模型化和可视化支持,包括由需求分析到规格,到构造 ...

  4. crontab中使用mysql问题

    第1列分钟1-59第2列小时1-23(0表示子夜)第3列日1-31第4列月1-12第5列星期0-6(0表示星期天)第6列要运行的命令 ,  并列 -  连续 crontab中不能执行mysql,百分之 ...

  5. Uva 225 Golygons

    这道题如果直接用Dfs,运气好的话是可以直接过的. 但如果要在Dfs的基础上加快速度,剪枝是必不可少的. 我的剪枝策略: 1.当前点(x,y)回到出发点至少需要 |x| +| y| 步,如果剩余的步数 ...

  6. Girls and Boys(匈牙利)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. poj 3691

    ac自动机+dp 自动机上的节点来作为状态 dp[i][j]表示长度为i状态为j至少需要转换多少个字符 #include <iostream> #include <cstdio> ...

  8. Java程序如何自动在线升级

    有时候我们的程序需要连接服务器检测新版本,如果发现新版本则需要自动下载升级.这种需求在Linux下还好说,但在windows下如何替换正在运行的程序文件呢? 当然有办法,步骤如下: 1. 将我们的程序 ...

  9. iOSAPP启动时实现加载广告

    现在很多APP在启动的时候都在加载广告,现在也很流行,主要是盈利啊.笔者也做了很多关于广告的事情.现在记录下自己在APP启动的时候,怎么加载广告的. 下面总结下广告加载的三种方式 1.现在很多APP的 ...

  10. if else配对问题

    else语句总是与离它最近的if语句配对,所以在if语句的嵌套中一定要注意else语句与哪个if语句匹配 #include <iostream> using namespace std; ...