月度归档:2018年06月

利用CloudFlare设置Dynamic DNS(DDNS)

如果买了动态 VPS,IP 会经常改变。这时,就可以设置 DDNS 来获取动态 IP。比如,设置后,我可以用 ddns.zhaozhu.net 获取自己 VPS 的最新 IP。

获取 API

以 zhaozhuji.net 域名为例,在 CloudFlare 按提示添加域名 zhaozhuji.net 和对应的 A 记录 ddns.zhaozhuji.net,TTL 可设为 2 分钟。注意,DDNS 使用的域名不要开启 CloudFlare 的 CDN。

前往https://www.cloudflare.com/a/profile获取 API,把 API 一长串字符复制保存。

获取脚本

下载脚本 https://gist.github.com/larrybolt/6295160/raw/c634c48c001a411240fc78147949a6a32e1de370/cf-ddns.sh 到/usr/local/bin 目录:

curl https://gist.githubusercontent.com/larrybolt/6295160/raw > /usr/local/bin/cf-ddns.sh && chmod +x /usr/local/bin/cf-ddns.sh

配置

打开脚本进行配置:
vi /usr/local/bin/cf-ddns.sh

需要修改以下内容:


# 输入前面获取的 API
CFKEY=nvake8vn8ak8en8fjka88bnfe

# 输入 Zone name,如 zhaozhuji.net
CFZONE=zhaozhuji.net

# 输入域名的 id,如果不知道可先不填,运行一次脚本获取对应的 id 后再填入
CFID=

# 输入 CloudFlare 的账号邮箱,如 user@example.com
CFUSER=user@example.com

# 设置需要更新的 Hostname,如 ddns.zhaozhuji.net
CFHOST=ddns.zhaozhuji.net

# 设置 Cloudflare TTL,单位是秒,可填 120 到 86400 间的数值
CFTTL=120

输入bash /usr/local/bin/cf-ddns.sh运行脚本,会显示:

bash cf-ddns.sh 
No file, need IP
Missing DNS record ID
fetching from Cloudflare...
 => Incorrect zone, or zone doesn't contain the A-record light.acg.al!
listing all records for zone acg.al:
ID          RECORD        TYPE
133333332  zhaozhuji.net        "A"
133333333  ddns.zhaozhuji.net  "A"
133333334  www.zhaozhuji.net    "A"

这时,把 DDNS 使用的域名对应的 ID 填入刚才提到的 CFID 中,例如这里是CFID=133333333。保存退出后,再运行一遍 cf-ddns.sh,如果显示如下内容,则代表配置成功:

bash cf-ddns.sh
No file, need IP
Updating DNS to 9.9.9.9
Updated succesfuly!

crontab 定时运行

脚本配置成功后,需要让它定时运行,这里设置每 10 分钟运行一次 cf-ddns.sh 脚本。输入crontab -e,然后会有个 vi 编辑界面,在里面添加一行:

*/10 * * * *  /usr/local/bin/cf-ddns.sh >/dev/null 2>&1

crontab 的用法建议参考http://man.linuxde.net/crontab,涵盖了 crontab 服务状态的启动、重启、查看、简单配置等。另外也可以看看http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.htmlhttp://www.runoob.com/linux/linux-comm-crontab.html

参考

cloudflare-update-record.sh同样可设置 DDNS,配置也比较简单。

本文参考了PumpCloud 的教程

备注

有人提及换了域名再操作提示WAN IP Unchanged, to update anyway use flag -f true,这是因为脚本是检测到 IP 发生变化后,才会更新 CloudFlare 的 DNS。可以先手动在 CloudFlare 改 dns,下一次换 IP 时,脚本就会自动修改更新 CF 的 DNS(前提是设了 crontab 定时运行)。

如果有问题,欢迎留言。

手动安装deb

尽管首选的安装方式是通过软件包管理软件来安装,见第 3 章 添加、删除和更新应用程序,你依然可以下载并安装单独的软件包。Linux下有各种不同的软件包文件,大多数都与特定的Linux发行版本相关联。

如果你发现了想安装的软件包,建议你先通过软件包管理系统检查是否有适合Kubuntu本地的安装包,并安装替代版本。这样可以保证该软件完全与系统兼容。如果当时没有合适的软件包,你可以手动进行安装。安装过程与安装包的类型相关。

