一.初识firewalld
1.出了点小故障防火墙文件找不到,解决方式如下:
[root@localhost ~]# yum install firewalld -y
[root@localhost ~]# systemctl unmask firewalld
[root@localhost ~]# systemctl enable firewalld
[root@localhost ~]# systemctl start firewalld
2.查找防火墙服务名的技巧
[root@localhost ~]# systemctl list-units |grep fire
firewalld.service loaded active running firewalld - dynamic firewall daemon
3.这个命令,其实是找到一个服务脚本文件
[root@localhost ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-11-07 04:41:25 CST; 2h 39min ago
Docs: man:firewalld(1)
Main PID: 112106 (firewalld)
CGroup: /system.slice/firewalld.service
└─112106 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
Nov 07 04:41:25 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 07 04:41:25 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 07 04:41:25 localhost.localdomain firewalld[112106]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration o...it now.
Hint: Some lines were ellipsized, use -l to show in full.
4.这个firewalld.service文件在哪?
[root@localhost ~]# find / -type f -name 'firewalld.service'
/usr/lib/systemd/system/firewalld.service
5.这个脚本,其实就是执行了运行防火墙命令的一个脚本文件 ,直接看这个脚本的,第11 12 13行
[root@localhost ~]# cat -n /usr/lib/systemd/system/firewalld.service
1 [Unit]
2 Description=firewalld - dynamic firewall daemon
3 Before=network-pre.target
4 Wants=network-pre.target
5 After=dbus.service
6 After=polkit.service
7 Conflicts=iptables.service ip6tables.service ebtables.service ipset.service
8 Documentation=man:firewalld(1)
9
10 [Service]
11 EnvironmentFile=-/etc/sysconfig/firewalld
12 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS
13 ExecReload=/bin/kill -HUP $MAINPID
14 # supress to log debug and er服务器托管网ror output also to /var/log/messages
15 StandardOutput=null
16 StandardError=null
17 Type=dbus
18 BusName=org.fedoraproject.FirewallD1
19 KillMode=mixed
20
21 [Install]
22 WantedBy=multi-user.target
23 Alias=dbus-org.fedoraproject.FirewallD1.service
6.使用防火墙命令,查看系统提供了哪些模板
列出区域模板,以及具体信息
[root服务器托管网@localhost ~]# firewall-cmd --help |grep list
[root@localhost ~]# firewall-cmd --list-all-zones
列出所有区域的名字
[root@localhost ~]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
列出当前使用的区域
[root@localhost ~]# firewall-cmd --get-default-zone
public
列出当前使用的区域,以及详细信息
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
7.先运行一个80端口的服务
[root@localhost ~]# python -m SimpleHTTPServer 80
8.给当前的防火墙区域,添加一个策略,允许80端口通过
[root@localhost ~]# firewall-cmd --add-port=80/tcp
success
就可以直接在浏览器上访问了,可以看到里面的文件
9.删除,添加的端口规则
[root@localhost ~]# firewall-cmd --remove-port=80/tcp
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
二.防火墙放行http服务
1.针对服务名添加,比如ntp服务
[root@localhost ~]# firewall-cmd --add-service=ntp
success
2.查看当前public区域,使用了哪些规则
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: dhcpv6-client ntp ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
3.firewalld,作用其实是添加iptables的规则
查看系统上所有iptables的命令
[root@localhost ~]# iptables -L
tcp 是一个安全可靠的连接,需要双向确认,客户端,和服务端,都要确认对方以及连接上了
udp 是一个不可靠的额连接协议,客户端可以随便给服务端发,不需要对方确认
比如一个很差的网络环境下,网页无法访问,无法做dns解析(网络服务,网站服务,用的都是tcp协议)
但是qq可以收发消息(qq用的是udp协议,以及ntp用的也是udp协议)
4.查看到firewalld命令,添加的防火墙规则如下
[root@localhost ~]# iptables -L |grep tcp
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate NEW,UNTRACKED
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
相关推荐: C++ 连接、操作postgreSQL(基于libpq库)
1.环境
2.数据库操作C++ 连接postgreSQL(基于libpq库) 1.环境 2.数据库操作 2.1. c++ 连接数据库 2.2. c++ 删除数据库属性表内容 2.3. c++ 插入数据库属性表内容 2.4 c++ 关闭数据库 1.环境 使用libpq库来链接postg…