Linux下iptables开放端口端示例
来源:互联网 发布:pychram软件运行环境 编辑:程序博客网 时间:2024/05/16 05:05
Linux系统在当做网站服务器运行时,具有很高的效率和运行稳定性。windows系统下可以通过系统防火墙来限制外部计算机对服务器端口的访问,而Linux是通过iptables来允许或限制端口访问的。 本文讨论的使用情境是LNmp或LNmpA系统架构下的情况。 为了方便举例说明,飘易就直接拿来一段我的现有服务器上运行的防火墙iptables内容。
请注意:后面的注释说明文字:
或者
保存命令:service iptables save
使用命令:iptables -L -n 可以查看当前iptables的开放端口情况。
iptables服务开机自动启动:
检查iptables服务:
上面开放的端口后面都有注明,有一个要注意的地方,就是FTP端口,FTP的默认端口21肯定要开放,但是一般的ftp软件都是默认先尝试几次被动模式PASV连接,在PASV模式连接失败后,才会进行主动模式PORT连接。 如果我们仅仅开放21端口,这里就有问题了。FTP PASV模式下,还会随机使用一个空闲端口,这个端口范围在20000-30000之间。所以,我们需要把这个端口范围加入防火墙:
请注意:后面的注释说明文字:
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT # (ssh端口)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT # (web端口)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT # (ftp端口)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20000:30000 -j ACCEPT # (ftp被动模式端口范围)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT # (mysql端口)
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
修改完防火墙iptables后,需要重新启动:# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT # (ssh端口)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT # (web端口)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT # (ftp端口)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20000:30000 -j ACCEPT # (ftp被动模式端口范围)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT # (mysql端口)
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
/etc/init.d/iptables restart
或者
service iptables restart
注意:iptables配置文件存放位置是:/etc/sysconfig/iptables保存命令:service iptables save
使用命令:iptables -L -n 可以查看当前iptables的开放端口情况。
iptables服务开机自动启动:
chkconfig iptables on
检查iptables服务:
# chkconfig --list iptables
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
上面开放的端口后面都有注明,有一个要注意的地方,就是FTP端口,FTP的默认端口21肯定要开放,但是一般的ftp软件都是默认先尝试几次被动模式PASV连接,在PASV模式连接失败后,才会进行主动模式PORT连接。 如果我们仅仅开放21端口,这里就有问题了。FTP PASV模式下,还会随机使用一个空闲端口,这个端口范围在20000-30000之间。所以,我们需要把这个端口范围加入防火墙:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20000:30000 -j ACCEPT
0 0
- Linux下iptables开放端口端示例
- Linux下iptables 禁止端口和开放端口
- Linux下iptables 禁止端口和开放端口
- Linux下iptables 禁止端口和开放端口
- Linux iptables 开放Mysql端口
- Linux iptables 开放Mysql端口
- Linux iptables 开放Mysql端口
- linux iptables开放端口命令
- linux iptables 端口开放限制
- linux iptables开放端口命令
- linux iptables开放端口命令
- linux iptables开放端口命令
- linux开放端口--防火墙iptables
- Linux iptables开放特定端口
- iptables下开放ftp连接端口
- linux 防火墙开放特定端口 (iptables)
- Linux 防火墙开放特定端口 (iptables)
- Linux 防火墙开放特定端口 (iptables)
- 如何实现在Oracle中应用存储过程调用MatLab函数(3)
- 【优先队列】HDU4006The kth great number
- loadrunner简单使用——HTTP,WebService,Socket压力测试脚本编写
- 无法激活服务,因为它不支持 ASP.NET 兼容性
- Android开发随笔之自定义TitleBar
- Linux下iptables开放端口端示例
- 你只是追逐时髦的码农
- [BZOJ2705] [SDOI2012] Longge的问题 - 欧拉函数
- zjnu 1762 U(想法、线段树)
- 【POJ 1191】 棋盘分割(DP)
- SQL调优 - Hints指定索引 解决慢查询案例
- pat--列出连通集
- OC 中new与alloc/init的区别
- Socket通信模式和URL通信模式