安装/卸载 .deb 文件

适用于Kubuntu系统的安装文件后缀名为 .deb,因为Kubuntu与 Debian GNU/Linux 关系密切。你可以单独的下载和安装 .deb 文件。你可能需要系统权限来完成上述动作 (参见 “Root和Sudo”一节).

安装某个.deb文件,简单的在.deb文件上Right单击鼠标,然后选择Kubuntu Package Menu->安装软件包。

或者,你可以在终端下输入如下内容来安装.deb文件

sudo dpkg -i 软件包名.deb
卸载.deb文件,可以使用Adept,或输入:

sudo apt-get remove 软件包名称
转换 .rpm 文件为 .deb 文件

另一种安装包类型是Red Hat Package 包管理文件,以.rpm为后缀。不建议安装其到Kubuntu系统上。在大多数的情况下,都有适用于Kubuntu系统的.deb 安装包可用。然而,实在有必要的情况下,可以通过程序alien将.rpm 文件转换为.deb 文件。

安装 alien 程序 (第 3 章 添加、删除和更新应用程序)。

在终端使用管理权限运行以下命令:

sudo alien package_file.rpm
基于源代码安装

后缀为.tar.gz 或 .tar.bz2 的文件是以tarballs 或 source 形式发行的安装包文件,这种方式在Linux下被广泛采用。如果在Kubuntu仓库下没有合适的软件包,你可以尝试用源文件编译。关于编译软件的消息,请参阅Ubuntu Wiki上的 编译软件 页面。

充分使用树莓派SD卡容量

前言
在编译opencv的时候,出现内存不够的情况,/root使用率100%,导致编译错误,所以需要拓展SD卡容量
google了一下,发现树莓派在默认情况下,仅仅使用了SD卡的4G容量,剩下的空间,属于空白分区,完全没有利用起来
所以,我们可以通过df命令,来调整linux分区的size
操作步骤
重新树莓派,进入命令行页面
登陆树莓派,用户名pi,密码raspberry
sudo su
切换至超级用户
df -h
显示出当前分区的状态和使用率
输入fdisk /dev/mmcblk0 加载SD卡
p打印当前分区
你应该会看到三个分区(mmcblk0, mmcblk0p1, mmcblk0p2),现在把分区2的信息写下来(/dev/mmcblk0p2)
我主要记录了开始扇区(122880)和结束扇区(8447999)的数值
按d开始删除分区
系统提示输入删除分区号,输入2
按n新建分区,然后依次输入p, 2
接下来输入原来记录的2扇区开始号(122880),记得替换成你自己的数字
按w保持配置
输入reboot重启树莓派
输入sudo resize2fs /dev/mmcblk0p2 更新系统
输入df -h看看,是不是已经完全使用了剩余空间

dongle小记

IMSI
dongle/s:imsi/$OUTNUM$

IAX设置

username=abc
type=friend
trunk=yes
transfer=no
secret=abcpassword
qualifyfreqok=25000
qualify=yes
host=1.1.1.1
forceencryption=yes
encryption=yes
disallow=all
context=from-internal
auth=md5
allow=alaw&ulaw&gsm

extensions_custom.conf模板


[from-trunk-dongle]
include => dongle-incoming-sms
include => dongle-incoming-ussd

