当前位置: 首页 > 工具软件 > OpenFirewall > 使用案例 >

firewall

章飞章
2023-12-01

1.首先打开虚拟机,添加一块网卡,共两块网卡,启动虚拟机,分别为两块网卡配置ip

2.火墙图形管理界面:firewall-config

systemctl start firewall //保证火墙是打开的

3.使用命令行接口配置防火墙

 

基于用户对网络中设备和交通所给与的信任程度,防火墙可以用来将网络分割成不同的区域。

NetworkManager通知firewalld一个接口归属某个区域,新加入的接口被分配到默认区域。

网络区名称 默认配置

trusted( 信任 )   可接受所有的网络连接

home( 家庭 ) 用于家庭网络,仅接受ssh、mdns、ipp-client、samba-client、或dhcpv6-client服

务连接

internal( 内部 ) 用于内部网络,仅接受ssh、mdns、ipp-client、samba-client、dhcpv6-client服务

连接

work( 工作 ) 用于工作区,仅接受ssh、ipp-client或dhcpv6-client服务连接

public( 公共 ) 在公共区域内使用,仅接受ssh或dhcpv6-client服务连接,为firewalld的默认区域

external( 外部 ) 出去的ipv4网络连接通过此区域伪装和转发,仅接受ssh服务连接

dmz( 非军事区 ) 仅接受ssh服务接连

block( 限制 ) 拒绝所有网络连接

drop( 丢弃 ) 任何接收的网络数据包都被丢弃,没有任何回复

 

 

查看firewalld的状态:

# firewall-cmd --state

查看当前活动的区域,并附带一个目前分配给它们的接口列表:

# firewall-cmd --get-active-zones

查看默认区域:

# firewall-cmd --get-default-zone

查看所有可用区域:

# firewall-cmd --get-zones

列出指定域的所有设置:

# firewall-cmd --zone=public --list-all

列出所有预设服务:

# firewall-cmd --get-services

(这样将列出 /usr/lib/firewalld/services/ 中的服务器名称。注意:配置文件是以服务本身命名的

service-name. xml)

 

 

[root@firewall ~]# cd /usr/lib/firewalld/services/

[root@firewall services]# ls

amanda-client.xml      ipp-client.xml   mysql.xml       rpc-bind.xml

bacula-client.xml      ipp.xml          nfs.xml         samba-client.xml

bacula.xml             ipsec.xml        ntp.xml         samba.xml

dhcpv6-client.xml      kerberos.xml     openvpn.xml     smtp.xml

dhcpv6.xml             kpasswd.xml      pmcd.xml        ssh.xml

dhcp.xml               ldaps.xml        pmproxy.xml     telnet.xml

dns.xml                ldap.xml         pmwebapis.xml   tftp-client.xml

ftp.xml                libvirt-tls.xml  pmwebapi.xml    tftp.xml

high-availability.xml  libvirt.xml      pop3s.xml       transmission-client.xml

https.xml              mdns.xml         postgresql.xml  vnc-server.xml

http.xml               mountd.xml       proxy-dhcp.xml  wbem-https.xml

imaps.xml              ms-wbt.xml       radius.xml

只有更改文件名字才能更改相应服务的名字,更改配置文件内容不能更改服务名字

 

列出所有区域的设置:

# firewall-cmd --list-all-zones

设置默认区域:

# firewall-cmd --set-default-zone=dmz

设置网络地址到指定的区域:

# firewall-cmd --permanent --zone=public --add-source=172.25.254.60

(--permanent参数表示永久生效设置,如果没有指定--zone参数,那么会加入默认区域),添加主机ip可以在主机和虚拟机的浏览器中访问到,但是添加虚拟机的ip只能在虚拟机中访问到

 

删除指定区域中的网路地址:

# firewall-cmd --permanent --zone=public --remove-source=172.25.254.60/24

添加、改变、删除网络接口:

# firewall-cmd --permanent --zone=trusted --add-interface=eth0

# firewall-cmd --permanent --zone=trusted --change-interface=eth0

# firewall-cmd --permanent --zone=trusted --remove-interface=eth0

 

添加、删除服务:

# firewall-cmd --permanent --zone=public --add-service=smtp

# firewall-cmd --permanent --zone=public --remove-service=smtp

 

3。DIRECT RULES(直接端口模式)

通过 firewall-cmd 工具,可以使用 --direct 选项在运行时间里增加或者移除链。如果不熟悉 iptables ,使用直接接口非常危险,因为您可能无意间导致防火墙被入侵。直接端口模式适用于服务或者程序,以便在运行时间内增加特定的防火墙规则。直接端口模式添加的规则优先应用。

