本文共 4391 字,大约阅读时间需要 14 分钟。
保存和备份iptables规则
service iptables save
//会把规则保存到/etc/sysconfig/iptables
把iptables规则备份到my.ipt文件中iptables-save > my.ipt
恢复刚才备份的规则iptables-restore < my.ipt
打开firewalld
systemctl disable iptablessystemctl stop iptablessystemctl enable firewalldsystemctl start firewalld
firewalld默认有9个zone
默认zone为publicfirewall-cmd --get-zones
//查看所有zone [root@test221 ~]# firewall-cmd --get-zones block dmz drop external home internal public trusted work
firewall-cmd --get-default-zone
//查看默认zone
[root@test221 ~]# firewall-cmd --get-default-zone public
drop(丢弃):任何接收的网络数据包都被丢弃,没有任何回复。仅能有发送出去的网络连接。
block(限制):任何接收的网络连接都被IPv4的icmp-host-prohibited信息和IPv6的icmp-adm-prohibited信息所拒绝。
public (公共):在公共区域内使用,不能相信网络内的其他计算机不会对你的计算机造成危害,只能接收经过选取的连接。
external(外部):特别是为路由器启用了伪装功能的外部网。你不能信任来自网络的其他计算,不能相信它们不会对你的计算机造成危害,只能接收经过选择的连接。
dmz(非军事区):用于你的非军事区内的计算机,此区域内可公开访问,可以有限的进入你的内部网络,仅仅接收经过选择的连接。
work(工作):用于家庭网络。你可以基本相信网络内的其他计算机不会危害你的计算机。仅仅接收经过选择的连接。
home(家庭):用于家庭网络。你可以基本信任网络内的其他计算机不会危害你的计算机。仅仅接收经过选择的连接。
internal(内部):用于内部网络。你可以基本上信任网络内的其他计算机不会威胁你的计算机。仅仅接受经过选择的连接。
trust(信任):可接受所有的网络连接。
firewall-cmd --set-default-zone=work //设定默认zone
[root@test221 ~]# firewall-cmd --set-default-zone=work success[root@test221 ~]# firewall-cmd --set-default-zone=publicsuccess
firewall-cmd --get-zone-of-interface=eth0 //查指定网卡
[root@test221 ~]# firewall-cmd --get-zone-of-interface=eth0public
firewall-cmd --zone=public --add-interface=lo //给指定网卡设置zone
[root@test221 ~]# firewall-cmd --zone=public --add-interface=losuccess
firewall-cmd --zone=dmz --change-interface=lo //针对网卡更改zone
[root@test221 ~]# firewall-cmd --zone=dmz --change-interface=lo success
firewall-cmd --zone=dmz --remove-interface=lo //针对网卡删除zone
[root@test221 ~]# firewall-cmd --zone=dmz --remove-interface=lo success
firewall-cmd --get-active-zones //查看系统所有网卡所在的zone
[root@test221 ~]# firewall-cmd --get-active-zones public interfaces: eth0 eth1trusted
firewall-cmd --get-services 查看所有的servies
[root@test221 ~]# firewall-cmd --get-servicesRH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master high-availability http https imap imaps ipp ipp-client ipsec iscsi-target kadmin kerberos kibana klogin kpasswd kshell ldap ldaps libvirt libvirt-tls managesieve mdns mosh mountd ms-wbt mssql mysql nfs nrpe ntp open*** ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server
firewall-cmd --list-services //查看当前zone下有哪些service
[root@test221 ~]# firewall-cmd --list-services dhcpv6-client ssh
firewall-cmd --zone=public --add-service=http //把http增加到public zone下面
[root@test221 ~]# firewall-cmd --zone=public --add-service=http success
firewall-cmd --zone=public --remove-service=http 移除public下的http服务
[root@test221 ~]# firewall-cmd --zone=public --remove-service=httpsuccess
ls /usr/lib/firewalld/zones/ //zone的配置文件模板
[root@test221 ~]# ls /usr/lib/firewalld/zones/ block.xml drop.xml home.xml public.xml work.xmldmz.xml external.xml internal.xml trusted.xml
firewall-cmd --zone=public --add-service=http --permanent //更改配置文件,之后会在/etc/firewalld/zones目录下面生成配置文件
[root@test221 ~]# firewall-cmd --zone=public --add-service=http --permanentsuccess
需求:ftp服务自定义端口1121,需要在work zone下面放行ftp
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services 复制服务配置文件vi /etc/firewalld/services/ftp.xml //把21改为1121cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/ 复制zone配置文件vi /etc/firewalld/zones/work.xml //增加一行<service name="ftp"/>firewall-cmd --reload //重新加载[root@test221 ~]# firewall-cmd --reload success
firewall-cmd --zone=work --list-services 查看work zone下的服务
[root@test221 ~]# firewall-cmd --zone=work --list-servicesssh dhcpv6-client
转载于:https://blog.51cto.com/235571/2113763