iptables规则备份和恢复、firewall的zone的操作、service的操作

iptables规则备份和恢复

保存和备份iptables规则如下:

service iptables save //会把规则保存到/etc/sysconfig/iptables

把iptables规则备份到my.ipt文件中

 iptables-save > my.ipt

 恢复刚才备份的规则

 iptables-restore < my.ipt


实验:

[root@test-7 ~]# iptables-save > my.ipt

[root@test-7 ~]# iptables -t nat -F  #清空

[root@test-7 ~]# iptables -t nat -nvL #查看下

Chain PREROUTING (policy ACCEPT 2 packets, 406 bytes)

 pkts bytes target     prot opt in     out     source               destination         


Chain INPUT (policy ACCEPT 2 packets, 406 bytes)

 pkts bytes target     prot opt in     out     source               destination         


Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)

 pkts bytes target     prot opt in     out     source               destination         


Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)

 pkts bytes target     prot opt in     out     source               destination         


Chain OUTPUT_direct (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain POSTROUTING_ZONES (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain POSTROUTING_ZONES_SOURCE (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain POSTROUTING_direct (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain POST_public (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain POST_public_allow (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain POST_public_deny (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain POST_public_log (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain PREROUTING_ZONES (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain PREROUTING_ZONES_SOURCE (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain PREROUTING_direct (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain PRE_public (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain PRE_public_allow (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain PRE_public_deny (0 references)

 pkts bytes target     prot opt in     out     source               destination         


Chain PRE_public_log (0 references)

 pkts bytes target     prot opt in     out     source               destination         

[root@test-7 ~]# iptables-restore < my.ipt #恢复

[root@test-7 ~]# iptables -t nat -nvL  #查看下,数据又回来了

Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)

 pkts bytes target     prot opt in     out     source               destination         

    0     0 DNAT       tcp  --  *      *       0.0.0.0/0            192.168.100.102      tcp dpt:1122 to:192.168.133.2:22


Chain INPUT (policy ACCEPT 0 packets, 0 bytes)

 pkts bytes target     prot opt in     out     source               destination         


Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)

 pkts bytes target     prot opt in     out     source               destination         


Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)

 pkts bytes target     prot opt in     out     source               destination         

    0     0 SNAT       all  --  *      *       192.168.133.2        0.0.0.0/0            to:192.168.100.102



firewalld的9个zone

1、查看zone类型:

[root@test-7 ~]# firewall-cmd --get-zones

block dmz drop external home internal public trusted work


关于9种zone的解析:

image.png

查看默认的zone:

[root@test-7 ~]# firewall-cmd --get-default-zone

public

firewalld关于zone的操作

1、设置

[root@test-7 ~]# firewall-cmd --set-default-zone=work

success

2、查看

[root@test-7 ~]# firewall-cmd --get-default-zone 

work

3、查看网卡的zone

[root@test-7 ~]# firewall-cmd --get-zone-of-interface=eno16777736

work


给指定的网卡增加zone


更改zone:

firewall-cmd --zone=block --change-interface=eno16777736


查看:

[root@test-7 ~]# firewall-cmd --get-zone-of-interface=eno16777736

block

删除zone

[root@test-7 ~]# firewall-cmd --zone=block --remove-interface=eno16777736

success

查看所有网卡的zone

[root@test-7 ~]# firewall-cmd --get-active-zones

work

  interfaces: eno33554984


firewalld关于service的操作

1、查看系统所有的service

firewall-cmd --get-services

RH-Satellite-6 amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns freeipa-ldap freeipa-ldaps freeipa-replication ftp high-availability http https imaps ipp ipp-client ipsec iscsi-target kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind rsyncd samba samba-client smtp ssh telnet tftp tftp-client transmission-client vdsm vnc-server wbem-https


2、查看当前zone下的service

[root@test-7 ~]# firewall-cmd --list-services 

dhcpv6-client ipp-client ssh


3、查看指定zone下的service

[root@test-7 ~]# firewall-cmd --zone=public --list-services 

dhcpv6-client ssh


添加一个服务到某个zone下


一、临时添加(配置文件中不存在,重启会恢复原配置)

[root@test-7 ~]# firewall-cmd --zone=public --add-service=http

success

查看:

[root@test-7 ~]# firewall-cmd --zone=public --list-services 

dhcpv6-client http ssh

二、永久添加

[root@test-7 ~]# firewall-cmd --zone=public --add-service=http --permanent

success


临时删除

1、

[root@test-7 ~]# firewall-cmd --zone=public --remove-service=ssh

success

[root@test-7 ~]# firewall-cmd --zone=public --list-service

dhcpv6-client http


2、[root@test-7 ~]# firewall-cmd --zone=public --remove-service=ftp --permanent













本文转自方向对了,就不怕路远了!51CTO博客,原文链接:http://blog.51cto.com/jacksoner/2046630 ,如需转载请自行联系原作者


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在linux中使用iptables清空所有规则可以使用以下命令: ``` iptables -F iptables -X iptables -t nat -F iptables -t nat -X iptables -t mangle -F iptables -t mangle -X iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT ``` - `iptables -F` 清除所有链的规则。 - `iptables -X` 删除自定义的链。 - `iptables -t nat -F` 清除nat表中的所有规则。 - `iptables -t nat -X` 删除nat表中的自定义链。 - `iptables -t mangle -F` 清除mangle表中的所有规则。 - `iptables -t mangle -X` 删除mangle表中的自定义链。 - `iptables -P INPUT ACCEPT` 设置默认的输入链为接受状态。 - `iptables -P FORWARD ACCEPT` 设置默认的转发链为接受状态。 - `iptables -P OUTPUT ACCEPT` 设置默认的输出链为接受状态。 恢复默认规则也可以使用一条命令: ``` iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT ``` 默认规则为接受所有流量。 注意:上述操作会永久清空规则,在重启后还需重新配置规则。 ### 回答2: 要清空所有的iptables规则恢复默认规则,可以按照以下步骤进行操作: 1. 首先,我们需要以root身份登录到Linux服务器上。在终端或SSH会话中输入以下命令以切换到root用户: ``` sudo su ``` 2. 为了确保清空所有规则恢复默认规则,我们首先需要查看当前的iptables规则。输入以下命令以显示当前的iptables规则: ``` iptables -L -v ``` 3. 下一步,我们需要清空所有的iptables规则。输入以下命令以清空所有的规则: ``` iptables -F ``` 这将删除所有的规则,但保留所有的链和默认策略。 4. 接下来,我们需要恢复默认规则。输入以下命令以恢复默认规则: ``` iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT ``` 这将将默认策略更改为接受所有的输入、转发和输出流量。 5. 最后,我们可以再次输入以下命令来确认iptables规则已被清空并恢复默认规则: ``` iptables -L -v ``` 如果输出中不再显示任何规则,则表示已成功清空所有规则恢复默认规则。 请注意,在清空所有规则恢复默认规则之前,请确保您了解当前的iptables设置和规则,并确保不会导致任何网络安全问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值