linux?iptables防火墻中的工作常用命令
linux iptables防火墻-工作常用命令
Linux之iptables防火墻基礎
[推薦]Linux之iptables防火墻
參考URL:http://m.fzitv.net/article/165883.htm
linux系統(tǒng)的防火墻:IP信息包過濾u系統(tǒng),它實際上由兩個組件netfilter和iptables組成。
主要工作在網(wǎng)絡層,針對IP數(shù)據(jù)包,體現(xiàn)在對包內的IP地址、端口、協(xié)議等信息的處理上。
數(shù)據(jù)包到達防火墻時,規(guī)則表之間的優(yōu)先順序: 首先過濾raw表里面的規(guī)則其次依次過濾> mangle > nat > filter如果所有表都沒有匹配到則表示放空

- 入站數(shù)據(jù)(來自外界的數(shù)據(jù)包,且目標地址是防火墻本機) : PREROUTING --> INPUT --> 本機的應用程序
- 出站數(shù)據(jù)(從防火墻本機向外部地址發(fā)送的數(shù)據(jù)包) :本機的應用程序–> OUTPUT --> POSTROUTING 網(wǎng)絡型防火墻
- 轉發(fā)數(shù)據(jù)(需要經(jīng)過防火墻轉發(fā)的數(shù)據(jù)包) : PREROUTING --> FORWARD --> POSTROUTING
iptables命令行配置方法
iptables [-t 表明] 管理選項 [鏈名] [匹配條件] [-j 控制類型]

查看iptables防火墻規(guī)則
iptables -nvL --line-number
-L 查看當前表的所有規(guī)則,默認查看的是filter表,如果要查看NAT表,可以加上-t NAT參數(shù)
-n 不對ip地址進行反查,加上這個參數(shù)顯示速度會快很多
-v 輸出詳細信息,包含通過該規(guī)則的數(shù)據(jù)包數(shù)量,總字節(jié)數(shù)及相應的網(wǎng)絡接口
–-line-number 顯示規(guī)則的序列號,這個參數(shù)在刪除或修改規(guī)則時會用到
關閉某個端口(注意同時添加ip或接口的限制)\iptables 配置只能本地ip訪問某端口
iptables -I INPUT -p tcp --dport 9527 -j DROPip6tables -I INPUT -p tcp --dport 9527 -j DROP
注意:工作中切記不要直接使用上面命令,除非在這個命令之前還有一條放過
lo接口的防火墻規(guī)則。
一般情況,我們目的都是某個端口不讓外網(wǎng)訪問,這樣操作,就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的
注意 感嘆號的位置,親測可用.~
防火墻規(guī)則放開自己的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永久生效
第一種方法
執(zhí)行命令service iptables save
第二種方法
執(zhí)行命令iptables-save > xxx寫入到一個文件,開機以后執(zhí)行命令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.
問題描述:
執(zhí)行命令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操作(啟動、停止、重啟、嘗試重啟、重載、強制重載、狀態(tài))。對于其他操作,請嘗試使用systemctl。
centos新版本,firewalld 被引入代替 iptables 了,所以再使用 service iptables save 保存 iptables 規(guī)則時,就會出現(xiàn)上述的報錯。
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服務:
到此這篇關于linux iptables防火墻-工作常用命令的文章就介紹到這了,更多相關linux iptables命令內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
shell腳本分析 nginx日志訪問次數(shù)最多及最耗時的頁面(慢查詢)
下面是我在做優(yōu)化時候,經(jīng)常用到的一段shell 腳本。 這個也可以算是,統(tǒng)計web頁面的slowpage 慢訪問頁面,象mysql slowquery2013-11-11
Linux各項目環(huán)境部署記錄(換服務器部署腳本整理)
每次換便宜的服務器都要導致環(huán)境重新部署一遍,十分麻煩,于是把每次部署的腳本整理了一下,方便在服務器上快速進行部署,基于?CentOS2023-05-05

