中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

防止入侵網站百度400電話

防止入侵網站,百度400電話,網站建設培訓資料,怎么掃碼進入公眾號目錄 1 iptables 入門介紹 1.1 iptables 介紹 1.2 iptables 安裝 1.3 iptables 服務管理 1.4 命令參數 1.5 顯示規(guī)則 1.6 刪除/插入規(guī)則 2 iptables 實例 2.1 清空當前的所有規(guī)則和計數 2.2 配置允許 ssh 端口連接 2.3 配置白名單 2.4 開啟相應的服務端口 2.5 列出…

目錄

1 iptables 入門介紹

1.1 iptables 介紹

1.2 iptables 安裝

1.3 iptables 服務管理

1.4 命令參數

1.5 顯示規(guī)則

1.6 刪除/插入規(guī)則

2 iptables 實例

2.1 清空當前的所有規(guī)則和計數

2.2 配置允許 ssh 端口連接

2.3 配置白名單

2.4 開啟相應的服務端口

2.5 列出已設置的規(guī)則

2.6 刪除已添加的規(guī)則

2.7 開放指定的端口

2.8 屏蔽 IP

2.9 查看已添加的規(guī)則

2.10 啟動網絡轉發(fā)規(guī)則

2.11 端口映射

2.12 字符串匹配

2.13 防止攻擊

2.14 連接管理

2.15 ssh & http管理

2.16 包管理



1 iptables 入門介紹


1.1 iptables 介紹


iptables 使用三個不同的鏈來允許或阻止流量:輸入(input)、輸出(output)和轉發(fā)(forward)

  • 輸入(input) —— 此鏈用于控制傳入連接的行為
  • 輸出(output) —— 此鏈用于傳出連接
  • 轉發(fā)(forward) —— 這條鏈用于傳入的連接,這些連接實際上不是在本地傳遞的,比如路由和 NATing

1.2 iptables 安裝


centos
CentOS 7 上默認安裝了 firewalld 作為防火墻,使用 iptables 建議關閉并禁用 firewalld。

$ systemctl stop firewalld
$ systemctl disable firewalld



安裝 iptables

$ yum install -y iptables-services



Ubuntu
安裝 iptables

apt-get install iptables

1.3 iptables 服務管理
$ systemctl status iptables ?# 查看服務狀態(tài)
$ systemctl enable iptables ?# 啟用服務
$ systemctl disable iptables # 禁用服務
$ systemctl start iptables ? # 啟動服務
$ systemctl restart iptables # 重啟服務
$ systemctl stop iptables ? ?# 關閉服務

