iptables 用法總結

2021-06-25 10:00:51 字數 2639 閱讀 3266

一、iptables ip和mac繫結

方法一:iptables

iptables -a forward -s 10.10.0.2 -m mac --mac-source 00:10:4b:15:16:6c -j accept

就將 10.10.0.2 與其mac位址繫結了

方法二:arp

192.168.0.2 08:00:4e:b0:24:47

2 .然後在 /etc/rc.d/rc.local 檔案最末新增:

arp -f /etc/ether

二、禁止客戶機訪問某些**

方法一:

iptables -i forward -d www.***.com

方法二:

iptables -i forward -m string --string www.***.com

--algo kmp -j reject

三、禁止某些客戶機上網

(這裡要用"i",-s,-d都行)

iptables -i forward -d 192.168.1.200 -j drop

iptables -i forward -s 192.168.1.200 -j drop

四、禁止客戶機訪問特定的服務

iptables -i forward -s 192.168.1.0/24 -p tcp --dport 21 -j drop

(禁止192.168.1.0網路訪問ftp服務)

要是多個埠用逗號隔開:

iptables -i forward -s 192.168.1.0/24 -p tcp --dport 21,22,23 -j drop

五、禁止客戶機ping linux伺服器,但linux 伺服器可以ping客戶機

iptables -t filter -a input -picmp --icmp-type echo-request -j drop

(只允許狀態為establish和related的資料報通過,而狀態為new的請求包不允許)

六、發布內網的伺服器 (目的nat,開放內網伺服器)

iptables -t nat -a prerouting -i ppp0 -p tcp --dport 80 -j dnat --to-destination 192.168.1.200:80

(internet的使用者訪問linux主機的80埠時,轉到192.168.1.200的80埠,即訪問內網的web服務)

七、 內網ip共享公網ip上網(源nat,實現共享上網)

iptables -t nat -i postrouting -s 192.168.0.0/24  -j masquerade

將內網192.168.0網段的資料報進行源位址轉換,共享公網ip位址上網。

八、智慧型dns服務

iptables -t nat -a prerouting -i eth0 -p udp --dport 53 -j dnat --to-destination 61.128.128.68:53

iptables -t nat -a prerouting -i eth0 -p tcp --dport 53 -j dnat --to-destination 61.128.128.68:53

(內網使用者的dns請求均送到乙個合法的dns伺服器61.128.128.68,此時不論客戶機設定的dns是否正確,均能由61.128.128.68進行解析)

九、dmz功能(防火牆自我保護功能)

iptables -t nat -a prerouting -i eth0 -p tcp --dport 80 -j dnat --to-destination 210.21.118.68:80

十、給特定資料報打mark,區分不同的資料流

iptables -t mangle -a prerouting -j internet

iptables  -t mangle -a internet  -d 192.168.0.1 -j mark --set-mark 99

iptables -t nat -i prerouting   -m mark --mark 99  -p tcp --dport 80  -j accept/drop

(標記特定資料流,方便對資料流進行精細化控制)

一、統計內網客戶端流量

iptables -i forward -d 192.168.1.200 -j accept

iptables -i forward -s 192.168.1.200 -j accept

只要用單位時間內流量除以時間即可得出這個客戶端的上網速度。想要限速也就輕而易舉

二、限制網速

iptables -a  forward -d 192.168.0.0/24 -m limit --limit 50/s -j accept

iptables -a  forward -d 192.168.0.0/24 -j drop

iptables用法總結

1.iptables的規則寫法 iptables t table command chain cretiria j action 2.t table table 表 有三個,即 filter表,nat表,mangle表,它們分別代表對經過iptables的資料報進行篩選 filter 轉譯 nat ...

略談iptables用法

linux上的iptables是基於其kernel內建的netfilter,netfilter工作在核心。因此使用者一般無法直接跟核心打交道,為了解決這個問題,提供了iptables這個軟體來設定netfilter。也就是說,當我們設定規則時,要通過iptables。iptables會檢查我們設定的...

總結iptables的應用

由於伺服器被黑,又研究的了一下iptables。總結一下他的幾個應用 1 限制埠 iptables a input p tcp dport 80 j accept iptables a input p tcp dport 22 j accept iptables a input j accept 實...