Linux 防火墻:Netfilter iptables

?

?

一、Netfilter 簡介

(1)?Netfilter 是 Linux 內置的一種防火墻機制,我們一般也稱之為數據包過濾機制,而 iptables 只是操作 netfilter 的一個命令行工具
(2) Netfilter 是 Linux CentOS 6 內置的防火墻機制,Firewall 是 Linux CentOS 7 內置的防火墻機制,如果想在 CentOS 7 中使用 netfilter 而不是 firewall,操作如下

?

[root@MongoDB ~]# systemctl stop firewalld.service  // 停止firewalld
[root@MongoDB ~]# systemctl disable firewalld.service  // 禁止firewall開機啟動
[root@MongoDB ~]# yum install iptables-services -y
[root@MongoDB ~]# systemctl start iptables.service  //啟動防火墻
[root@MongoDB ~]# systemctl enable iptables.service  // 設置防火墻開機啟動

?

?

?

?

?

centos7 iptables服務

1.查看iptables服務狀態

[root@MongoDB ~]#systemctl status iptables

?

?

systemctl start iptables  // 啟動iptables服務
systemctl restart iptables  // 重啟iptables服務
systemctl stop iptables    // 關閉iptables服務

?

centos6 iptables 服務

service iptables start  // 啟動 iptables服務
service iptables restart  // 重啟iptables服務
service iptables stop    // 關閉iptables服務
service iptables status  // 查看iptables服務狀態

?

/etc/init.d/iptables stop // 關閉iptables服務
/etc/init.d/iptables status  // 查看iptables狀態

?

2.查看規則,默認查看filter表的規則
iptables -nvL              
針對INPUT鏈 默認規則ACCEPT通過
iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)  // 針對INPUT鏈 默認規則
// INPUT鏈 規則pkts bytes target     prot opt in     out     source               destination         7589  858K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           42  2520 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           2   104 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:220     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:27017
30806 3205K REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited// FORWARD鏈 默認規則
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// OUTPUT鏈 默認規則
Chain OUTPUT (policy ACCEPT 6732 packets, 950K bytes)pkts bytes target     prot opt in     out     source               destination 
 
 

?

二、iptables 常見用法:

iptables -F                # 清空規則,默認清空filter表的規則
iptables -X                # 刪除用戶自定義規則
iptables -Z                # 清空鏈的計數器
service iptables save      # 保存規則,會把當前規則保存到/etc/sysconfig/iptables
iptables-save > my.ipt     # 備份規則,這里指定備份到my.ipt文件
iptables-restore < my.ipt  # 恢復規則,這里指定使用my.ipt文件進行恢復  

?

?

清空所有的規則,只留下默認規則

iptables -F??清空規則,默認清空filter表的規則

只留下默認規則 默認規則都是ACCEPT動作

[root@MongoDB ~]# iptables -F
[root@MongoDB ~]# iptables -nvL
Chain INPUT (policy ACCEPT 6 packets, 480 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 6 packets, 528 bytes)pkts bytes target     prot opt in     out     source               destination 

iptables -X? 刪除用戶定義規則

iptables -Z 清空鏈的計數器

?

?

iptables -A INPUT -p tcp --dport 80 -j ACCEPT                                                # 放通80端口
iptables -A INPUT -p tcp --dport 22 -j DROP                                                  # 禁用22端口
iptables -A INPUT -p tcp -m multiport --dport 80,843,443 -j ACCEPT                          # 放通多個端口
iptables -A INPUT -s 192.168.1.1/32 -p tcp --dport 22 -j ACCEPT                              # 只允許某個IP訪問22端口
iptables -A INPUT -s 192.168.1.1/32 -p tcp -m multiport --dport 3873,4507,3306 -j ACCEPT    # 允許某個IP訪問多個端口

?

?添加一條規則 到filter表 允許8080端口

[root@MongoDB ~]# iptables -t filter -A INPUT -p tcp --dport 8080 -j ACCEPT

刪除一條規則

