需要开 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
以上是临时设置.
1. 先备份 iptables
# cp /etc/sysconfig/iptables /var/tmp
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.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 到 PCiptables -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 都不许 PINGiptables -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
来源: http://www.bubuko.com/infodetail-2928828.html