Linux 防火墙开放特定端口 (iptables)
2015-12-15 20:33
507 查看
iptables是linux下的防火墙,同时也是服务名称。
service iptables status 查看防火墙状态service iptables start 开启防火墙
service iptables stop 关闭防火墙
service iptables restart 重启防火墙
防火墙开放特定端口:
①文件/etc/sysconfig/iptables
②添加:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
★数字8080代表开放8080端口,也可以改成其他的端口★
③重启防火墙
================================================================
保存对防火墙的设置
serivce iptables save
查看iptables规则及编号
iptables -nL --line-number
关闭所有的INPUT FORWARD(转发) OUTPUT的所有端口
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
只打开22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
参数讲解:
–A 参数就看成是添加一条规则
–p 指定是什么协议,我们常用的tcp 协议,当然也有udp,例如53端口的DNS
–dport 就是目标端口,当数据从外部进入服务器为目标端口
–sport 数据从服务器出去,则为数据源端口使用
–j 就是指定是 ACCEPT -接收 或者 DROP 不接收
禁止某个IP访问
iptables -A INPUT -p tcp -s 192.168.1.2 -j DROP
–s 参数是来源(即192.168.1.2)
后面拒绝就是DROP
删除规则
iptables -D INPUT 2
删除INPUT链编号为2的规则
相关文章推荐
- FreeImage图形库如何在Linux下的使用
- 【Linux驱动】内存管理
- Linux_NFS/Samba服务器
- centos6中创建软raid方法
- centos6中创建软raid方法
- Linux内存寻址
- Linux下静态IP地址的设置及TFTP服务的搭建
- 解决vmware虚拟机克隆后启动centos报错device eth0 does not seem to be present, delaying initialization
- 解决vmware虚拟机克隆后启动centos报错device eth0 does not seem to be present, delaying initialization
- linux 库文件查找及其可执行文件查找定位
- Linux C编程----3(gdb调试)
- linux中与test命令相同功能的[] __demo
- Unix环境高级编程第三版中实例代码如何在自己的linux上运行的问题
- CentOS开机自动运行程序的脚本
- CentOS开机自动运行程序的脚本
- Linux下启动和关闭mysql服务
- Linux下rz/sz安装及使用方法
- 【window10下硬盘安装双系统linux之ubuntu14.04】
- dd制作linux启动盘
- linux 局域网内文件传送