網站首頁 編程語言 正文
linux iptables防火墻-工作常用命令
Linux之iptables防火墻基礎
[推薦]Linux之iptables防火墻
參考URL:https://www.jb51.net/article/165883.htm
linux系統的防火墻:IP信息包過濾u系統,它實際上由兩個組件netfilter和iptables組成。
主要工作在網絡層,針對IP數據包,體現在對包內的IP地址、端口、協議等信息的處理上。
數據包到達防火墻時,規則表之間的優先順序: 首先過濾raw表里面的規則其次依次過濾> mangle > nat > filter如果所有表都沒有匹配到則表示放空
- 入站數據(來自外界的數據包,且目標地址是防火墻本機) : PREROUTING --> INPUT --> 本機的應用程序
- 出站數據(從防火墻本機向外部地址發送的數據包) :本機的應用程序–> OUTPUT --> POSTROUTING 網絡型防火墻
- 轉發數據(需要經過防火墻轉發的數據包) : PREROUTING --> FORWARD --> POSTROUTING
iptables命令行配置方法
iptables [-t 表明] 管理選項 [鏈名] [匹配條件] [-j 控制類型]
查看iptables防火墻規則
iptables -nvL --line-number
-L 查看當前表的所有規則,默認查看的是filter表,如果要查看NAT表,可以加上-t NAT參數
-n 不對ip地址進行反查,加上這個參數顯示速度會快很多
-v 輸出詳細信息,包含通過該規則的數據包數量,總字節數及相應的網絡接口
–-line-number 顯示規則的序列號,這個參數在刪除或修改規則時會用到
關閉某個端口(注意同時添加ip或接口的限制)\iptables 配置只能本地ip訪問某端口
iptables -I INPUT -p tcp --dport 9527 -j DROPip6tables -I INPUT -p tcp --dport 9527 -j DROP
注意:工作中切記不要直接使用上面命令,除非在這個命令之前還有一條放過
lo
接口的防火墻規則。
一般情況,我們目的都是某個端口不讓外網訪問,這樣操作,就127.0.0.1訪問這個端口也被限制了。
一定要記得,添加ip或接口的條件~
例如:
iptables -I INPUT ! -i lo -p tcp --dport 9527 -j DROP ip6tables -I INPUT ! -i lo -p tcp --dport 9527 -j DROP
或
iptables -I INPUT ! -d 127.0.0.1 -p tcp --dport 9527 -j DROP
iptables 是控制ipv4的,ip6tables 是控制ipv6的
注意 感嘆號的位置,親測可用.~
防火墻規則放開自己的ip,讓自己的ip可以訪問
iptables -I INPUT -p tcp -s 192.168.11.1 -j ACCEPT
開放某個tcp、某個udp。
iptables -I INPUT -p tcp --dport 9527 -j ACCEPT iptables -I INPUT -p tcp --dport 9527 -j ACCEPT
iptables永久生效
第一種方法
執行命令service iptables save
第二種方法
執行命令iptables-save > xxx
寫入到一個文件,開機以后執行命令iptables-restore < xxx用來恢復。
報錯:The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
問題描述:
執行命令service iptables save
報錯The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
問題分析:
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
服務命令只支持基本的LSB操作(啟動、停止、重啟、嘗試重啟、重載、強制重載、狀態)。對于其他操作,請嘗試使用systemctl。
centos新版本,firewalld 被引入代替 iptables 了,所以再使用 service iptables save 保存 iptables 規則時,就會出現上述的報錯。
service命令只保留下了極少部分使用,大部分命令都要改用systemctl使用。
這是因為沒有安裝iptables服務,直接使用yum安裝iptables服務即可.
解決方法:
1.systemctl stop firewalld --關閉防火墻
2.yum install iptables-services --安裝或更新服務
yum install iptables-services
3.systemctl enable iptables --允許開機啟動iptables
4.systemctl start iptables --啟動iptables
5.service iptables save --保存設置
6.service iptables restart --重啟iptables服務:
原文鏈接:https://blog.csdn.net/inthat/article/details/127394548
相關推薦
- 2022-04-29 Go語言中的通道channel詳情_Golang
- 2022-06-19 C++詳細分析講解函數參數的擴展_C 語言
- 2023-05-11 SQL?多表聯合查詢的幾種方式詳解_MsSql
- 2022-08-28 Python?Decorator的設計模式演繹過程解析_python
- 2022-09-14 Go語言中序列化與反序列化示例詳解_Golang
- 2023-10-16 向前端傳遞Long類型數據時發生精度缺失解決辦法
- 2022-12-12 Android?DataBinding布局的加載深入探究_Android
- 2022-08-21 python深度學習tensorflow實例數據下載與讀取_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支