防火墙规则配置iptables
Linux防火墙Iptable如何设置只允许某个ip访问80端口,只允许特定ip访问某端口?参考下面命令,只允许46.166.150.22访问本机的80端口。如果要设置其他ip或端口,改改即可。
iptables -I INPUT -p TCP --dport 80 -j DROP
iptables -I INPUT -s 46.166.150.22 -p TCP --dport 80 -j ACCEPT
在root用户下执行上面2行命令后,重启iptables, service iptables restart
查看iptables是否生效:
[root@www.ctohome.com]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 46.166.150.22 anywhere tcp dpt:http
DROP tcp -- anywhere anywhere tcp dpt:http
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
上面命令是针对整个服务器(全部ip)禁止80端口,如果只是需要禁止服务器上某个ip地址的80端口,怎么办?
下面的命令是只允许来自174.140.3.190的ip访问服务器上216.99.1.216的80端口
iptables -A FORWARD -s 174.140.3.190 -d 216.99.1.216 -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A FORWARD -d 216.99.1.216 -p tcp -m tcp --dport 80 -j DROP
如果您不熟悉linux的ssh命令,那么可以在webmin/virtualmin面板中设置,达到相同效果。参考:webmin面板怎样设置允许特定ip访问80端口,禁止80端口
更多iptables参考命令如下:
1.先备份iptables
# cp /etc/sysconfig/iptables /var/tmp
需要开80端口,指定IP和局域网
下面三行的意思:
先关闭所有的80端口
开启ip段192.168.1.0/24端的80口
开启ip段211.123.16.123/24端ip段的80口
# iptables -I INPUT -p tcp --dport 80 -j DROP
# iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT
# iptables -I INPUT -s 211.123.16.123/24 -p tcp --dport 80 -j ACCEPT
以上是临时设置。
2.然后保存iptables
# service iptables save
3.重启防火墙
#service iptables restart
===============以下是转载================================================
以下是端口,先全部封再开某些的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.1.22 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 21 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.1.22:21
只允许访问指定网址
iptables -A Filter -p udp --dport 53 -j ACCEPT
iptables -A Filter -p tcp --dport 53 -j ACCEPT
iptables -A Filter -d www.ctohome.com -j ACCEPT
iptables -A Filter -d www.guowaivps.com -j ACCEPT
iptables -A Filter -j DROP
开放一个IP的一些端口,其它都封闭
iptables -A Filter -p tcp --dport 80 -s 192.168.1.22 -d www.pconline.com.cn -j ACCEPT
iptables -A Filter -p tcp --dport 25 -s 192.168.1.22 -j ACCEPT
iptables -A Filter -p tcp --dport 109 -s 192.168.1.22 -j ACCEPT
iptables -A Filter -p tcp --dport 110 -s 192.168.1.22 -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.1.22:80
MAIL服务器要转的端口
iptables -t nat -A PREROUTING -p tcp --dport 110 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.1.22:110
iptables -t nat -A PREROUTING -p tcp --dport 25 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.1.22:25
只允许PING 202。96。134。133,别的服务都禁止
iptables -A Filter -p icmp -s 192.168.1.22 -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.1.22 -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相关推荐
- linux防火墙规则配置教程,linux防火墙iptables详细教程
2.1 框架图 -->PREROUTING-->[ROUTE]-->FORWARD-->POSTROUTING--> mangle | mangle ...
- linux的firewalld防火墙规则配置
目录 一.查看firewall规则 二.配置允许访问规则 (一)配置文件添加 (二)命令行添加 1. 开通所有源IP访问http服务 2. 开通访问http服务,并限制源IP访问 三.配置禁止访问规则 ...
- linux7保存防火墙规则,centos7中没有service iptables save指令来保存防火墙规则
1.任意运行一条iptables防火墙规则配置命令: iptables -P OUTPUT ACCEPT 2.对iptables服务进行保存: service iptables save 如果上述命令 ...
- Deepin/Linux系统使用GUFW可视化管理、配置防火墙规则
对于没有接触过 Linux 的人,配置防火墙难于上青天,即便是缙哥哥这样玩过一丢丢的,也不喜欢用命令控制.所以,今天就给大家带来一款Deepin/Linux系统可视化管理.配置防火墙规则的软件--GU ...
- linux 防火墙的配置
Linux 的防火墙是一个非常重要的安全功能,可以保护系统免受网络攻击.在 Linux 中,有很多种防火墙软件可供选择,其中最常见的是 iptables 和 firewalld. 下面是针对 ipta ...
- linux的nfs端口111,【NFS】NFS设置固定端口,添加防火墙规则
NFS server启动时会随机启动多个端口并向RPC注册,这样如果使用iptables对NFS sever 端口进行限制就会有点麻烦,可以更改配置文件固定NFS服务相关端口. 以前配置的nfs端口一 ...
- 对linux防火墙规则的优化,Linux防火墙规则优化的研究
摘要: 随着Internet在全球范围内的迅速发展和广泛应用,在给人们的生活带来方便和快捷的同时,也带来了大量的问题,这其中就包括网络信息安全问题.作为常用的处理网络安全问题的工具,防火墙作用就显得尤 ...
- 25个常用的防火墙规则
本文将给出25个iptables常用规则示例,这些例子为您提供了些基本的模板,您可以根据特定需求对其进行修改调整以达到期望. 格式 iptables [-t 表名] 选项 [链名] [条件] [-j ...
- linux防火墙规则命令意思,linux防火墙iptables配置规则分享
类似的,对于HTTP/HTTPS(80/443).pop3(110).rsync(873).MySQL(3306)等基于tcp连接的服务,也可以参照上述命令配置. 对于基于udp的dns服务,使用以下 ...
最新文章
- 简单线性分类学习机(平分最近点法)matlab实现
- 数据中心机房蓄电池培训
- Couldn‘t connect to session bus: Did not receive a reply. Possible causes include: the remote applic
- LeetCode—220. 存在重复元素 III
- cubemx lan8720模块_通过STM32cubeMX将STM32F767+LAN8720+LwIP+FreeRTOS的以太网实现
- centos7 python3.7 ssl_centos 解决python3.7 安装时No module named _ssl
- Unity 内嵌网页
- Source Insight3.x注册码
- Ubuntu MySQL 重新安装
- linux 上rocketMQ 安装启动
- 1月16日新经济智库大会聚焦数字经济,议程、直播全收藏
- pip下载速度慢的解决方法
- 如何领取门票参加中国北京科技产业博览会?
- 薪资待遇#23届#海尔#嵌入式软件
- python 语言与numpy库
- SpringBoot2.0.X使用Redis连接池Lettuce踩坑
- 基于 Nios II 的串口打印和流水灯设计【使用 Quartus 软件】【掌握 SOPC 开发流程】
- 什么是等保?为什么做等保?如何做等保?
- UART的RTL逻辑设计部分 - uart_rx
- 关于二叉树的建立和遍历易错问题
热门文章
- HTTP代理如何正确处理Cookie
- 使用VC编写VB使用DLL
- 天胶指数发布 对话国际农民丰收节贸易会海垦集团走出去
- OMG: daily scrum six
- 电子书下载:Learn Office 2011 for Mac OS X
- Java笔记:与系统交互、系统相关的类,Object类
- [搬运工系列]-JMeter(二十四)搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)
- MySQL导出表结构相关字段以及把字段由下划线转驼峰命名
- MySql cmd下的学习笔记 —— 有关select的操作(max, min等常见函数)
- PHP 防XSS跨站攻击