Linux 防火墙开放特定端口
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的规则
热门日志
分类
- Django(4)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- about(1)
- git(9)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(19)
- Vue(1)
- game(2)
- Html(6)
- Java(8)
- Mysql(37)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(73)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Php(102)
- Windows(8)
- Message(48)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)
最新日志
- 成为架构师,如何真正具备“系统思维”?
- DHCP(Dynamic Host Configuration Protocol) 动态主机配置协议
- 从技术专家到战略领袖:成就技术总监的路径与思维
- python 如何读取超大的文件
- python requests 模块
- 如何给自己充电?
- 告别2024,迎接2025:深耕梦想,向前而行
- linux 的 dns 缓存,NSCD 服务
- The following untracked working tree files would be overwritten by checkout
- insecure connection not allowed,产生原因及如何解决
随机日志
- linux 批量查找删除
- 独立IP与共享IP对SEO的影响分析(转载)
- php-fpm通过request_slowlog_timeout检查哪个脚本执行时间长
- 永远不要在 Linux 执行的 10 个最危险的命令
- js 实现php中sprintf函数
- Js中window.parent ,window.top,window.self 详解
- Warning: Unknown: Unable to allocate memory for pool. in Unknown on line 0 Warning: require_once(): Unable to allocate memory for pool
- Jquery跨域请求php获取数据之jsonp