Resolved: Arch Linux WiFi issue

When I connected my laptop running Arch Linux to a new WiFi this morning, it worked for a brief moment then all connections were dropped. Connecting to the same WiFi with phone or Macbook works fine so the problem is at Arch LInux(AL)’s end.

Then I noticed if I do a route it actually showed 2 entries for the LAN. I took a closer look and saw there were 2 IPs for the wireless interface!

Strange enough if I connect to the hotspot of my phone, AL will also have 2 IPs but the connection is still working.

So I googled a bit why there will be 2 IPs, here’s what I got:

https://raspberrypi.stackexchange.com/questions/13359/where-does-my-secondary-ip-come-from

Finally, after I shutdown and disabled the dhcpcd service with

sudo systemctl disable dhcpcd
sudo systemctl stop dhcpcd

and restarted NetworkManager, the problem is fixed. Guess some WiFi AP is more tolerant than others.

🙂

Gotcha AWS NAT instance

It’s quite straight forward when creating an NAT instance for a private subnet in AWS, eg. search for amzn-ami-vpc-nat-hvm for the AMI then launch it into a public subnet.

However I need to disable source/destination check before the NAT instance becomes available in the drop down list of destinations of a route table:

🙂

土法制造 DDNS 完整版

节日快乐! 最近我又对之前的脚本完善了一下, 添加了对 CloudFlare DNS API 的呼叫, 这样 DDNS 才名副其实吧:

#!/bin/bash
function update_dns {
 logger 'Prepare to update DNS...'
 curl -i https://www.cloudflare.com/api_json.html \
 -d 'a=rec_edit' \
 -d 'id=DOMAIN_ID' \
 -d 'tkn=THIS_IS_MY_KEY_GO_GET_YOURS' \
 -d 'email=MY_EMAIL' \
 -d 'z=raynix.info' \
 -d "content=$1" \
 -d 'type=A' \
 -d 'name=XXX' \
 -d 'ttl=1' |logger
}
url='http://direct.raynix.info/ip.php'
last='/tmp/extip'
rcpt='MY_EMAIL'
extip=`curl $url`
echo $extip |diff $last -
if [ $? == 0 ]; then
 sleep 1
else
 if [[ $extip =~ [0-9]+.[0-9]+.[0-9]+.[0-9]+ ]]; then
 logger 'last IP: ' `cat $last`
 logger 'new IP: ' $extip
 echo $extip > $last
 echo "New IP: $extip" |[email protected] mutt -s "IP Changed" $rcpt
 update_dns $extip
 fi
fi

以上脚本已通过实践检验, 但你用的话需要把那些大写的部分替换成你自己的哦. 🙂

土法制造 DDNS

自从上次我用树莓派(raspberry pi)做了个家用服务器后, 动态域名解析(DDNS)就从一种懒得过问的技术变成必须的解决方案了, 因为家里的 ADSL 的 IP 地址不是固定的, 偶尔会变化. 我看了若干现成的 DDNS 服务, 虽然有免费选项, 但限制颇多, 甚至有的要插播广告… 其实 DDNS 没啥技术含量的东西, 基本逻辑就是在客户端发送请求到服务端, 一旦发现客户端的外部 IP 地址已变, 就更新对应的 DNS 记录.

首先来写客户端, 使用的是我擅长的 Shell Script:

#!/bin/bash
url='http://direct.raynix.info/ip.php'
last='/tmp/extip'
rcpt='[email protected]'
extip=`curl $url`
echo $extip |diff $last -
if [ $? == 0 ]; then
 exit 0
else
 logger 'last IP: ' `cat $last`
 logger 'new IP: ' $extip
 echo $extip > $last
 echo "New IP: $extip" |mutt -s "IP Changed" $rcpt
fi

目前只是在检测到外部 IP 变化时给自己发邮件(把 [email protected] 替换成自己的邮箱哦), 下一步可以加入对 DNS 服务器 API 的调用, 以达到更新域名解析的目的. 测试通过后, 可以把这个脚本加入到 crojob, 每分钟运行一次.

服务器端就相当简单了, 只要输出客户端来访的 IP 即可(以PHP为例):

<?php
echo $_SERVER['REMOTE_ADDR'];
?>

🙂