[root@centos001 ~]# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ 肯定 ]
[root@centos001 ~]# iptables-save > /tmp/ipt.txt //保存 [root@centos001 ~]# iptables-restore < /tmp/ipt.txt //恢復
[root@centos001 ~]# systemctl disable iptables [root@centos001 ~]# systemctl stop iptables [root@centos001 ~]# systemctl enable firewalld Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service. Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service. [root@centos001 ~]# systemctl start firewalld
[root@centos001 ~]# firewall-cmd --get-zones block dmz drop external home internal public trusted work
[root@centos001 ~]# firewall-cmd --get-default-zone public //這裏能看到默認的zone是public
[root@centos001 ~]# firewall-cmd --set-default-zone=work//設定默認zone是,並查看 success [root@centos001 ~]# firewall-cmd --get-default-zone work
[root@centos001 ~]# firewall-cmd --get-zone-of-interface=lo no zone
[root@centos001 ~]# cd /etc/sysconfig/network-scripts/ //1.複製配置文件到網卡 [root@centos001 network-scripts]# ls ifcfg-e ifdown-ib ifdown-Team ifup-ippp ifup-sit ifcfg-ens ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team ifcfg-ens33 ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort ifcfg-ens33:0 ifdown-isdn ifup ifup-plip ifup-tunnel ifcfg-lo ifdown-post ifup-aliases ifup-plusb ifup-wireless ifdown ifdown-ppp ifup-bnep ifup-post init.ipv6-global ifdown-bnep ifdown-routes ifup-eth ifup-ppp network-functions ifdown-eth ifdown-sit ifup-ib ifup-routes network-functions-ipv6 [root@centos001 network-scripts]# cp ifcfg-ens33 ifcfg-ens37 [root@centos001 network-scripts]# vi /etc/sysconfig/network-scripts/ifcfg-ens37 //2.配置下這個文件 [root@centos001 network-scripts]# uuidgen ens37 //這裏是查詢uuid 0868ef08-a957-44d8-9554-c4966a7f0bf5 [root@centos001 network-scripts]# vi /etc/sysconfig/network-scripts/ifcfg-ens37 [root@centos001 network-scripts]# systemctl restart network.service //3.重啓網絡服務 Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details. [root@centos001 network-scripts]# systemctl restart firewalld //4.重啓firewalld服務 [root@centos001 network-scripts]# firewall-cmd --get-zone-of-interface=ens37 //5.從新運行查看網卡的zone no zone //這裏出錯了 坑能是咱們網絡環境的問題
[root@centos001 network-scripts]# firewall-cmd --zone=public --add-interface=lo //設定並查看 success [root@centos001 network-scripts]# firewall-cmd --get-zone-of-interface=lo public
[root@centos001 network-scripts]# firewall-cmd --zone=block --change-interface=lo //修改並查看 success [root@centos001 network-scripts]# firewall-cmd --get-zone-of-interface=lo block
[root@centos001 network-scripts]# firewall-cmd --zone=block --remove-interface=lo success [root@centos001 network-scripts]# firewall-cmd --get-zone-of-interface=lo no zone
firewall-cmd --get-active-zones //查看系統全部網卡所在的zone
firewall-cmd --get-services 查看全部的servies
-查看當前zone下有哪些servicecentos
[root@centos001 network-scripts]# firewall-cmd --get-default-zone //查看當前的zone是什麼 work [root@centos001 network-scripts]# firewall-cmd --list-services ssh dhcpv6-client
[root@centos001 network-scripts]# firewall-cmd --zone=public --list-service dhcpv6-client ssh http
[root@centos001 network-scripts]# firewall-cmd --zone=public --add-service=http success [root@centos001 network-scripts]# firewall-cmd --zone=public --list-service dhcpv6-client ssh http
[root@centos001 network-scripts]# firewall-cmd --zone=public --add-service=http --permanent success [root@centos001 network-scripts]# ls /etc/firewalld/zones/public.xml //保存的路徑 /etc/firewalld/zones/public.xml [root@centos001 network-scripts]# ls /etc/firewalld/zones/ public.xml public.xml.old [root@centos001 network-scripts]# cat /etc/firewalld/zones/public.xml <?xml version="1.0" encoding="utf-8"?> <zone> <short>Public</short> <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> <service name="dhcpv6-client"/> <service name="ssh"/> <service name="http"/> //能看到咱們添加的service </zone>
ls /usr/lib/firewalld/zones/
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services
<?xml version="1.0" encoding="utf-8"?> <service> <short>FTP</short> <description>FTP is a protocol used for remote file transfer. If you plan to make your FTP server publicly available, enable this option. You need the vsftpd package installed for this option to be useful.</description> <port protocol="tcp" port="1121"/> //這裏修改成1121 <module name="nf_conntrack_ftp"/> </service>
cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
<?xml version="1.0" encoding="utf-8"?> <zone> <short>Work</short> <description>For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> <service name="ssh"/> <service name="dhcpv6-client"/> <service name="ftp"/> </zone>
[root@centos001 ~]# firewall-cmd --reload success
[root@centos001 ~]# firewall-cmd --zone=work --list-services ssh dhcpv6-client ftp //新添加的ftp