[dongle-incoming-sms]
exten => sms,1,Verbose(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(echo "To: qq@163.com\nSubject: ${CALLERID(num)}\n\n${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - (${DONGLENUMBER}): " > /tmp/sms.txt)
exten => sms,n,Set(FILE(/tmp/sms.txt,,,a)=${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(ssmtp -F"110 SMS" -t < /tmp/sms.txt) exten => sms,n,Hangup()
exten => _.,1,Set(CALLERID(name)=${CALLERID(num)})
exten => _.,n,Goto(from-trunk,${EXTEN},1)

[dongle-incoming-ussd]
exten => ussd,1,Noop(Incoming USSD: ${BASE64_DECODE(${USSD_BASE64})})
exten => ussd,n,System(echo "To: qq@163.com\nSubject: ${DONGLEPROVIDER}\n\n${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - (${DONGLENUMBER}): " > /tmp/ussd.txt)
exten => ussd,n,Set(FILE(/tmp/ussd.txt,,,a)=${BASE64_DECODE(${USSD_BASE64})})
exten => ussd,n,System(ssmtp -F"110 USSD" -t < /tmp/ussd.txt) exten => ussd,n,Hangup()
exten => _.,1,Set(CALLERID(name)=${CALLERID(num)})
exten => _.,n,Goto(from-trunk,${EXTEN},1)

zerotier-one安装

Linux (DEB and RPM distributions)

We’ve found a way to make the easy but infamous “curl|bash” more secure. If your system has GPG, try this:

curl -s 'https://pgp.mit.edu/pks/lookup?op=get&search=0x1657198823E52A61' | gpg --import && \
if z=$(curl -s 'https://install.zerotier.com/' | gpg); then echo "$z" | sudo bash; fi

Some users may need to replace gpg with gpg2 in the above commands.

This first makes sure you have the contact@zerotier.com GPG key. If this succeeds it then fetches our install script and pipes it through GPG. This verifies the script against its embedded signature, and if it is valid only the verified portion is forwarded through to “sudo bash.” Otherwise the script is not executed and you will see a GPG error about signature check failure.

The install.zerotier.com script first characterizes your Linux distribution and adds the ZeroTier official package repository if we have one available for you. It then installs the zerotier-one package, enables and starts the service, and prints your new 10-digit ZeroTier address.

For those who are a bit more careless lazy brave, the script also works without GPG:

curl -s https://install.zerotier.com/ | sudo bash

RPMs are available for x86 and x64. DEBs for a wide variety of architectures are present, with x86 and x64 for almost any distribution and armhf, armel, mipsel, mips64, aarch64, etc. available for certain others.

If you want to manually add our repositories they can be found on download.zerotier.com and source code can be found on GitHub.

if install on OpenVZ, enable TUN/Tap, then start/stop the server

chmod 777 /dev/net

Force Apt-Get to IPv4 or IPv6 on Ubuntu or Debian

In this guide, we will configure apt-get to use only IPv4 or IPv6. This guide targets Ubuntu 14.04 and Debian Jessie, but may work for newer versions as well.

Fast command line option

If you want to force the apt-get to use IPv4 or IPv6 only one time, follow these steps. This feature is available after the 0.9.7.9~exp1 version of apt-get. First, make sure your version of apt-get is newer than 0.9.7.9~exp1 by running the following command:

apt-get --version

The result will be something like this:

apt 1.0.1ubuntu2 for amd64 compiled on Oct 28 2014 20:55:14

If the version checks out, then you can force IPv4 with:

apt-get -o Acquire::ForceIPv4=true update

or IPv6:

apt-get -o Acquire::ForceIPv6=true update

This will update the repositories resolving the URLs in sources.list to IPv4 only.

Persistent option

To make the setting persistent, create the file 99force-ipv4 in /etc/apt/apt.conf.d/.

sudoedit /etc/apt/apt.conf.d/99force-ipv4

Put the following contents in it:

Acquire::ForceIPv4 "true";

Save the file, and you’re good to go. If you want to force IPv6 instead, change the 4 to 6 in the file name and settings. To choose between one of them, test with the fast method and see which works better.

树莓派升级内核到4.90并开启Google 的bbr tcp加速

Google 开源了其 TCP BBR 拥塞控制算法,并提交到了 Linux 内核,最新的 4.9 版内核已经用上了该算法。根据以往的传统,Google 总是先在自家的生产环境上线运用后,才会将代码开源,此次也不例外。
根据实地测试,在部署了最新版内核并开启了

#
#
sudo rpi-update
#升级完成后重启树莓派

sudo reboot
#重启之后,查看一下当前的内核:

uname -r
#4.9.4-v7+
#已经是 4.9.4了,现在可以启用 BBR

sudo bash -c 'echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf'
sudo bash -c 'echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf'
sudo sysctl -p
#使配置生效。
#重启树莓派

sudo reboot
#重启完成后然后可以检查一下:

sysctl net.ipv4.tcp_available_congestion_control
##net.ipv4.tcp_available_congestion_control = bbr cubic reno

lsmod | grep bbr

TCP BBR 的机器上,网速甚至可以提升好几个数量级。前几天Raspbian 官方加入 BBR 流量拥塞控制算法。tcp_bbr 20480 14
结果里边已经有 BBR 了,说明启用成功。