1.4 命令參數
基本語法:$ iptables(選項)(參數)
-P?? ?設置默認策略:
iptables -P INPUT (DROP
-F?? ?清空規(guī)則鏈
-L?? ?查看規(guī)則鏈
-A?? ?在規(guī)則鏈的末尾加入新規(guī)則
-I?? ?num 在規(guī)則鏈的頭部加入新規(guī)則
-D?? ?num 刪除某一條規(guī)則
-s?? ?匹配來源地址 IP/MASK
加嘆號"!"表示除這個 IP 外
-d?? ?匹配目標地址
-i?? ?網卡名稱 匹配從這塊網卡流入的數據
-o?? ?網卡名稱 匹配從這塊網卡流出的數據
-p?? ?匹配協議,如 tcp,udp,icmp
--dport num?? ?匹配目標端口號
--sport num?? ?匹配來源端口號
$ iptables -t 表名 <-A/I/D/R> 規(guī)則鏈名 [規(guī)則號] <-i/o 網卡名> -p 協議名 <-s 源IP/源子網> --sport 源端口 <-d 目標IP/目標子網> --dport 目標端口 -j 動作


1.5 顯示規(guī)則
詳細打印出所有活動的 iptables 規(guī)則$ iptables -n -L -v
具有行號的相同輸出:$ iptables -n -L -v --line-numbers
最后,相同的數據輸出但與 INPUT/OUTPUT 鏈相關:$ iptables -L INPUT -n -viptables -L OUTPUT -n -v --line-numbers


?


1.6 刪除/插入規(guī)則
按鏈條和編號刪除規(guī)則$ iptables -D INPUT 10
按規(guī)范刪除規(guī)則$ iptables -D INPUT -m conntrack --ctstate INVALID -j DROP
刷新所有規(guī)則,刪除所有鏈,并接受所有$ iptables -P INPUT ACCEPT
$ iptables -P FORWARD ACCEPT
$ iptables -P OUTPUT ACCEPT
$ iptables -t nat -F
$ iptables -t mangle -F
$ iptables -F
$ iptables -X
# 沖洗所有鏈
$ iptables -F
# 刷新單鏈
$ iptables -F INPUT
# 插入規(guī)則
$ iptables -I INPUT 2 -s 202.54.1.2 -j DROP


?


2 iptables 實例

2.1 清空當前的所有規(guī)則和計數
$ iptables -F ?# 清空所有的防火墻規(guī)則
$ iptables -X ?# 刪除用戶自定義的空鏈
$ iptables -Z ?# 清空計數


2.2 配置允許 ssh 端口連接
$ iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 22 -j ACCEPT
22 為你的 ssh 端口, -s 192.168.1.0/24 表示允許這個網段的機器來連接,其它網段的 ip 地址是登陸不了你的機器的。-j ACCEPT 表示接受這樣的請求

2.3 配置白名單
# 允許機房內網機器可以訪問
$ iptables -A INPUT -p all -s 192.168.1.0/24 -j ACCEPT?
# 允許機房內網機器可以訪問
$ iptables -A INPUT -p all -s 192.168.140.0/24 -j ACCEPT?
# 允許 183.121.3.7 訪問本機的3380端口
$ iptables -A INPUT -p tcp -s 183.121.3.7 --dport 3380 -j ACCEPT

2.4 開啟相應的服務端口
# 開啟 80 端口,因為web對外都是這個端口
$ iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# 允許被 ping
$ iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
# 已經建立的連接得讓它進來
$ iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

2.5 列出已設置的規(guī)則
$ iptables -L [-t 表名][鏈名]
四個表名 raw,nat,filter,mangle
五個規(guī)則鏈名 INPUT、OUTPUT、FORWARD、PREROUTING、POSTROUTING
filter 表包含INPUT、OUTPUT、FORWARD三個規(guī)則鏈
# 列出 nat 上面的所有規(guī)則
$ iptables -L -t nat ? ? ? ? ? ? ? ?
# ? ? ? ? ? ?^ -t 參數指定,必須是 raw, nat,filter,mangle 中的一個
# 規(guī)則帶編號
$ iptables -L -t nat ?--line-numbers
$ iptables -L INPUT
# 查看,這個列表看起來更詳細
$ iptables -L -nv

2.6 刪除已添加的規(guī)則
# 添加一條規(guī)則
$ iptables -A INPUT -s 192.168.1.5 -j DROP
將所有 iptables 以序號標記顯示,執(zhí)行:$ iptables -L -n --line-numbers
比如要刪除 INPUT 里序號為 8 的規(guī)則,執(zhí)行:$ iptables -D INPUT 8

2.7 開放指定的端口
# 允許本地回環(huán)接口(即運行本機訪問本機)
$ iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
# 允許已建立的或相關連的通行
$ iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# 允許所有本機向外的訪問
$ iptables -A OUTPUT -j ACCEPT
# 允許訪問22端口
$ iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# 允許訪問80端口
$ iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# 允許ftp服務的21端口
$ iptables -A INPUT -p tcp --dport 21 -j ACCEPT
# 允許FTP服務的20端口
$ iptables -A INPUT -p tcp --dport 20 -j ACCEPT
# 禁止其他未允許的規(guī)則訪問
$ iptables -A INPUT -j reject
# 禁止其他未允許的規(guī)則訪問
$ iptables -A FORWARD -j REJECT


2.8 屏蔽 IP
# 屏蔽惡意主機(比如,192.168.0.8
$ iptables -A INPUT -p tcp -m tcp -s 192.168.0.8 -j DROP
# 屏蔽單個IP的命令
$ iptables -I INPUT -s 123.45.6.7 -j DROP
# 封整個段即從123.0.0.1到123.255.255.254的命令
$ iptables -I INPUT -s 123.0.0.0/8 -j DROP
# 封IP段即從123.45.0.1到123.45.255.254的命令
$ iptables -I INPUT -s 124.45.0.0/16 -j DROP
# 封IP段即從123.45.6.1到123.45.6.254的命令是
$ iptables -I INPUT -s 123.45.6.0/24 -j DROP

2.9 查看已添加的規(guī)則
$ iptables -L -n -v
Chain INPUT (policy DROP 48106 packets, 2690K bytes)pkts bytes target ? ? prot opt in ? ? out ? ? source ? ? ? ? ? ? ? destination5075 ?589K ACCEPT ? ? all ?-- ?lo ? ? * ? ? ? 0.0.0.0/0 ? ? ? ? ? ?0.0.0.0/0191K ? 90M ACCEPT ? ? tcp ?-- ?* ? ? ?* ? ? ? 0.0.0.0/0 ? ? ? ? ? ?0.0.0.0/0 ? ? ? ? ? tcp dpt:22
1499K ?133M ACCEPT ? ? tcp ?-- ?* ? ? ?* ? ? ? 0.0.0.0/0 ? ? ? ? ? ?0.0.0.0/0 ? ? ? ? ? tcp dpt:80
4364K 6351M ACCEPT ? ? all ?-- ?* ? ? ?* ? ? ? 0.0.0.0/0 ? ? ? ? ? ?0.0.0.0/0 ? ? ? ? ? state RELATED,ESTABLISHED6256 ?327K ACCEPT ? ? icmp -- ?* ? ? ?* ? ? ? 0.0.0.0/0 ? ? ? ? ? ?0.0.0.0/0
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)pkts bytes target ? ? prot opt in ? ? out ? ? source ? ? ? ? ? ? ? destination
Chain OUTPUT (policy ACCEPT 3382K packets, 1819M bytes)pkts bytes target ? ? prot opt in ? ? out ? ? source ? ? ? ? ? ? ? destination5075 ?589K ACCEPT ? ? all ?-- ?* ? ? ?lo ? ? ?0.0.0.0/0 ? ? ? ? ? ?0.0.0.0/0


