iptables开放端口的使用方法总结

# 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

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开放端口的使用方法总结

时间: 2024-07-30 22:53:26

iptables开放端口的使用方法总结的相关文章

【Linux】iptables开放端口

1. 允许某一个端口通过 编辑iptables配置文件 vi /etc/sysconfig/iptables 添加配置 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙) 重启iptables使配置生效 service iptables restart 2. 指定端口只允许指定IP访问 iptables -I INPUT -p TCP --dport 80 -j DROP iptables -

Centos7防火墙快速开放端口配置方法

▲这篇文章主要为大家详细介绍了Centos7防火墙开放端口的快速方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下! 例如安装Nagios后,要开放5666端口与服务器连接,命令如下 [[email protected] ~]# firewall-cmd --add-port=5666/tcp 即时打开,这里也可以是一个端口范围,如1000-2000/tcp success [[email protected] ~]# firewall-cmd --permanent --add-port=

CentOS 7防火墙开放端口快速方法

这篇文章主要为大家详细介绍了Centos7.1防火墙开放端口的快速方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 例如安装Nagios后,要开放5666端口与服务器连接,命令如下: [[email protected] ~]# firewall-cmd --add-port=5666/tcp 即时打开,这里也可以是一个端口范围,如1000-2000/tcp success [[email protected] ~]# firewall-cmd --permanent --add-port

Linux下iptables 禁止端口和开放端口

iptables 禁止端口和开放端口 1.首先介绍一下指令和相关配置文件 启动指令:service iptables start 重启指令:service iptables restart 关闭指令:service iptables stop 然后是相关配置:/etc/sysconfig/iptables 如何操作该配置呢? vim /etc/sysconfig/iptables 然后进去修改即可,修改完了怎么办?这里很多人会想到/etc/rc.d/init.d/iptables save指令,

记录一次服务器防火墙开放端口,参考了网上一位网友的方法可行,在此记录一下

CentOS 7 的防火墙开启 http 80 端口 在虚拟机 CentOS 7 上装了 Nginx,结果发现另一台电脑无法访问其默认页面,通过 telnet 192.168.1.88 80 监听发现是 http 80 端口被 CentOS 7 的防火墙 Firewalld(CentOS 6 的防火墙是 iptables)给阻止通信了. 接下来就讲下如何添加防火墙规则. 先查看防火墙是否开启的状态,以及开放端口的情况: systemctl status firewalld.service sud

CentOS 7防火墙快速开放端口配置方法

一.CentOS 7快速开放端口: CentOS升级到7之后,发现无法使用iptables控制Linuxs的端口,baidu之后发现Centos 7使用firewalld代替了原来的iptables.下面记录如何使用firewalld开放Linux端口: 开启端口 [[email protected] ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent 查询端口号80 是否开启: [[email protected] ~]#

Iptables开放FTP(主/被)模式端口

FTP是File Transfer Protocol(文件传输协议),它有两种工作模式,分别是主动模式(post)和被动模式(passive) PORT(主动模式) FTP客户端连接到FTP服务器的21端口,发送用户名和密码登录,登录成功后要list列表或者读取数据时,客户端随机开放一个端口(1024以上),发送 PORT命令到FTP服务器,告诉服务器客户端采用主动模式并开放端口:FTP服务器收到PORT主动模式命令和端口号后,通过服务器的20端口和客户端开放的端口连接,发送数据. PASV(被

linux下通过iptables只允许指定ip地址访问指定端口的设置方法

这篇文章主要介绍了linux下通过iptables只允许指定ip地址访问指定端口的设置方法,需要的朋友可以参考下. 首先,清除所有预设置 iptables -F#清除预设表filter中的所有规则链的规则 iptables -X#清除预设表filter中使用者自定链中的规则 其次,设置只允许指定ip地址访问指定端口 其次,设置只允许指定ip地址访问指定端口 iptables -A INPUT -s xxx.xxx.xxx.xxx -p tcp --dport 22 -j ACCEPT iptab

CentOS 7 iptables 开放8080端口

# 安装iptables-services [[email protected] bin]# yum install iptables-services [[email protected] bin]# /bin/systemctl status iptables.service # 临时开放端口 [[email protected] sysconfig]# iptables -I INPUT -p tcp --dport 8080 -j ACCEPT # 重启iptables临时端口失效 [[