`
zhaohaolin
  • 浏览: 1003376 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

IPTABLES 防火墙 只允许某IP访问某端口

 
阅读更多

http://www.17rumen.com/archives/57.html

(有视频)需要2个命令一齐

iptables -A INPUT -P tcp -s 192.168.0.0 -j ACCEPT

iptables -A OUTPUT -p tcp -d 192.168.0.0 -j ACCEPT

以下是端口,先全部封再开某些的IP

iptables -I INPUT -p tcp --dport 9889 -j DROP 
iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 9889 -j ACCEPT

如果用了NAT转发记得配合以下才能生效

iptables -I FORWARD -p tcp --dport 80 -j DROP 
iptables -I FORWARD -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT

 

常用的IPTABLES规则如下:

只能收发邮件,别的都关闭
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -j DROP
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p udp --dport 53 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p tcp --dport 25 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p tcp --dport 110 -j ACCEPT


IPSEC NAT 策略
iptables -I PFWanPriv -d 192.168.100.2 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 80 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:80

iptables -t nat -A PREROUTING -p tcp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723

iptables -t nat -A PREROUTING -p udp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723

iptables -t nat -A PREROUTING -p udp --dport 500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:500

iptables -t nat -A PREROUTING -p udp --dport 4500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:4500


FTP服务器的NAT

iptables -I PFWanPriv -p tcp --dport 21 -d 192.168.100.200 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 21 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:21


只允许访问指定网址
iptables -A Filter -p udp --dport 53 -j ACCEPT
iptables -A Filter -p tcp --dport 53 -j ACCEPT
iptables -A Filter -d www.3322.org -j ACCEPT
iptables -A Filter -d img.cn99.com -j ACCEPT
iptables -A Filter -j DROP


开放一个IP的一些端口,其它都封闭
iptables -A Filter -p tcp --dport 80 -s 192.168.100.200 -d www.pconline.com.cn -j ACCEPT
iptables -A Filter -p tcp --dport 25 -s 192.168.100.200 -j ACCEPT
iptables -A Filter -p tcp --dport 109 -s 192.168.100.200 -j ACCEPT
iptables -A Filter -p tcp --dport 110 -s 192.168.100.200 -j ACCEPT
iptables -A Filter -p tcp --dport 53 -j ACCEPT
iptables -A Filter -p udp --dport 53 -j ACCEPT
iptables -A Filter -j DROP


多个端口
iptables -A Filter -p tcp -m multiport --destination-port 22,53,80,110 -s 192.168.20.3 -j REJECT


连续端口
iptables -A Filter -p tcp -m multiport --source-port 22,53,80,110 -s 192.168.20.3 -j REJECT iptables -A Filter -p tcp --source-port 2:80 -s 192.168.20.3 -j REJECT


指定时间上网
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
iptables -A Filter -m time --timestart 12:00 --timestop 13:00 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT
iptables -A Filter -m time --timestart 17:30 --timestop 8:30 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT

禁止多个端口服务
iptables -A Filter -m multiport -p tcp --dport 21,23,80 -j ACCEPT


将WAN 口NAT到PC
iptables -t nat -A PREROUTING -i $INTERNET_IF -d $INTERNET_ADDR -j DNAT --to-destination 192.168.0.1


将WAN口8000端口NAT到192。168。100。200的80端口
iptables -t nat -A PREROUTING -p tcp --dport 8000 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:80


MAIL服务器要转的端口
iptables -t nat -A PREROUTING -p tcp --dport 110 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:110
iptables -t nat -A PREROUTING -p tcp --dport 25 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:25


只允许PING 202。96。134。133,别的服务都禁止
iptables -A Filter -p icmp -s 192.168.100.200 -d 202.96.134.133 -j ACCEPT
iptables -A Filter -j DROP

禁用BT配置
iptables –A Filter –p tcp –dport 6000:20000 –j DROP

禁用QQ防火墙配置
iptables -A Filter -p udp --dport ! 53 -j DROP
iptables -A Filter -d 218.17.209.0/24 -j DROP
iptables -A Filter -d 218.18.95.0/24 -j DROP
iptables -A Filter -d 219.133.40.177 -j DROP

基于MAC,只能收发邮件,其它都拒绝
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -j DROP
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 25 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 110 -j ACCEPT

禁用MSN配置
iptables -A Filter -p udp --dport 9 -j DROP
iptables -A Filter -p tcp --dport 1863 -j DROP
iptables -A Filter -p tcp --dport 80 -d 207.68.178.238 -j DROP
iptables -A Filter -p tcp --dport 80 -d 207.46.110.0/24 -j DROP

只允许PING 202。96。134。133 其它公网IP都不许PING
iptables -A Filter -p icmp -s 192.168.100.200 -d 202.96.134.133 -j ACCEPT
iptables -A Filter -p icmp -j DROP

禁止某个MAC地址访问internet:
iptables -I Filter -m mac --mac-source 00:20:18:8F:72:F8 -j DROP

禁止某个IP地址的PING:
iptables –A Filter –p icmp –s 192.168.0.1 –j DROP

禁止某个IP地址服务:
iptables –A Filter -p tcp -s 192.168.0.1 --dport 80 -j DROP
iptables –A Filter -p udp -s 192.168.0.1 --dport 53 -j DROP

只允许某些服务,其他都拒绝(2条规则)
iptables -A Filter -p tcp -s 192.168.0.1 --dport 1000 -j ACCEPT
iptables -A Filter -j DROP

禁止某个IP地址的某个端口服务
iptables -A Filter -p tcp -s 10.10.10.253 --dport 80 -j ACCEPT
iptables -A Filter -p tcp -s 10.10.10.253 --dport 80 -j DROP

禁止某个MAC地址的某个端口服务

iptables -I Filter -p tcp -m mac --mac-source 00:20:18:8F:72:F8 --dport 80 -j DROP

禁止某个MAC地址访问internet:
iptables -I Filter -m mac --mac-source 00:11:22:33:44:55 -j DROP

禁止某个IP地址的PING:
iptables –A Filter –p icmp –s 192.168.0.1 –j DROP
分享到:
评论

相关推荐

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

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

    Linux上iptables防火墙的应用教程

    iptables 防火墙的基本应用包括安装、清除规则、开放指定端口、屏蔽指定 IP、删除已添加的规则等。 安装 iptables 防火墙 若要使用 iptables 防火墙,需要先安装它。对于 CentOS,可以使用 yum install iptables ...

    10.6: iptables防火墙 、 filter表控制 、 扩展匹配 、 nat表典型应用 、 总结和答疑.docx

    扩展匹配可以对网络流量进行详细的匹配,例如根据源 IP 地址、目的 IP 地址、协议类型、端口号等进行匹配。扩展匹配可以实现对网络流量的精准控制。 四、nat 表典型应用 nat 表是 iptables 防火墙中的一个重要组件...

    Linux上iptables防火墙的基本应用教程.docx

    iptables 是 Linux 上常用的防火墙软件,本教程将介绍 iptables 的安装、清除 iptables 规章、iptables 只开放指定端口、iptables 屏蔽指定 IP、IP 段及解封、删除已添加的 iptables 规章等 iptables 的基本应用。...

    阿里云Centos配置iptables防火墙.docx

    阿里云CentOS配置iptables防火墙是一项重要的安全措施,尽管阿里云提供了云盾服务,但额外的防火墙层能提供额外的安全保障。以下是配置iptables防火墙的详细步骤: 1. **检查iptables服务状态**: 首先,通过运行`...

    iptables防火墙设置

    本文档详细介绍了iptables防火墙的设置和配置,包括iptables的基本概念、防火墙配置原则、iptables基础语法、ip和网卡接口设置、设定端口访问、模块调用等方面的知识点。 一、iptables基本概念 iptables是Linux...

    Linux Ubuntu系统iptables防火墙配置

    配置iptables防火墙的主要目的是保护服务器安全,防止未经授权的访问和恶意攻击,以及避免不必要的服务暴露,提高系统的稳定性和安全性。通过制定精确的规则,可以阻止非法探测,确保只有指定的主机能够访问特定的...

    利用iptables来配置linux禁止所有端口登陆和开放指定端口的方法

    下面小编就为大家带来一篇利用iptables来配置linux禁止所有端口登陆和开放指定端口的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    iptables 端口转发

    iptables是一个Linux下优秀的nat+防火墙工具

    linux iptables防火墙配置

    ### Linux iptables防火墙配置详解 #### 一、iptables与Linux防火墙的演进 Linux系统自诞生以来,其防火墙功能经历了多个阶段的发展。在2.0版内核时代,包过滤机制由`ipfw`承担,配套的管理工具为`ipfwadm`;到了...

    防火墙白名单设置方法_iptables_centos6

    防火墙白名单设置方法_iptables_centos6 防火墙白名单设置方法_iptables_centos6 防火墙白名单设置方法_iptables_centos6

    一键配置CentOS iptables防火墙的Shell脚本分享

    ### 一键配置CentOS iptables防火墙Shell脚本解析 #### 概述 本文将详细介绍一个用于一键配置CentOS系统中的iptables防火墙的Shell脚本。该脚本可以帮助用户简化新装系统的iptables配置过程,使其更加高效且易于...

    linux开启redis端口的防火墙.docx

    防火墙可以根据不同的协议和端口号来控制访问,例如,允许或拒绝来自某个 IP 地址的访问。 在 Linux 中,常用的防火墙软件有 UFW(Uncomplicated Firewall)和 iptables。UFW 是一个简洁易用的防火墙工具,它提供了...

    mysql设置指定ip远程访问连接实例

    - 要限制只允许特定IP(例如218.12.50.60)的远程访问,修改命令如下: ``` GRANT ALL PRIVILEGES ON *.* TO 'root'@'218.12.50.60' IDENTIFIED BY 'jb51' WITH GRANT OPTION; FLUSH PRIVILEGES; ``` 2. **...

    通过iptables实现端口转发和内网共享上网.docx

    例如,我们可以将公网IP的80端口映射到内网IP的8080端口,从而实现互联网用户访问我们内部的web服务器。 iptables是一个功能强大且灵活的nat+防火墙工具,可以配置灵活强劲的防火墙+nat系统,並且可以实现端口转发...

    Linux防火墙iptables简明教程.docx

    * 允许访问特定端口: `iptables -A INPUT -p tcp --dport 22 -j ACCEPT` * 屏蔽特定 IP: `iptables -I INPUT -s 123.123.123.123 -j DROP` 这些规则可以根据需要进行修改和添加。 6. 设置开机启动 在安装 ...

    linux防火墙iptables常用规则.docx

    ### Linux防火墙iptables常用规则详解 #### 一、iptables基础操作与配置 ##### 删除现有规则 在使用iptables之前,我们通常需要先清除已有的规则,以便于重新建立新的规则集。这可以通过`iptables -F`命令来实现。...

    firewall:使用 iptables 在 Linux 中生成防火墙的 bash 脚本集。 基于

    标准用法您只需要运行一个脚本来管理防火墙,但您可以向其传递各种命令。 它们通常应按显示的顺序运行。 请注意,所有命令都需要以 root 权限执行(例如,通过使用 sudo)。重置规则此命令将 iptables 重置为空状态...

Global site tag (gtag.js) - Google Analytics