防火牆簡單應用

2022-03-12 01:36:39 字數 2232 閱讀 4955

iptables -a input -p all -m state --state established,related -j accept

iptables -a input -i lo -j accept

iptables -a input -p icmp -j accept

iptables -a input -p tcp --syn -m state --state new --dport 80 -j accept

iptables -a input -p tcp --syn -m state --state new --dport 22 -j accept

iptables -a input -p tcp --syn -m state --state new --dport 25 -j accept

iptables -t filter -p forward drop

iptables -t nat -p postrouting drop

iptables -a input -p tcp --syn -m state --state new --dport

iptables -a input -p tcp -s 211.147.90.100/32 -m multiport --dports 13579,28005,28009 -j accept

結尾(不加上面規則起不到過濾作用)

iptables -a input -p all -j drop              //禁止除上面放行埠的所有埠請求,這條規則很重要,防止一些不用埠被惡意利用攻擊

插入規則

iptables -i input 4 -s 192.168.1.1 -j accept

multiport :不連續的多埠匹配

允許源192.168.1.123訪問22埠的ip進來

iptables -a input -s 192.168.1.123 -p tcp --dport 22 -j accept

-m :匹配

state 匹配包的狀態

--state

newestablished

releted

invaild

-p 後面必須接協議

--syn = --tcp-flags syn,ack,fin syn

表示連線請求

syn 連線請求

ack 請求確認

fin 斷開請求

限制apache每秒新建連線數為1,峰值為3

每秒新建連線數 一般都是由防火牆來做,apache本身好像無法設定每秒新建連線數,只能設定最大連線:

iptables -a input -d 172.16.100.1 -p tcp --dport 80 -m limit --limit 1/second -j accept

172.16.100.1為apache位址(本機位址)

iptables實現埠對映和埠負載均衡

使用 dnat 來實現,但 ip 不要寫 127.0.0.1,而應該寫使用者可以訪問到的 ip 位址

比如prerouting

iptables -t nat -aprerouting-d 12.1.1.1 -p tcp --dport 80 -jdnat--to 12.1.1.1:8080 //將對ip為12.1.1.1,埠為80的請求**到8080埠

實現外網訪問內網服務

iptables -t nat -aprerouting-i eth0 -d 12.1.1.1 -p tcp --dport 8080 -jdnat--to 12.1.1.2:80

iptables -t nat -apostrouting-o eth1 -d 12.1.1.2 -p tcp --dport 80 -jsnat--to 12.1.1.3   //修改output源ip

(對於prerouting鏈,只能用-i指定進來的網路介面;而對於postrouting和 output只能用-o指定出去的網路介面)

負載均衡

iptables -t nat -aprerouting-d 192.168.10.160 -p tcp --dport 3000 -jdnat--to 192.168.10.160:3001-3003

防火牆 防火牆安全

作為計算機的第一道屏障,防火牆的重要性不言而喻,儘管防火牆在面臨網路攻擊時仍有很大的缺陷,不如無法阻止自內而外的攻擊,對複雜多變的網路攻擊攻擊無法預警和像ids所做的那樣。但防火牆依然是伺服器乃至個人機的一道不可或缺的屏障。木桶原理 本文將對防火牆做乙個初步的簡介,顯然像我們知道的那樣,防火牆是一款...

防火牆簡單實驗

總結 ar1 int g0 0 0 ip ad 172.16.1.254 24 int g0 0 2 ip ad 192.168.1.254 24 int g0 0 1 ip ad 10.1.12.1 24 fw int g0 0 0 ip ad 192.168.43.3 24 這裡配置與橋接的網絡...

防火牆簡單實驗

總結 ar1 int g0 0 0 ip ad 172.16.1.254 24 int g0 0 2 ip ad 192.168.1.254 24 int g0 0 1 ip ad 10.1.12.1 24 fw int g0 0 0 ip ad 192.168.43.3 24 這裡配置與橋接的網絡...