ysx24 發表於 2022-2-4 23:35:38

关于屏蔽所有境外IP 问题

<font face="&amp;quot"><font size="2"><strong><font color="#006400">境外对我来说没有任何流量帮助,</font></strong></font></font><font face="&amp;quot"><strong><font color="#006400"><font size="2">攻击源绝大多数来自于境外,所以屏蔽了所有境外IP源&nbsp; &nbsp;但是后台还是发现谷歌蜘蛛疯狂抓取,感觉没起作用<br /></font>网上找的,</font><font color="#ff0000">大家看看哪里问题</font></strong><br /><strong><font size="2"><font color="#0000ff">Linux服务器 屏蔽国外IP访问 </font></font></strong><br /><strong><font color="#8b0000">命令如下</font></strong><br /></font><ol><li>wget -q --timeout=60 -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf(&quot;%s/%d\n&quot;, $4, 32-log($5)/log(2)) }' &gt; /root/china_ssr.txt</ol><font color="#2b2b2b"><font face="Tahoma, &amp;quot">将下面脚本保存为/root/allcn.sh ,并设置可执行权限( 命令: chmod +x&nbsp;&nbsp;allcn.sh)<br /></font></font><ol><li>mmode=$1<br /><li><br /><li>CNIP=&quot;/root/china_ssr.txt&quot;<br /><li><br /><li>gen_iplist() {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;cat &lt;&lt;-EOF<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $(cat ${CNIP:=/dev/null} 2&gt;/dev/null)<br /><li>EOF<br /><li>}<br /><li><br /><li>flush_r() {<br /><li>iptables&nbsp;&nbsp;-F ALLCNRULE 2&gt;/dev/null<br /><li>iptables -D INPUT -p tcp -j ALLCNRULE 2&gt;/dev/null<br /><li>iptables&nbsp;&nbsp;-X ALLCNRULE 2&gt;/dev/null<br /><li>ipset -X allcn 2&gt;/dev/null<br /><li>}<br /><li><br /><li>mstart() {<br /><li>ipset create allcn hash:net 2&gt;/dev/null<br /><li>ipset -! -R &lt;&lt;-EOF <br /><li>$(gen_iplist | sed -e &quot;s/^/add allcn /&quot;)<br /><li>EOF<br /><li><br /><li>iptables -N ALLCNRULE <br /><li>iptables -I INPUT -p tcp -j ALLCNRULE <br /><li>iptables -A ALLCNRULE -s 127.0.0.0/8 -j RETURN<br /><li>iptables -A ALLCNRULE -s 169.254.0.0/16 -j RETURN<br /><li>iptables -A ALLCNRULE -s 224.0.0.0/4 -j RETURN<br /><li>iptables -A ALLCNRULE -s 255.255.255.255 -j RETURN<br /><li>iptables -A ALLCNRULE -m set --match-set allcn&nbsp;&nbsp;src -j RETURN <br /><li>iptables -A ALLCNRULE -p tcp -j DROP <br /><li>}<br /><li>if [ &quot;$mmode&quot; == &quot;stop&quot; ] ;then<br /><li>flush_r<br /><li>exit 0<br /><li>fi<br /><li>flush_r<br /><li>sleep 1<br /><li>mstart</ol><font color="#2b2b2b"><font face="Tahoma, &amp;quot">执行如下命令将开始拦截<br /></font></font><ol><li>/root/allcn.sh</ol><br /><br />境外<em>, </em>屏蔽<em>, </em>IP

老周部落 發表於 2022-2-5 09:47:17

别忘了 CDN

ysx24 發表於 2022-2-5 10:35:27

还真把cdn忘了!<br />对了,服务器级别的拦截境外ip&nbsp;&nbsp;cdn也能成为梯子么

老周部落 發表於 2022-2-5 10:39:19

<br />CDN 代理之后源 IP 就是 CDN 地址了,用户地址一般是通过 XFF 传过来,但是您这个判断不了 XFF ,判断 XFF 地址要在 Web Server 上做。

ysx24 發表於 2022-2-5 10:48:23

<br />虽然不是很明白,按你说的我做下功课<br />去查下相关信息<br />虽然度娘往往不靠谱

老周部落 發表於 2022-2-5 11:43:53

<br />嗯,您先了解下。<br />最简单的就是在 CDN 上做个禁止境外访问。

ysx24 發表於 2022-2-5 12:08:36

<br />对了,周大大&nbsp;&nbsp;<br />我弱弱的问一下&nbsp;&nbsp;dz的防盗链在哪,我怎么找不到?虽然宝塔也能实现这个功能,但是只有nginx有效,apache有bug无效<br />我更倾向于自带的,可是就是找不到防盗链设置

無名 發表於 2022-2-5 12:43:11

<br /><br />这个貌似只有以前旧的版本才有的功能,如图:<br /><br /><img title="22.JPG" id="aimg_13673" aid="13673" src1="static/image/common/none.gif" zoom="https://www.dismall.com/data/attachment/forum/202202/05/124116fsu7z8usyo5n615h.jpg" src="https://www.dismall.com/data/attachment/forum/202202/05/124116fsu7z8usyo5n615h.jpg" class="zoom" onclick="zoom(this, this.src, 0, 0, 0)" width="600" inpost="1" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" /><br /><br /><img title="21.JPG" id="aimg_13672" aid="13672" src1="static/image/common/none.gif" zoom="https://www.dismall.com/data/attachment/forum/202202/05/124116sxm2k46c606kad4s.jpg" src="https://www.dismall.com/data/attachment/forum/202202/05/124116sxm2k46c606kad4s.jpg" class="zoom" onclick="zoom(this, this.src, 0, 0, 0)" width="600" inpost="1" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" /><br /><br />现在3.4 和 3.5的版本都没找到。<br /><br /><img title="23.JPG" id="aimg_13674" aid="13674" src1="static/image/common/none.gif" zoom="https://www.dismall.com/data/attachment/forum/202202/05/124116x5761a3lpgeec6ab.jpg" src="https://www.dismall.com/data/attachment/forum/202202/05/124116x5761a3lpgeec6ab.jpg" class="zoom" onclick="zoom(this, this.src, 0, 0, 0)" width="600" inpost="1" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" />

ysx24 發表於 2022-2-5 12:54:21

……

老周部落 發表於 2022-2-5 14:20:38

<br />在 Apache 上设置会效果更好,如果必须论坛设置可以在附件设置里面找,截图的三个选项在新版本都有,但是效率不如 Apache 。
頁: [1]
查看完整版本: 关于屏蔽所有境外IP 问题