admin管理员组文章数量:1642334
- 设置前要知道default zone和所有网卡的zone,因为设置都是根据zone来设置;zone设置成你想要的样子,然后相应的网卡是在zone里,网卡就实施zone的规则;
- 默认在使用的网卡都是public,其他一些网卡是没有zone;
- 所以设置public就影响了在用的网卡;
- 修改default-zone是public, 修改default-zone变成block,原来是public zone的网卡变成block zone;
- 修改后要确认一下操作是否生效,使用list之类,如果没有生效就reload或重启服务;
[root@tanyvlinux zones]# firewall-cmd --get-zones #查看所有zones;
block dmz drop external home internal public trusted work
[root@tanyvlinuxn2 ~]# firewall-cmd --get-default-zone
public
[root@tanyvlinuxn2 ~]# firewall-cmd --get-zone-of-interface=ens33
public
[root@tanyvlinuxn2 ~]# firewall-cmd --get-zone-of-interface=ens37
public
[root@tanyvlinuxn2 ~]# firewall-cmd --get-zone-of-interface=ens38
no zone
[root@tanyvlinuxn2 ~]# firewall-cmd --get-zone-of-interface=lo
no zone
[root@tanyvlinuxn2 ~]# firewall-cmd --get-zone-of-interface=virbr0
no zone
- 如果要对所有网卡作不同的规则设置,就要规划好哪个网卡使用哪个zone;
[root@tanyvlinuxn2 ~]# firewall-cmd --set-default-zone=block
success #修改default-zone,原来public-zone网卡受影响;
[root@tanyvlinuxn2 ~]# firewall-cmd --get-zone-of-interface=ens33
block
[root@tanyvlinux zones]# firewall-cmd --zone=public --add-interface=lo #添加网卡到一个zone;
success
[root@tanyvlinux zones]# firewall-cmd --zone=dmz --change-interface=lo #改变网卡的zone;
[root@tanyvlinux zones]# firewall-cmd --get-active-zones #查看活动的zone和对应的接口;
dmz
interfaces: lo
public
interfaces: ens33 ens37
[root@tanyvlinux zones]# firewall-cmd --zone=dmz --remove-interface=lo #从一个zone中删除网卡;
success
- 修改时可以针对service或端口作出修改,如果不清楚端口情况,就使用service会较好,自动开放好相应的端口;清楚端口可直接对端口指定规则;
[root@tanyvlinux zones]# firewall-cmd --get-services #查看所有services;
RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry docker-swarm dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target jenkins kadmin kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls managesieve mdns minidlna mongodb mosh mountd ms-wbt mssql murmur mysql nfs nfs3 nmea-0183 nrpe ntp openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius redis rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh syncthing syncthing-gui synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server
[root@tanyvlinux zones]# firewall-cmd --list-services #当前zone放行的services;
ssh dhcpv6-client ftp
[root@tanyvlinux zones]# firewall-cmd --zone=public --add-service=http
#临时增加services,重启后需要重新添加;
success
[root@tanyvlinux zones]# firewall-cmd --zone=public --remove-service=http #删除services;
success
[root@tanyvlinux zones]# firewall-cmd --zone=public --add-service=http --permanent
#使用permanent参数后,修改更新在配置文件里,重启后也会加载;
success
[root@tanyvlinuxn2 ~]# firewall-cmd --zone=block --add-port=80/tcp #添加端口;
success
[root@tanyvlinuxn2 ~]# firewall-cmd --zone=block --list-port #列出zone的端口;
80/tcp
[root@tanyvlinuxn2 ~]# firewall-cmd --zone=block --remove-port=80/tcp
success #删除一个开放的端口;
-
端口服务两者修改效果是一样的,但是用服务修改的条目,可能在端口上没有显示,如开通http,list 端口规则是没有80的,但实际是生效的;在端口上作出的修改,在服务里也不一定有显示,如开通80,list服务没有显示http;用服务更保险;
-
放行端口的两个协议;
[root@tanyvlinux ~]# firewall-cmd --zone=public --add-port=8730/udp --permanent
success
[root@tanyvlinux ~]# firewall-cmd --zone=public --add-port=8730/tcp --permanent
success
[root@tanyvlinux ~]# firewall-cmd --reload
success
[root@tanyvlinux ~]# firewall-cmd --zone=public --list-ports
80/tcp 8730/udp 8730/tcp
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="192.168.1.188" port port=20-21 protocol=tcp accept' #开通某一个IP访问20-21端口;
firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop'
#不能被ping的设置;
- 电脑A内网外网两个网卡,电脑B只有内网网卡,电脑B通过电脑A连接外网;
A:
1、设置IP地址伪装
firewall-cmd --zone=public --add-masquerade --permanent #外网网卡的zone添加masquerade;
firewall-cmd --remove-masquerade --permanent #取消的命令
2、添加规则
firewall-cmd --direct --passthrough ipv4 -t nat -A POSTROUTING -o ens33 -s 172.16.92.0/24 -j MASQUERADE
3、重载Firewall使配置生效
firewall-cmd --reload
- 端口映射(可实现通过一台机器A的1122端口访问另外一台机器B的ssh服务即22端口
也不需要设置转发;
添加规则
firewall-cmd --zone=public --add-forward-port=port=1122:proto=tcp:toport=22:toaddr=172.16.92.154 --permanent
firewall-cmd --reload
firewall-cmd --list-all #查看zone的所有规则;
firewall-cmd --list-all-zones #查看所有zone的所有规则;
firewall-cmd --zone=public --remove-forward-port=port=1122:proto=tcp:toport=22:toaddr=172.16.92.154 --permanent #取消的命令;
第三方可访问A的1122端口,连接到B
ssh root@192.168.31.128 -p 1122
一般应用应该足够了
版权声明:本文标题:firewall-cmd使用 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1729336464a1197047.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论