<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Network on All about Raspberry Pi</title><link>https://hugozhu.site/tags/network/</link><description>Recent content in Network on All about Raspberry Pi</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 08 Mar 2013 00:00:00 +0000</lastBuildDate><atom:link href="https://hugozhu.site/tags/network/index.xml" rel="self" type="application/rss+xml"/><item><title>如何封杀尝试Raspberry Pi SSH密码的来源IP</title><link>https://hugozhu.site/post/2013/block_failed_ssh_attempts_with_iptable/</link><pubDate>Fri, 08 Mar 2013 00:00:00 +0000</pubDate><guid>https://hugozhu.site/post/2013/block_failed_ssh_attempts_with_iptable/</guid><description>&lt;p>Raspberry Pi整天开着，如果用缺省SSH端口对外开放，就会经常遇到扫描SSH密码的肉鸡。虽然密码不是很简单，但还是感觉很不安全的。&lt;/p>
&lt;p>系统的ssh登录日志文件在：/var/log/auth.log，登录失败时会记录以下格式的日志：&lt;/p>
&lt;pre>&lt;code>Mar 7 10:31:51 raspberrypi sshd[24510]: Failed password for root from 221.8.19.129 port 4066 ssh2
Mar 7 10:31:55 raspberrypi sshd[24514]: Failed password for root from 221.8.19.129 port 4079 ssh2
Mar 7 10:31:56 raspberrypi sshd[24518]: Failed password for sshd from 221.8.19.129 port 4080 ssh2
Mar 7 10:32:26 raspberrypi sshd[24522]: Failed password for sshd from 221.8.19.129 port 4149 ssh2
&lt;/code>&lt;/pre>
&lt;p>用最简单的Shell脚本来解决这个问题：&lt;/p>
&lt;h3 id="guardsh">guard.sh&lt;/h3>
&lt;pre>&lt;code>#!/bin/bash

last_ip=&amp;quot;&amp;quot;
tail -f /var/log/auth | while read LINE; do
{
 if [[ &amp;quot;${LINE}&amp;quot; =~ &amp;quot;Failed&amp;quot; ]]; then 
 ip=&amp;quot;$(echo ${LINE} | awk '{print $(NF-3)}')&amp;quot;
 if [[ &amp;quot;$last_ip&amp;quot; == &amp;quot;$ip&amp;quot; ]]; then
 echo &amp;quot;block $ip&amp;quot;
 #curl -s --data-ascii &amp;quot;uuid=&amp;lt;my iphone's uuid&amp;gt;&amp;quot; --data &amp;quot;body=${LINE}&amp;quot; http://raspberrypi/pushme 
 iptables -A INPUT -s &amp;quot;$ip&amp;quot; -j DROP
 fi
 last_ip=$ip
 echo $LINE
 fi
}
done
&lt;/code>&lt;/pre>
&lt;p>用root用户执行以下命令，也可以放到启动脚本里：/etc/rc.local&lt;/p></description></item><item><title>动态DNS程序</title><link>https://hugozhu.site/post/2013/dynamic-dns-script/</link><pubDate>Tue, 26 Feb 2013 00:00:00 +0000</pubDate><guid>https://hugozhu.site/post/2013/dynamic-dns-script/</guid><description>&lt;h2 id="动态根据宽带public-ip更新dnspod登记的域名">动态根据宽带public ip更新dnspod登记的域名&lt;/h2>
&lt;p>按照 &lt;a href="https://gist.github.com/833369">https://gist.github.com/833369&lt;/a> 逻辑重新用Go实现了，用更少的内存开销在Raspberry Pi上跑。&lt;/p>
&lt;p>替换上你的Email，密码，域名ID，记录ID等参数，就可以运行了。 会在后台一直运行，每隔30秒检查一遍IP，如果修改了就更新IP。&lt;/p>
&lt;p>获得domain_id可以用：&lt;/p>
&lt;pre>&lt;code>curl curl -k https://dnsapi.cn/Domain.List -d &amp;quot;login_email=xxx&amp;amp;login_password=xxx&amp;quot; 
&lt;/code>&lt;/pre>
&lt;p>获得record_id：&lt;/p>
&lt;pre>&lt;code>curl -k https://dnsapi.cn/Record.List -d &amp;quot;login_email=xxx&amp;amp;login_password=xxx&amp;amp;domain_id=xxx&amp;quot;
&lt;/code>&lt;/pre>
&lt;script src="https://gist.github.com/hugozhu/6506189.js">&lt;/script></description></item></channel></rss>