Don’t Need Ngrok When I Have SSH

I was trying to create a Slack app. In order to let Slack send REST requests to my dev environment, eg. http://localhost:9000, I searched a bit and saw ngrok. Ngrok is very handy for this kind of setup:

Slack -> -> localhost

However I just don’t want to install anything so I turned to Google and to my surprise SSH can exactly do this(for who knows how many years). I know I can forward a local port to a remote host to connect to a service behind firewall such as databases, this is my first attempt to forward a remote port to local so Slack API can contact my localhost.

Here’s a better article which explained how to do port forwarding in both directions with SSH.

In short, to forward a remote port to my localhost, I need to

1, update the sshd_config on remote host and have GatewayPorts enabled and then restart SSH service

GatewayPorts yes

2, in a local terminal, run the following command replacing with your server’s domain or IP.

ssh -nNT -R 9800:localhost:9000

Then test it with

curl -i

The request should be forwarded to your localhost:9000.


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:

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 才名副其实吧:

function update_dns {
 logger 'Prepare to update DNS...'
 curl -i \
 -d 'a=rec_edit' \
 -d 'id=DOMAIN_ID' \
 -d 'email=MY_EMAIL' \
 -d '' \
 -d "content=$1" \
 -d 'type=A' \
 -d 'name=XXX' \
 -d 'ttl=1' |logger
extip=`curl $url`
echo $extip |diff $last -
if [ $? == 0 ]; then
 sleep 1
 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

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