您现在的位置: 万盛学电脑网 >> 网络安全 >> 安全资讯防护 >> 正文

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

作者:佚名    责任编辑:admin    更新时间:2022-06-22

> 杀毒防毒 > 正文 iptables防火墙 只允许某IP访问某端口、访问特定网站 2012-11-15               我要投稿 1.先备份iptables

  织梦内容管理系统

# cp /etc/sysconfig/iptables /var/tmp dedecms.com

需要开80端口,指定IP和局域网 内容来自dedecms

下面三行的意思: dedecms.com

先关闭所有的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  copyright dedecms

# iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT 内容来自dedecms

# iptables -I INPUT -s 211.123.16.123/24 -p tcp --dport 80 -j ACCEPT 内容来自dedecms

以上是临时设置。

本文来自织梦

2.然后保存iptables

本文来自织梦

# service iptables save 织梦好,好织梦

3.重启防火墙 本文来自织梦

#service iptables restart dedecms.com

===============以下是转载================================================ dedecms.com

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

iptables -I INPUT -p tcp --dport 9889 -j DROP  内容来自dedecms

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

copyright dedecms

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

织梦内容管理系统

iptables -I FORWARD -p tcp --dport 80 -j DROP  内容来自dedecms

iptables -I FORWARD -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT 本文来自织梦

  织梦好,好织梦

 

织梦好,好织梦

常用的IPTABLES规则如下: 织梦好,好织梦

只能收发邮件,别的都关闭 copyright dedecms

iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -j DROP copyright dedecms

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

内容来自dedecms

iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p tcp --dport 110 -j ACCEPT

copyright dedecms

  织梦内容管理系统

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 dedecms.com

 

织梦内容管理系统

FTP服务器的NAT 织梦内容管理系统

iptables -I PFWanPriv -p tcp --dport 21 -d 192.168.100.200 -j ACCEPT

内容来自dedecms

iptables -t nat -A PREROUTING -p tcp --dport 21 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:21 内容来自dedecms

 

dedecms.com

只允许访问指定网址

dedecms.com

iptables -A Filter -p udp --dport 53 -j ACCEPT 内容来自dedecms

iptables -A Filter -p tcp --dport 53 -j ACCEPT 织梦内容管理系统

iptables -A Filter -d -j ACCEPT 织梦好,好织梦

iptables -A Filter -d img.cn99.com -j ACCEPT 本文来自织梦

iptables -A Filter -j DROP copyright dedecms

  本文来自织梦

开放一个IP的一些端口,其它都封闭 织梦内容管理系统

iptables -A Filter -p tcp --dport 80 -s 192.168.100.200 -d -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 dedecms.com

iptables -A Filter -j DROP

copyright dedecms

  织梦好,好织梦

多个端口 织梦好,好织梦

iptables -A Filter -p tcp -m multiport --destination-port 22,53,80,110 -s 192.168.20.3 -j REJECT 本文来自织梦

  织梦内容管理系统

连续端口 内容来自dedecms

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 本文来自织梦

  织梦内容管理系统

指定时间上网 dedecms.com

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

内容来自dedecms

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 dedecms.com

  本文来自织梦

将WAN 口NAT到PC 织梦好,好织梦

iptables -t nat -A PREROUTING -i $INTERNET_IF -d $INTERNET_ADDR -j DNAT --to-destination 192.168.0.1

dedecms.com

  内容来自dedecms

将WAN口8000端口NAT到192。168。100。200的80端口 copyright dedecms

iptables -t nat -A PREROUTING -p tcp --dport 8000 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:80 copyright dedecms

  织梦内容管理系统

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

织梦好,好织梦

 

内容来自dedecms

只允许PING 202。96。134。133,别的服务都禁止 dedecms.com

iptables -A Filter -p icmp -s 192.168.100.200 -d 202.96.134.133 -j ACCEPT 内容来自dedecms

iptables -A Filter -j DROP 内容来自dedecms

禁用BT配置 织梦好,好织梦

iptables –A Filter –p tcp –dport 6000:20000 –j DROP copyright dedecms

禁用QQ防火墙配置 dedecms.com

iptables -A Filter -p udp --dport ! 53 -j DROP 本文来自织梦

iptables -A Filter -d 218.17.209.0/24 -j DROP copyright dedecms

iptables -A Filter -d 218.18.95.0/24 -j DROP 本文来自织梦

iptables -A Filter