linux-防火墙设置

news/2024/7/5 3:06:36 标签: 操作系统, 网络

防火墙状态

查询防火墙状态
service iptables status
停止防火墙
service iptables stop
启动防火墙
service iptables start
重启防火墙
service iptables restart
永久关闭防火墙
chkconfig iptables off
永久关闭后启动
chkconfig iptables on

关闭防火墙注意

*) 如果要关闭iptables ,可以通过命令 /etc/init.d/iptables stop 停止
*) 也可以通过 service iptables stop 来停止

注意:
以上命令虽然关闭了iptables,但是如果设置了自动启动的话,iptables会自动开启(命令chkconfig查看系统自动启动进程)
[root@ssgao1987 bin]# chkconfig |grep iptables
iptables        0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭


'所以我们还要关闭自动启动,避免重启后又启动了防火墙'
[root@ssgao1987 bin]# chkconfig iptables off(设置自动启动为关闭 chkconfig --del iptables 移除开机自动启动)
[root@ssgao1987 bin]# chkconfig |grep iptables
iptables        0:关闭    1:关闭    2:关闭    3:关闭    4:关闭    5:关闭    6:关闭
然后停止防火墙(service iptables stop)
[root@ssgao1987 bin]# service iptables stop
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
[root@ssgao1987 bin]# service iptables status
iptables:未运行防火墙

防火墙打开某个端口

查看防火墙状态
[root@ssgao1987 bin]# service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
                                                                (表示目前防火墙开着,只接受外面的(本机外)22端口)
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source      
编辑/etc/sysconfig/iptables防火墙配置文件
*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
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT(打开2181端口)
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
重启防火墙: service iptables restatus
查看防火墙状态:
[root@ssgao1987 bin]# service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2181 
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination 

转载于:https://www.cnblogs.com/ssgao/p/8807330.html


http://www.niftyadmin.cn/n/735350.html

相关文章

JVM汇总--jvm调优-命令篇

2019独角兽企业重金招聘Python工程师标准>>> GC的最根本原因:垃圾收集器的工作就是清除Java创建的对象,垃圾收集器需要清理的对象数量以及要执行的GC数量均取决于已创建的对象数量。因此,为了使你的系统在GC上表现良好&#xff0c…

论文中积累的常用表达

To our best knowledge   据我们所知 Ideally,…   理想情况下 Specifically,…   具体来说 Accordingly,…   因此 With regard to   关于, 相对于 We also enforce that the following frames in a sequence must also be considered static with regard to t…

VScode一些快捷键的简记

全屏和退出   F11 调出终端   ctrl 选择所有出现的当前选择,可进行批量修改   ctrlshiftL 触发参数提示   ctrlshiftspace

python基础—函数式编程

函数式编程 1.不可变数据 2.第一类对象 3.尾调用优化(尾递归)  1.高阶函数 满足两个条件任意一个为高阶函数: 1.函数的传入参数是一个函数名 2.函数的返回值是一个函数 #非函数式 a 1 def test():global aa 1return a test() print(a)#函数…

Http 缓存: 强缓存与协商缓存

Http 缓存: 强缓存与协商缓存 文章目录Http 缓存: 强缓存与协商缓存简介参考完整示例代码正文Http 缓存机制:强缓存 & 协商缓存强缓存:Expires & Cache-ControlHttp 1.0:ExpiresHttp 1.1:Cache-Control协商缓存&#xff1…

Docker网络基础

目录 网络bridge网络none网络host网络端口端口绑定自定义网络网络 docker提供几种网络,它决定容器之是以及外界和容器之间怎么样去通信。 可以通过如下方法查看docker的网络: docker network ls null:无网络,使用这种网络的容器会…

CVPR 2022 Paper Reading List

Best Paper —— Learning to Solve Hard Minimal Problems Best Student Paper —— EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monocular Object Pose Estimation Best Student Paper Mention —— Ref-NeRF: Structured View-Dependent A…

基于OpenResty和Node.js的微服务架构实践

什么是微服务? 传统的单体服务架构是单独服务包,共享代码与数据,开发成本较高,可维护性、伸缩性较差,技术转型、跨语言配合相对困难。而微服务架构强调一个服务负责一项业务,服务可以单独部署,独…