先執行 iptables -nvL --line-numbers 查看規則的序列號
[root@MongoDB ~]# iptables -nvL --line-numbers
Chain INPUT (policy ACCEPT 93 packets, 7775 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8080Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         Chain OUTPUT (policy ACCEPT 59 packets, 6900 bytes)
num   pkts bytes target     prot opt in     out     source               destination 

-D 刪除規則

然后執行 iptables -D INPUT <number> 刪除規則
[root@MongoDB ~]# iptables -D INPUT 1
[root@MongoDB ~]# 
[root@MongoDB ~]# iptables -nvL --line-numbers
Chain INPUT (policy ACCEPT 14 packets, 1020 bytes)
num   pkts bytes target     prot opt in     out     source               destination         Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         Chain OUTPUT (policy ACCEPT 6 packets, 728 bytes)
num   pkts bytes target     prot opt in     out     source               destination

?

?
-A       # 添加規則,默認添加到最后一條規則
-I       # 插入規則,默認插入到第一條規則
-D       # 刪除規則,先執行 iptables -nvL --line-numbers 查看規則的序列號,然后執行 iptables -D INPUT <number> 刪除規則
-n       # 數字
-s       # 用于指定源IP地址,用法如:iptables -A INPUT -s 192.168.1.1/32 -p tcp --dport 22 -j ACCEPT
-d       # 用于指定目標IP地址,用法如:iptables -A INPUT -d 192.168.1.1/32 -p tcp --dport 22 -j ACCEPT
-p       # 用于指定檢查哪個協議,用法如:iptables -A INPUT -p tcp --dport 80 -j ACCEPT
-i       # 用于指定入口網卡,用法如:iptables -A INPUT -i eth0 -j ACCEPT 
-o       # 用于指定出口網卡,用法如:iptables -A FORWARD -o eth0 -j ACCEPT
-j       # 用于指定要進行的處理動作,ACCEPT表示接受數據包進來 DROP直接丟棄數據包 用法如:iptables -A INPUT -p tcp --dport 80 -j ACCEPT
-P       # 用于設置默認規則,用法如:iptables -P INPUT DROP
-t       # 用于指定操作哪張表,用法如:iptables -t nat -nvL , iptables -t filter ,如果沒有指定默認是filter表
-Z       # 用于清空計數器,用法如:iptables -Z
-L       # 用于列出規則鏈中的所有規則
--sport  # 用于指定源端口,用法如:iptables -A INPUT -p tcp --sport 1234 -j ACCEPT
--dport  # 用于指定目標端口,用法如:iptables -A INPUT -s 192.168.1.1/32 -p tcp --dport 22 -j ACCEPT    
!        # 取反 
 

?

?
 

?

 
 

?

?

轉載于:https://www.cnblogs.com/mingerlcm/p/10685450.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/248118.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/248118.shtml
英文地址,請注明出處:http://en.pswp.cn/news/248118.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

無法加載 DLL“SQLite.Interop.DLL”: 找不到指定的模塊。 (異常來自 HRESULT:0x8007007E)。...

無法加載 DLL“SQLite.Interop.DLL”: 找不到指定的模塊。 (異常來自 HRESULT:0x8007007E)。 在項目里添加 現有項 把SQLite.Interop.DLL文件添加進來&#xff0c;然后點擊屬性 修改一個屬性 把 屬性 復制到輸出目錄 改為 始終復制 然后打開你的項目屬性 進入生成的 頁面&a…

jQuery第三天

課程回顧&#xff1a; ? 動畫效果&#xff1a;基本動畫&#xff0c;滑動動畫&#xff0c;淡入淡出&#xff0c;自定義動畫效果(animate) ? 事件切換&#xff1a;hover(over&#xff0c;out); ? 停止動畫&#xff1a;stop ? 操作屬性&#xff1a;prop&#xff08;固有屬…

C語言程序設計II—第八周教學

第八周教學總結&#xff08;15/4-21/4&#xff09; 教學內容 本周的教學內容為&#xff1a;   8.4 電碼加密 知識點&#xff1a;指針與字符串&#xff0c;重難點&#xff1a;字符指針與字符串的關聯和區別&#xff1b;   8.5 任意個整數求和 知識點&#xff1a;動態內存分配…

AFNetworking 對數據進行https ssl加密

參考來源&#xff1a;http://www.cnblogs.com/jys509/p/5001566.html 現在在工作中的工作需求&#xff1a;https請求驗證證書一般來講如果app用了web service , 我們需要防止數據嗅探來保證數據安全.通常的做法是用ssl來連接以防止數據抓包和嗅探其實這么做的話還是不夠的 。…

數據庫系統原理(第一章概述)

一、數據庫基本概念 什么是數據&#xff1a;數據&#xff08;Data&#xff09;是描述事物的符號記錄&#xff0c;是指利用物理符號記錄下來的、 可以鑒別的信息。 數據是信息存在的一種形式&#xff0c;只有通過解釋或處理的數據才能成為有用的信息。 什么是數據庫&#xff1a;…

jQuery第四天

課程回顧&#xff1a; ? 元素操作&#xff1a; ? 遍歷元素&#xff1a; ? $(‘元素’).each(function (index, elm) {}); ? $.each(對象&#xff0c;function (index, elm) {}); ? 創建元素&#xff1a;$(‘ 新的元素?’);? 添加元素&#xff1a; ? 內部添加&…

navigationController的NavigationBar和ToolBar的POP或PUSH消失問題

今天在工作中發現一個坑&#xff0c; 其他頁面都是隱藏。YSViewController 使用的時候必須是需要 navigationBar 和 toorbar&#xff0c;但是 pop出這個viewcontroller后&#xff0c;需要隱藏navigationBar 和 toorbar&#xff0c;但是直接設置為hiddenYES會出現其他頁面壓棧出…

實驗二:Linux下Xen環境的安裝

實驗名稱&#xff1a; Linux下Xen環境的安裝&#xff08;centOS7&#xff09; 實驗環境&#xff1a; 本次實驗基本是在centOS7的環境下完成&#xff0c;系統內核和系統版本如下&#xff1a; 實驗要求&#xff1a; 為centOS7的環境下安裝Xen的平臺&#xff0c;能夠正常使用Xen下…

IDEA寫vue項目出現紅色波浪線警告如何解決??

1.看圖 2.希望對大家有幫助&#xff0c;只要修改了這個就可以&#xff0c;如有任何問題都可以留言&#xff0c;謝謝大家 2019-09-1923:54:11 作者&#xff1a;何秀好 轉載于:https://www.cnblogs.com/itboxue/p/11553395.html

數據可視化(BI報表的開發)第一天

課程回顧&#xff1a; ? jQuery事件注冊&#xff1a; ? $(元素).click(function () {}); ? $(元素).on(‘click’, [后代元素], function () {}); ? $(元素).one(‘click’, function () {}); ? 解綁事件&#xff1a;off ? 自動觸發&#xff1a; ? $(元素).click…

在Block中使用weakSelf與strongSelf的意義

在Block中使用weakSelf與strongSelf的意義 我們都會聲明一個弱引用在block中使用, 目的就是防止循環引用, 那么weakSelf與strongSelf一起使用目的是什么呢? 首先先定義2個宏: #define YXWeakSelf(type) __weak typeof(type) weak##type type; #define StrongSelf(type) __…

操作系統原理之操作系統簡介(第一章)

一、 什么是操作系統 操作系統&#xff1a;是一種復雜的系統軟件&#xff0c;是不同程序代碼、數據結構、數據初始化文件的集合&#xff0c;可執行。 操作系統是用戶與硬件之間的接口&#xff1a;操作系統與硬件部分相互作用&#xff0c;并且為運行在計算機上的應用程序提供執行…

數據可視化(BI報表的開發)第二天

9、公用面板樣式 所有的面板的基礎樣式是一致的&#xff0c;提前布局好。 面板 .panel &#xff1a;box-sizing&#xff0c;邊框圖&#xff0c;大小&#xff0c;定位【51 38 20 132】容器 .inner&#xff1a;padding&#xff1a;24&#xff0c;36&#xff0c;定位外部拉寬標…

關于Xcode 7.3 7.3.1 斷點 卡死 無限菊花

關于Xcode 7.3 7.3.1 斷點 卡死 無限菊花 只要一打斷點,就無限卡死,變量區一直菊花在轉,只有強制退出Xcode才能重新編譯,找了Google和Stack OvewFlowe依然沒有解決辦法. 刪除項目,重新安裝Xcode,重新運行程序一切辦法都解決不到,百度上說的"build setting中將Enable Clang…

html5+hbuilder+夜神模擬器+webview

HTML5 Plus應用概述 首先新建一個移動App項目&#xff0c;文件-->新建-->移動APP HTML5 Plus移動App&#xff0c;簡稱5App&#xff0c;是一種基于HTML、JS、CSS編寫的運行于手機端的App&#xff0c;這種App可以通過擴展的JS API任意調用手機的原生能力&#xff0c;實現與…

第十九節:Asp.Net Core WebApi知識總結(一)

111 轉載于:https://www.cnblogs.com/yaopengfei/p/11558525.html

iOS設計模式 ——單例模式詳解以及嚴格單例模式注意點

一、我們常用的單例有哪些&#xff1f; [[UIApplication sharedApplication] statusBarStyle];//系統中的單例模式&#xff0c;通過它獲取到狀態欄的style [NSNotificationCenter defaultCenter] addObserver:<#(nonnull id)#> selector:<#(nonnull SEL)#> name:&…

科學計算庫學習報告

numpy與matplotlib的學習隨筆 我愛代碼 import numpy as npimport matplotlib.pyplot as pltimport matplotlibmatplotlib.rcParams[font.family]SimHeimatplotlib.rcParams[font.sans-serif][SimHei]labelsnp.array([第一次,第二次,第三次,第四次,第五次,第六次])nAttr6datanp…

前端網頁 — 初始化文件

/*--------------------------初始化代碼*/ /*清除默認的margin和padding*/ * {margin: 0;padding: 0; }/*清除小圓點*/ ul {list-style: none; }/*清除a標簽默認的下劃線*/ a {text-decoration: none; }/*表格邊框合并*/ table {border-collapse: collapse; }/*去除input標簽點…

數據庫系統原理(第二章關系數據庫 )

一、關系數據庫概述 20世紀80年代后&#xff0c;在商用數據庫管理系統中&#xff0c;&#xff08; 關系模型 &#xff09;逐漸取代早 期的網狀模型和層次模型&#xff0c;成為主流數據模型 SQL3&#xff08;SQL-99&#xff09;:1999年 SQL2&#xff08;SQL-92&#xff09;&…