?



2.10 啟動網絡轉發(fā)規(guī)則
公網210.14.67.7讓內網192.168.188.0/24上網$ iptables -t nat -A POSTROUTING -s 192.168.188.0/24 -j SNAT --to-source 210.14.67.127


?



2.11 端口映射
本機的 2222 端口映射到內網 虛擬機的 22 端口$ iptables -t nat -A PREROUTING -d 210.14.67.127 -p tcp --dport 2222 ?-j DNAT --to-dest 192.168.188.115:22

2.12 字符串匹配
比如,我們要過濾所有 TCP 連接中的字符串test,一旦出現它我們就終止這個連接,我們可以這么做:$ iptables -A INPUT -p tcp -m string --algo kmp --string "test" -j REJECT --reject-with tcp-reset
$ iptables -L
# Chain INPUT (policy ACCEPT)
# target ? ? prot opt source ? ? ? ? ?destination
# REJECT ? ? tcp ?-- ?anywhere ? ? ? ?anywhere ? ? ? ?STRING match "test" ALGO name kmp TO 65535 reject-with tcp-reset
#
# Chain FORWARD (policy ACCEPT)
# target ? ? prot opt source ? ? ? ? ?destination
#
# Chain OUTPUT (policy ACCEPT)
# target ? ? prot opt source ? ? ? ? ?destination

2.13 防止攻擊
阻止 Windows 蠕蟲的攻擊
$ iptables -I INPUT -j DROP -p tcp -s 0.0.0.0/0 -m string --algo kmp --string "cmd.exe"
防止 SYN 洪水攻擊
$ iptables -A INPUT -p tcp --syn -m limit --limit 5/second -j ACCEPT
防止端口掃描
$ iptables -N port-scanningiptables -A port-scanning -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s --limit-burst 2 -j RETURNiptables -A port-scanning -j DROP
SSH 暴力破解保護
$ iptables -A INPUT -p tcp --dport ssh -m conntrack --ctstate NEW -m recent --setiptables -A INPUT -p tcp --dport ssh -m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 10 -j DROP
同步泛洪保護
$ iptables -N syn_floodiptables -A INPUT -p tcp --syn -j syn_floodiptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
$ iptables -A syn_flood -j DROPiptables -A INPUT -p icmp -m limit --limit ?1/s --limit-burst 1 -j ACCEPT
$ iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:
$ iptables -A INPUT -p icmp -j DROPiptables -A OUTPUT -p icmp -j ACCEPT
使用 SYNPROXY 緩解 SYN 泛洪
$ iptables -t raw -A PREROUTING -p tcp -m tcp --syn -j CT --notrack
$ iptables -A INPUT -p tcp -m tcp -m conntrack --ctstate INVALID,UNTRACKED -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460
$ iptables -A INPUT -m conntrack --ctstate INVALID -j DROP
阻止非 SYN 的新數據包
$ iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP阻止帶有虛假 TCP 標志的數據包
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,RST FIN,RST -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,ACK FIN -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,URG URG -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,FIN FIN -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,PSH PSH -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL ALL -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,FIN,PSH,URG -j DROP
$ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP


2.14 連接管理
允許環(huán)回連接
$ iptables -A INPUT -i lo -j ACCEPTiptables -A OUTPUT -o lo -j ACCEPT
允許已建立和相關的傳入連接
$ iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
允許已建立的傳出連接
$ iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
內部到外部
$ iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
丟棄無效數據包
$ iptables -A INPUT -m conntrack --ctstate INVALID -j DROP
阻止 IP 地址
$ iptables -A INPUT -s 192.168.1.10 -j DROP
阻止和 IP 地址并拒絕
$ iptables -A INPUT -s 192.168.1.10 -j REJECT
阻止與網絡接口的連接
$ iptables -A INPUT -i eth0 -s 192.168.1.10 -j DROP

