[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