CentOS firewall operation commands

CentOS firewall operation commands 

1. Check the firewall service status

systemctl status firewalld.service

 Or check the status of the firewall:

1

firewall-cmd --state

  

2. Turn on and restart the firewall

Start firewall:

1

systemctl start firewalld.service

Set auto-start or disable at boot:

1

systemctl enable/disable firewalld.service

Restart the firewall:

1

systemctl restart firewalld.service

 

3. Check the firewall settings to see if the auto-start is successful: 

1

systemctl is-enabled firewalld.service

  

4. Turn off the firewall

Turn off running firewall

1

systemctl stop firewalld.service

  

Permanently disable the firewall service and it will not be enabled next time you reboot.

1

systemctl disable firewalld.service

  

5. Open a specific port

Take port 80 as an example

1

2

3

4

5

6

7

8

9

10

11

12

开端口命令:firewall-cmd --zone=public --add-port=80/tcp --permanent

重启防火墙:systemctl restart firewalld.service

关端口命令:firewall-cmd --zone=public --remove-port=80/tcp --permanent

命令含义:

firwall-cmd:是Linux提供的操作firewall的一个工具;

--zone #作用域

  

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

  

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

  

  

6. View all open ports

1

firewall-cmd --zone=public --list-ports(查看防火墙通过的端口)<br><br>netstat -ntlp //查看网络运行情况

  

7. View firewall rules

1

firewall-cmd --list-all

 

8. Restrict access to only specified IPs (it can also be done without restrictions within the internal network, but cannot be accessed from the external network)

1

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.1/32" port protocol="tcp" port="3306" accept"<br><br>将 accept 设置为 reject表示拒绝,设置为 drop表示直接丢弃(会返回timeout连接超时)

 

9. Remove this strategy

1

firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="3306" accept"

  

 10. Reload

firewall-cmd --reload

reference:

CentOS7 opens the firewall and specific ports_centos7 opens the firewall port_Zheng Lulu's blog-CSDN blog

Set to allow the specified port to pass through the firewall centos7_qq_40084534's blog-CSDN blog

https://www.cnblogs.com/xxoome/p/7115614.html

http://www.linuxcache.com/archives/3896

http://www.woniu.me/2017/12/08/CentOS7%E4%B9%8B%E9%98%B2%E7%81%AB%E5%A2%99(firewall)%E9%85%8D%E7%BD%AE.html

 

Guess you like

Origin blog.csdn.net/lqzixi/article/details/131748937