儲存和備份iptables規則及firewalld防火牆
1. 儲存和備份iptables規則
儲存規則的命令是“service iptables save”,它會將防火牆規則儲存到/etc/sysconfig/iptables檔案內,這個檔案就是iptables的配置檔案。
備份規則的命令是“iptables-save > filename”,而恢復規則的命令是“iptables-restore < filename”,其中,filename指檔名;
[[email protected] ~]# iptables-save > /usr/myipt.rule #備份規則至/usr/myipt.rule [[email protected]
~]# iptables -F #刪除規則 [[email protected] ~]# iptables -nvL Chain INPUT (policy ACCEPT 11 packets, 768 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 7 packets, 740 bytes) pkts bytes target prot opt in out source destination [[email protected] ~]# iptables-restore < /usr/myipt.rule #從/usr/myipt.rule恢復規則 [[email protected] ~]# iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 7 468 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 5 packets, 588 bytes) pkts bytes target prot opt in out source destination
2. firewalld防火牆
因為在之前,禁用了firewalld服務,現在需要重新開啟,執行的命令如下:
[[email protected] ~]# systemctl disable iptables
Removed symlink /etc/systemd/system/basic.target.wants/iptables.service.
[[email protected] ~]# systemctl stop iptables
[[email protected] ~]# 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.
[[email protected] ~]# systemctl start firewalld
在開啟firewalld服務之前,需要先將iptables服務關閉;
關閉之後,檢視firewalld的預設規則,會發現這些規則要比netfilter的規則複雜;
[[email protected] ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
12 924 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
1 92 INPUT_direct all -- * * 0.0.0.0/0 0.0.0.0/0
1 92 INPUT_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0
1 92 INPUT_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate INVALID
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_direct all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_IN_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_IN_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_OUT_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_OUT_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate INVALID
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT 12 packets, 1224 bytes)
pkts bytes target prot opt in out source destination
12 1224 OUTPUT_direct all -- * * 0.0.0.0/0 0.0.0.0/0
Chain FORWARD_IN_ZONES (1 references)
pkts bytes target prot opt in out source destination
0 0 FWDI_public all -- ens37 * 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 FWDI_public all -- ens33 * 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 FWDI_public all -- + * 0.0.0.0/0 0.0.0.0/0 [goto]
Chain FORWARD_IN_ZONES_SOURCE (1 references)
pkts bytes target prot opt in out source destination
Chain FORWARD_OUT_ZONES (1 references)
pkts bytes target prot opt in out source destination
0 0 FWDO_public all -- * ens37 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 FWDO_public all -- * ens33 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 FWDO_public all -- * + 0.0.0.0/0 0.0.0.0/0 [goto]
Chain FORWARD_OUT_ZONES_SOURCE (1 references)
pkts bytes target prot opt in out source destination
Chain FORWARD_direct (1 references)
pkts bytes target prot opt in out source destination
Chain FWDI_public (3 references)
pkts bytes target prot opt in out source destination
0 0 FWDI_public_log all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FWDI_public_deny all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FWDI_public_allow all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
Chain FWDI_public_allow (1 references)
pkts bytes target prot opt in out source destination
Chain FWDI_public_deny (1 references)
pkts bytes target prot opt in out source destination
Chain FWDI_public_log (1 references)
pkts bytes target prot opt in out source destination
Chain FWDO_public (3 references)
pkts bytes target prot opt in out source destination
0 0 FWDO_public_log all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FWDO_public_deny all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FWDO_public_allow all -- * * 0.0.0.0/0 0.0.0.0/0
Chain FWDO_public_allow (1 references)
pkts bytes target prot opt in out source destination
Chain FWDO_public_deny (1 references)
pkts bytes target prot opt in out source destination
Chain FWDO_public_log (1 references)
pkts bytes target prot opt in out source destination
Chain INPUT_ZONES (1 references)
pkts bytes target prot opt in out source destination
0 0 IN_public all -- ens37 * 0.0.0.0/0 0.0.0.0/0 [goto]
1 92 IN_public all -- ens33 * 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 IN_public all -- + * 0.0.0.0/0 0.0.0.0/0 [goto]
Chain INPUT_ZONES_SOURCE (1 references)
pkts bytes target prot opt in out source destination
Chain INPUT_direct (1 references)
pkts bytes target prot opt in out source destination
Chain IN_public (3 references)
pkts bytes target prot opt in out source destination
1 92 IN_public_log all -- * * 0.0.0.0/0 0.0.0.0/0
1 92 IN_public_deny all -- * * 0.0.0.0/0 0.0.0.0/0
1 92 IN_public_allow all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
Chain IN_public_allow (1 references)
pkts bytes target prot opt in out source destination
1 92 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 ctstate NEW
Chain IN_public_deny (1 references)
pkts bytes target prot opt in out source destination
Chain IN_public_log (1 references)
pkts bytes target prot opt in out source destination
Chain OUTPUT_direct (1 references)
pkts bytes target prot opt in out source destination
firewalld有兩個概念需要注意,分別是zone和service,每一個zone裡面有不同的iptables規則,預設一共有9個zone,CentOS預設的zone為public。
[[email protected] ~]# firewall-cmd --get-zones #獲取系統所有的zone
block dmz drop external home internal public trusted work
[[email protected] ~]# firewall-cmd --get-default-zone #檢視系統預設的zone
public
9個zone:
1)drop(丟棄):任何收到的網路資料包都被丟棄,沒有任何回覆。僅能有傳送出去的網路連線;
2)block(限制):任何接受的網路連線都被IPv4的icmp-host-prohibited資訊和IPv6的icmp6-adm-prohibited資訊所拒絕;
3)public(公共):在公共區域內使用,不能相信網路內的其它計算機不會對你的計算機造成危害,只能接受進過選取的連線;
4)external(外部):特別是為路由器啟用了偽裝功能的外部網,你不能信任來自網路的其他計算,不能相信它們不會對你的計算機造成危害,只能接受經過選擇的連線;
5)dmz(非軍事區):用於你的非軍事區內計算機,此區域內可公開訪問,可以有限地進入你的內部網路,僅僅接受經過選擇的連線;
6)work(工作):用於工作區,你可以基本相信網路內的其它計算機不會危害你的計算機,僅僅接受經過選擇的連線;
7)home(家庭):用於家庭網路,你可以基本上信任網路內的其它計算機不會威脅你的計算機,僅僅接受經過選擇的連線;
8)internal(內部):用於內部網路,你可以基本上信任網路內的其它計算機不會危害你的計算機,僅僅接受經過選擇的連線;
9)trusted(信任):可接受所有的網路連線。
2.1 zone的操作
修改預設的zone為work;
[[email protected] ~]# firewall-cmd --set-default-zone=work
success
[[email protected] ~]# firewall-cmd --get-default-zone
work
檢視指定網絡卡所在的zone;
[[email protected] ~]# firewall-cmd --get-zone-of-interface=ens33
work
[[email protected] ~]# firewall-cmd --get-zone-of-interface=ens37
work
[[email protected] ~]# firewall-cmd --get-zone-of-interface=lo
no zone
給指定網絡卡設定zone;
[[email protected] ~]# firewall-cmd --zone=public --add-interface=lo
success
[[email protected] ~]# firewall-cmd --get-zone-of-interface=lo
public
針對網絡卡更改zone;
[[email protected] ~]# firewall-cmd --zone=dmz --change-interface=lo
success
[[email protected] ~]# firewall-cmd --get-zone-of-interface=lo
dmz
針對網絡卡刪除zone;
[[email protected] ~]# firewall-cmd --zone=dmz --remove-interface=lo
success
[[email protected] ~]# firewall-cmd --get-zone-of-interface=lo
no zone
檢視系統所有網絡卡所在的zone;
[[email protected] ~]# firewall-cmd --get-active-zones
work
interfaces: ens33
2.2 service的操作
檢視所有的services,加不加‘s’都可以;
[[email protected] ~]# firewall-cmd --get-services
RH-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 openvpn 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
[[email protected] ~]# firewall-cmd --get-service
RH-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 openvpn 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
檢視當前zone下有哪些service;
[[email protected] ~]# firewall-cmd --list-services
ssh dhcpv6-client
把http新增到public zone下面;
[[email protected] ~]# firewall-cmd --zone=public --add-service=http
success
[[email protected] ~]# firewall-cmd --zone=public --list-services
ssh dhcpv6-client http
這些service都是由一個個配置檔案定義的,配置檔案的模板在/usr/lib/firewalld/zones/目錄下,真正生效的配置在/etc/firewalld/services目錄下面(預設為空);
[[email protected] ~]# ls /usr/lib/firewalld/zones/
block.xml dmz.xml drop.xml external.xml home.xml internal.xml public.xml trusted.xml work.xml
ftp服務自定義埠1121,需要在work zone下放行ftp:
[[email protected] ~]# cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services
[[email protected] ~]# vim /etc/firewalld/services/ftp.xml
把預設的21埠改為1121埠,如下:<?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"/>
<module name="nf_conntrack_ftp"/>
</service>
[[email protected] ~]# cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
[[email protected] ~]# vim /etc/firewalld/zones/work.xml
增加一行“<service name="ftp"/>”;
<?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>
重新載入,可以看到work zone下面多了一個ftp。
[[email protected] ~]# firewall-cmd --reload
success
[[email protected] ~]# firewall-cmd --zone=work --list-services
ssh dhcpv6-client ftp
相關推薦
儲存和備份iptables規則及firewalld防火牆
1. 儲存和備份iptables規則儲存規則的命令是“service iptables save”,它會將防火牆規則儲存到/etc/sysconfig/iptables檔案內,這個檔案就是iptables的配置檔案。備份規則的命令是“iptables-save > fi
iptables nat表應用,儲存和備份規則
一、iptables nat表應用 需求1: 兩臺機器,機器A可以訪問內網和外網(兩塊網絡卡),機器B只能訪問內網(一塊網絡卡),讓機器B通過機器A實現訪問外網的功能 1. 先將兩個虛擬機器A和B各新增一個張網絡卡, A機器的一張網絡卡可以訪問外網,第二張新增的網
CentOS新增 iptables規則及註冊事項
開放一個埠 iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 開放一個IP iptables -A INPUT -s 192.168.0.5 -j ACCEPT 開
iptables規則備份和恢復 及firewalld用法
roc fff oss ado process mage blog service one 10.19 iptables規則備份和恢復 10.20 firewalld的9個zone 10.21 firewalld關於zone的操作 10.22 firewal
10.19-10.22 iptables規則備份和恢10.20 firewalld的9個zone
iptables 規則 備份 10.19 iptables規則備份和恢復 10.20 firewalld的9個zone 10.21 firewalld關於zone的操作 10.22 firewalld關於service的操作 # 10.19 iptables 規則備份和恢復 - 保存和
iptables規則備份和恢復,firewalld的9個zone,firewalld關於zone的操作,firewalld關於service的操作
firewalld service zone iptables 筆記內容:l 10.19 iptables規則備份和恢復l 10.20 firewalld的9個zonel 10.21 firewalld關於zone的操作l 10.22 firewalld關於service的操作筆記日期:201
10.19 iptables規則備份和恢復 10.20 firewalld的9個zone 10.21
nag image 分享圖片 lld color cto .com shadow images 七周五次課10.19 iptables規則備份和恢復10.20 firewalld的9個zone10.21 firewalld關於zone的操作10.22 firewalld關於
10.19 iptables規則備份和恢復 10.20 firewalld
com table boa bold images 打開 chan 過濾 conf 10.19 iptables規則備份和恢復Linux防火墻—netfilter1. iptables規則保存:默認規則保存到:/etc/sysconfig/iptables文件中。[root
iptables規則備份和恢復 | firewalld
定義 rap systemd firewall fff color asi finish wall 10.19 iptables規則備份和恢復 備份(另存為) 命令:iptables-save [root@centos-01 ~]# iptables-save > /
iptables規則備份和恢復/firewalld的9個zone
sta disable 選擇 啟用 hang 發送 art 加載 lld iptables規則備份和恢復 iptables規則保存,默認保存的位置路徑:/etc/sysconfig/iptables文件裏; [root@Ask-02 ~]# service iptable
iptables規則備份和恢復 firewalld的9個zone與zone的操作service的操作
wal zone tts alt 51cto roc ble nag image 10.19 iptables規則備份和恢復10.20 firewalld的9個zone9個zone的介紹10.21 firewalld關於zone的操作10.22 firewalld關於ser
三十三、iptables規則備份和恢復、firewalld的9個zone、關於zone的操作、
iptables規則備份和恢復 firewalld的9個zone 關於zone的操作 關於service的操作 三十三、iptables規則備份和恢復、firewalld的9個zone、firewalld關於zone的操作、firewalld關於service的操作一、iptables規則備份
iptables規則備份和恢復 firewalld的9個zone
iptables firewalld一、iptables規則備份和恢復#iptables-save > /tmp/ipt.txt //將iptables規則保存到指定目錄#iptables-restore < /tmp/ipt.txt //將剛才備份的規則恢復 二、firewal
iptables規則備份和恢復
watermark ges 9.png onf b16 ble 默認 查看 blog 備份/恢復iptabels規則 service iptabels save 默認會把規則保存在/etc/sysconfig/iptabels設置並查看規則保存並查看規則刪除規則恢復規則 f
26期20180716 iptables規則備份恢復 firewalld zone
fir cto sans webkit onf change gin filter 清空 7月16日任務10.19 iptables規則備份和恢復10.20 firewalld的9個zone10.21 firewalld關於zone的操作10.22 firewalld關於s
linux下的iptables規則儲存和恢復
iptables -t nat -A OUTPUT -p tcp -j REDIRECT **** 應用後,規則僅僅儲存在記憶體中,下次重啟後又預設重新載入/etc/sysconfig/iptables防火牆配置檔案。1.如果想把當前新增的規則在重啟後仍能使用,可以先通過/sbin/service iptab
iPtables規則儲存及載入等操作
iptables防火牆可以用於建立過濾(filter)與NAT規則。所有Linux發行版都能使用iptables,因此理解如何配置iptables將會幫助你更有效地管理Linux防火牆。如果你是第一次接觸iptables,你會覺得它很複雜,但是一旦你理解iptables的工作原理,你會發現其實它很簡單。
iptables備份 firewalld9個zone firewalld操作zone service
Linuxiptables規則備份和恢復 保存和備份iptables規則 service iptables save //會把規則保存到/etc/sysconfig/iptablesservice iptables save 想要備份到指定文件中可以使用如下命令:(把iptables規則備份到/tmp/ip
iptables規則的保存 備份 恢復
iptables1. 規則保存編輯完iptables的規則使用命令:service iptables save 把規則保存在iptables的配置文件裏面:/etc/sysconfig/iptables2. 備份規則想把此刻的規則備份一下,一般情況是拷貝一個iptables的配置文件,也可以對規則進行備份。可
[學習筆記]優雅地儲存和管理資料---MongoDB資料庫及管理工具的安裝和使用
文章包含以下內容: 1.MongoDB的下載,安裝和命令列的使用 2.Studio 3T(又名 RoboMongo)的下載和安裝 3.adminMongo的下載和安裝 將在下一篇文章中介紹模組pymongo的第三方庫如何配合Studio 3T或adminMongo完成爬蟲資料的資