欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2022年10月20日 10:03:38   作者:西京刀客  
linux系統(tǒng)的防火墻,IP信息包過濾u系統(tǒng),它實(shí)際上由兩個(gè)組件netfilter和iptables組成,這篇文章主要介紹了linux?iptables防火墻-工作常用命令,需要的朋友可以參考下

linux iptables防火墻-工作常用命令

Linux之iptables防火墻基礎(chǔ)

[推薦]Linux之iptables防火墻
參考URL:http://www.dbjr.com.cn/article/165883.htm

linux系統(tǒng)的防火墻:IP信息包過濾u系統(tǒng),它實(shí)際上由兩個(gè)組件netfilter和iptables組成。
主要工作在網(wǎng)絡(luò)層,針對IP數(shù)據(jù)包,體現(xiàn)在對包內(nèi)的IP地址、端口、協(xié)議等信息的處理上。

數(shù)據(jù)包到達(dá)防火墻時(shí),規(guī)則表之間的優(yōu)先順序: 首先過濾raw表里面的規(guī)則其次依次過濾> mangle > nat > filter如果所有表都沒有匹配到則表示放空

  • 入站數(shù)據(jù)(來自外界的數(shù)據(jù)包,且目標(biāo)地址是防火墻本機(jī)) : PREROUTING --> INPUT --> 本機(jī)的應(yīng)用程序
  • 出站數(shù)據(jù)(從防火墻本機(jī)向外部地址發(fā)送的數(shù)據(jù)包) :本機(jī)的應(yīng)用程序–> OUTPUT --> POSTROUTING 網(wǎng)絡(luò)型防火墻
  • 轉(zhuǎn)發(fā)數(shù)據(jù)(需要經(jīng)過防火墻轉(zhuǎn)發(fā)的數(shù)據(jù)包) : PREROUTING --> FORWARD --> POSTROUTING

iptables命令行配置方法

iptables [-t 表明] 管理選項(xiàng) [鏈名] [匹配條件] [-j 控制類型]

查看iptables防火墻規(guī)則

iptables -nvL --line-number

-L 查看當(dāng)前表的所有規(guī)則,默認(rèn)查看的是filter表,如果要查看NAT表,可以加上-t NAT參數(shù)
-n 不對ip地址進(jìn)行反查,加上這個(gè)參數(shù)顯示速度會快很多
-v 輸出詳細(xì)信息,包含通過該規(guī)則的數(shù)據(jù)包數(shù)量,總字節(jié)數(shù)及相應(yīng)的網(wǎng)絡(luò)接口
–-line-number 顯示規(guī)則的序列號,這個(gè)參數(shù)在刪除或修改規(guī)則時(shí)會用到

關(guān)閉某個(gè)端口(注意同時(shí)添加ip或接口的限制)\iptables 配置只能本地ip訪問某端口

iptables -I INPUT -p tcp --dport 9527 -j DROP
ip6tables -I INPUT -p tcp --dport 9527 -j DROP

注意:工作中切記不要直接使用上面命令,除非在這個(gè)命令之前還有一條放過lo接口的防火墻規(guī)則。
一般情況,我們目的都是某個(gè)端口不讓外網(wǎng)訪問,這樣操作,就127.0.0.1訪問這個(gè)端口也被限制了。

一定要記得,添加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

開放某個(gè)tcp、某個(gè)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寫入到一個(gè)文件,開機(jī)以后執(zhí)行命令iptables-restore < xxx用來恢復(fù)。

報(bào)錯(cuò):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 報(bào)錯(cuò)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.
服務(wù)命令只支持基本的LSB操作(啟動、停止、重啟、嘗試重啟、重載、強(qiáng)制重載、狀態(tài))。對于其他操作,請嘗試使用systemctl。

centos新版本,firewalld 被引入代替 iptables 了,所以再使用 service iptables save 保存 iptables 規(guī)則時(shí),就會出現(xiàn)上述的報(bào)錯(cuò)。
service命令只保留下了極少部分使用,大部分命令都要改用systemctl使用。

這是因?yàn)闆]有安裝iptables服務(wù),直接使用yum安裝iptables服務(wù)即可.

解決方法:

1.systemctl stop firewalld --關(guān)閉防火墻
2.yum install iptables-services --安裝或更新服務(wù)

yum install iptables-services

3.systemctl enable iptables --允許開機(jī)啟動iptables
4.systemctl start iptables --啟動iptables
5.service iptables save --保存設(shè)置
6.service iptables restart --重啟iptables服務(wù):

到此這篇關(guān)于linux iptables防火墻-工作常用命令的文章就介紹到這了,更多相關(guān)linux iptables命令內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論