2.15 ssh & http管理
允許傳出 SSH
$ iptables -A OUTPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
$ iptables -A INPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT
允許所有傳入的 SSH
$ iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
$ iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT
允許來自特定 IP 地址或子網的傳入 SSH
$ iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
$ iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT允許傳入 HTTP
$ iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
$ iptables -A OUTPUT -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED -j ACCEPT
允許傳入 HTTPS
$ iptables -A INPUT -p tcp --dport 443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
$ iptables -A OUTPUT -p tcp --sport 443 -m conntrack --ctstate ESTABLISHED -j ACCEPT
允許傳入 HTTP 和 HTTPS
$ iptables -A INPUT -p tcp -m multiport --dports 80,443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
$ iptables -A OUTPUT -p tcp -m multiport --dports 80,443 -m conntrack --ctstate ESTABLISHED -j ACCEPT


?


2.16 包管理
記錄和丟棄數據包
$ iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j LOG --log-prefix "IP_SPOOF A: "
$ iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP
默認情況下,所有內容都記錄到 /var/log/messages 文件中:$ tail -f /var/log/messagesgrep --color 'IP SPOOF' /var/log/messages
丟棄或接受來自 Mac 地址的流量
$ iptables -A INPUT -m mac --mac-source 00:0F:EA:91:04:08 -j DROP
$ iptables -A INPUT -p tcp --destination-port 22 -m mac --mac-source 00:0F:EA:91:04:07 -j ACCEPT
阻止或允許 ICMP Ping 請求
$ iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
$ iptables -A INPUT -i eth1 -p icmp --icmp-type echo-request -j DROP
使用 random* 或 nth* 進行負載平衡
_ips=("172.31.250.10" "172.31.250.11" "172.31.250.12" "172.31.250.13")for ip in "${_ips[@]}" ; do ?iptables -A PREROUTING -i eth0 -p tcp --dport 80 -m state --state NEW -m nth --counter 0 --every 4 --packet 0 \ ? ?-j DNAT --to-destination ${ip}:80 done
or
_ips=("172.31.250.10" "172.31.250.11" "172.31.250.12" "172.31.250.13")for ip in "${_ips[@]}" ; do ?iptables -A PREROUTING -i eth0 -p tcp --dport 80 -m state --state NEW -m random --average 25 \ ? ?-j DNAT --to-destination ${ip}:80 done

http://www.risenshineclean.com/news/2644.html

相關文章:

  • 現在建一個網站一年費用只要幾百元網絡推廣平臺哪家公司最好
  • wordpress換電腦網站排名優(yōu)化教程
  • 做門戶網站的框架360地圖怎么添加商戶
  • 做游戲破解版的網站百度搜索關鍵詞排名優(yōu)化
  • 法人一證通主副證書管理新流程建站優(yōu)化推廣
  • 做微商在哪個網站打廣告好指數基金
  • 焦作做網站哪家好seo關鍵詞排名優(yōu)化案例
  • 西南大學校園網站建設往年考試卷產品網站推廣
  • 簡述網站開發(fā)設計流程圖深圳媒體網絡推廣有哪些
  • 廣州網站開發(fā)創(chuàng)意設計搜索關鍵詞優(yōu)化排名
  • 建網站怎么做百度文庫官網首頁
  • 蘭州網站移動端優(yōu)化百度托管公司
  • 大連網站推廣怎么收費整站seo排名費用價格
  • 哈爾濱網站備案地址關鍵詞優(yōu)化seo公司
  • 如何做網站網頁優(yōu)惠活動推廣文案
  • 公眾號網站制作淘寶seo優(yōu)化怎么做
  • 招聘網站做銷售2024很有可能再次封城嗎
  • 網頁設計個人簡歷長春網站建設方案優(yōu)化
  • 祝賀網站上線百度貼吧人工客服
  • 福州免費建站品牌企業(yè)滄州seo公司
  • wordpress加速樂沈陽網絡seo公司
  • 最新淮北論壇windows優(yōu)化大師使用方法
  • 張家界做網站商品推廣軟文范例300字
  • 網站如何做支付寶接口seo 工具推薦
  • 移動端網站模板怎么做友情鏈接交換的作用在于
  • 近期國內新聞熱點事件高級seo
  • 濰坊網絡營銷外包灰色行業(yè)關鍵詞優(yōu)化
  • 網站該怎么找到軟文代寫價格
  • WordPress添加live2dseo優(yōu)化包括哪些
  • 做網站有年費嗎作品提示優(yōu)化要刪嗎