[root@direwall ~]#systemctl start iptables

[root@direwall ~]#iptables -nL

[root@direwall ~]#iptables -nL filter/nat

[root@direwall ~]#sysemctl restart firewalld

[root@direwall ~]#firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -p --dropt=80 -s 172.25.254.250 -j REJECT

[root@direwall ~]#firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -p --dropt=80 -s 172.25.254.250 -j DROP

[root@direwall ~]#firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -p --dropt=80 -s 172.25.254.250 -j ACCEPT

[root@direwall ~]#firewall-cmd --direct --get-all-rules

[root@direwall ~]#firewall-cmd --dd-masquerade

[root@direwall ~]#firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toport=22:toaddr=172.25.254.19

 

 

添加规则:

# firewall-cmd --direct --remove-rule ipv4 filter IN_public_allow 0 -p tcp --dport 80 -j ACCEPT

删除规则:

# firewall-cmd --direct --remove-rule ipv4 filter IN_public_allow 10 -p tcp --dport 80 -j ACCEPT

列出规则:

# firewall-cmd --direct --get-all-rules

 

第六单元:nfs文件的存储

 

nfs概念:网络文件系统(NFS)是UNIX系统和网络附加存储文件管理期常用的网络文件系统,允许多个客户端通过网络共享文件访问。他可用于提供对共享二进制目录的访问,也可允许用户u在同以工作组中从不同客户端访问其文件。

NFS协议有多个版本,linux支持版本4.版本3,和版本2,而大多数系统管理员熟悉的和iNFSv3.默认情况下,该协议并不安全,但是更新的版本提供了对安全的身分验证的支持,甚至可以通过kerberos进行加密。

[root@firewall ~]# yum install nfs-utils -y

[root@firewall ~]# systemctl start nfs

[root@firewall ~]# showmount -e 172.25.254.119

Export list for 172.25.254.119:

[root@firewall ~]# firewall-cmd --add-service=rpc-bind

success

[root@firewall ~]# firewall-cmd --add-service=mountd

success

[root@firewall ~]# firewall-cmd --reload

success

[root@firewall ~]# showmount -e 172.25.254.119

Export list for 172.25.254.119:

[root@firewall ~]# mkdir /westos //建立共享目录

[root@firewall ~]# vim /etc/exports

/westos *(ro) //共享的目录只有可读权限

[root@firewall ~]# exportfs -rv

exporting *:/westos

[root@firewall ~]# showmount -e 172.25.254.119

Export list for 172.25.254.119:

/westos *

[root@firewall ~]# mount 172.25.254.119:/westos /mnt

 

 

 

[root@firewall mnt]# touch file1

touch: cannot touch ‘file1’: Read-only file system //没有可写权限

[root@firewall mnt]# cd

[root@firewall ~]# vim /etc/exports

/westos *(rw) //共享的目录有可写权限

[root@firewall ~]# exportfs -rv

exporting *:/westos

[root@firewall ~]# cd /mnt

[root@firewall mnt]# touch file1

touch: cannot touch ‘file1’: Permission denied

[root@firewall mnt]# cd

[root@firewall ~]# chmod 777 /westos

[root@firewall ~]# cd /mnt

[root@firewall mnt]# touch file1

[root@firewall mnt]# ls

file1

 

 

[root@firewall mnt]# ll

total 0

-rw-r--r--. 1 nfsnobody nfsnobody 0 Mar 22 07:02 file1

[root@firewall mnt]# touch file2

[root@firewall mnt]# ll

total 0

-rw-r--r--. 1 nfsnobody nfsnobody 0 Mar 22 07:02 file1 //目录的所有人所有组为nfsnobody

-rw-r--r--. 1 nfsnobody nfsnobody 0 Mar 22 07:03 file2

[root@firewall mnt]# vim /etc/exports

/westos         *(rw,no_root_squash) //更改所有人所有组为root

 

[root@firewall mnt]# expotrtfs -rv

[root@firewall mnt]# touch file3

[root@firewall mnt]# ll

total 0

-rw-r--r--. 1 nfsnobody nfsnobody 0 Mar 22 07:02 file1

-rw-r--r--. 1 nfsnobody nfsnobody 0 Mar 22 07:03 file2

-rw-r--r--. 1 root    root      0 Mar 22 07:07 file3

 

 

[root@firewall ~]# mount -o vers=3 172.25.254.119:/westos /mnt //更改nfs的版本(3)

 

 类似资料:

相关阅读

相关文章

相关问答