日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

linux?iptables防火墻中的工作常用命令_linux shell

作者:西京刀客 ? 更新時間: 2022-11-28 編程語言

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 DROP
ip6tables -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

欄目分類
最近更新