Linux 使用firewall-cmd配置端口

Linux 使用firewall-cmd配置端口,第1张

使用firewall-cmd配置端口

(1)查看防火墙状态:

(2)重新加载配置:

(3)查看开放的端口:

(4)开启防火墙端口:

命令含义:

–zone #作用域

–add-port=9200/tcp #添加端口,格式为:端口/通讯协议

–permanent #永久生效,没有此参数重启后失效

注意:添加端口后,必须用命令firewall-cmd --reload重新加载一遍才会生效

(5)关闭防火墙端口:

修改防火墙配置需要修改

/etc/sysconfig/iptables

这个文件,如果要开放哪个端口,在里面添加一条。

-A

RH-Firewall-1-INPUT

-m

state

--state

NEW

-m

tcp

-p

tcp

--dport

1521

-j

ACCEPT

就可以了,其中

1521

是要开放的端口号,然后重新启动linux的防火墙服务。

停止/启动防火墙服务的命令:

用root登录后,执行

service

iptables

stop

--停止

service

iptables

start

--启动

(service命令位于/sbin)

防火墙规则只有在

iptables

服务运行的时候才能被激活。要手工启动服务,使用以下命令:

/sbin

rvice

iptables

restart

要确保它在系统引导时启动,使用以下命令:

/sbin/chkconfig

--level

345

iptables

on

ipchains

服务不能和

iptables

服务同时运行。要确定

ipchains

服务被禁用,执行以下命令:

/sbin/chkconfig

--level

345

ipchains

off

打开配置文件 

命令代码  

[root@localhost ~]# vi /etc/sysconfig/iptables   

正确的配置文件 

配置代码  

# 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    

-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT   

-A INPUT -j REJECT –reject-with icmp-host-prohibited    

-A FORWARD -j REJECT –reject-with icmp-host-prohibited    

COMMIT   

配置[*]通配代码  

-A INPUT -m state –state NEW -m tcp -p tcp –dport * -j ACCEPT  

注意点:新开放的端口一定要在端口22后面 

重启防火墙使配置生效 

命令代码  

[root@localhost ~]# /etc/init.d/iptables restart  

其它 

查看开放端口 

命令代码  

[root@localhost ~]# /etc/init.d/iptables status  

关闭防火墙 

命令代码  

[root@localhost ~]# /etc/init.d/iptables stop  


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/5942035.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-09
下一篇 2023-03-09

发表评论

登录后才能评论

评论列表(0条)

保存