Tag Archives: networking

Compile kernel module on Linode Debian VPS

Connection to linode hosts from within China can be poor from time to time. Choosing a suitable TCP congestion algorithm may alleviate that from insignificant to a great deal, your mileage may vary. Trying it out is always the best way to find out. Here I will show you how to do that step by step.

  1. Login to your VPS and find out the version of the running kernel

    # uname -a
    Linux jhelom 3.12.6-x86_64-linode36 #2 SMP Mon Jan 13 18:54:10 EST 2014 x86_64 GNU/Linux

    That is 3.12.6.

  2. Go get the 3.12.6 from kernel.org at https://www.kernel.org/pub/linux/kernel/v3.x/
  3. Extract it and copy the kernel config over from the current one.

    # tar xf linux-3.12.6.tar.xz
    # zcat /proc/config.gz > .config
    # make oldconfig
  4. Now, edit .config with an editor such as vi, look for the line CONFIG_TCP_CONG_ADVANCED, remove the line, and add the following lines there:

    # CONFIG_DEFAULT_RENO is not set
  5. Now compile the kernel and the modules.

    # make -j4
    # make modules SUBDIRS=net/ipv4
  6. If everything goes well, you will be able to load the module.

    # sudo insmod net/ipv4/tcp_hybla.ko

    Check with lsmod and make sure the kernel module is loaded successfully. If not, check dmesg for any errors.

That’s it!

Is switching proxies on Mac OS 10.5 scriptable?

I often need to change the network proxies settings frequently due to the need to bypass the GFW when accessing websites that are considered “bad”, and have to set the settings back to not using any proxies when accessing “good” websites.

Doing so in Firefox is easy thanks to the little yet handy plugin called SwitchProxy, but for Safari or other applications which use the global system settings of Mac OS, one has to go through many steps in System Preferences to set them, and then go through the exact steps again to unset them. Too repetitive. I wish there is a way to set and unset proxies easily, but I cannot find one. I bit the bullet and use AppleScript (yuck) to do that, here’s the complete script (beware, this is my first AppleScript program):

I hate to use AppleScript as it simply plays back what a human does, and so the speed is slow, which takes about 5 seconds to finish. I tried to do that by shell script but I couldn’t find the right way to do so, having looked at the defaults command but seems it is not capable at what I want. Anybody knows?

簡單測試 bandwidth 方法

公司需要在北京找一個 data center 放 server,最後通過 agent 決定在位於中關村科技發展大廈的電信通數據中心(前身中關村數據)租了一個 2U 100M shared 的地方。Agent 說能保證 bandwidth 最少 1Mbps,最多也不會超過 1.2Mbps。但基於 sales 的不可信性,還是有自己去測試一下 bandwidth 的必要的。這裡給大家一個簡單的 poor man’s way 來測試 bandwidth,一般人會用 HTTP/FTP 傳送 file 的方法來看一下速度有多快,但是需要先裝好 HTTP 或 FTP daemon。我喜歡用 netcat,因為使用非常簡單。除了 netcat,你亦需要一個用來 monitor network bandwidth usage 的軟件,用來查看實際的網絡流量,推薦使用 muninntop

netcat 的使用方法非常簡單,步驟如下:

  1. 假設我的 server 叫電腦 A,你需要再多找一台電腦,叫電腦 B(我就找了一台在香港 data center 的 server)
  2. 在電腦 B 執行命令:netcat -l -p 10000 > /dev/null。意思就是用 netcat 監聽 port 10000,而且接收到的所有 data 都當成是垃圾扔到 /dev/null 這個黑洞裡。
  3. 在電腦 A 執行命令:netcat [電腦 B 的 IP] 10000 < /dev/urandom。意思就是連接到電腦 B 的 port 10000, 並且不斷 send data。 Linux 會為 /dev/urandom 不斷的供應一些隨機的 data。

就這樣,便可以測試電腦 A 的 outbound bandwidth 了。再多找兩三台電腦(當然是在不同的 network 的)同時 send 和 receive,差不多就能把可用的 bandwidth 用盡了。如果要測試 inbound bandwidth,把 A 和 B 的身份對換就可以了。

P.S. 測試後發現,bandwidth 比想像中的要好,深夜的時候可以達到 3Mbps,連到國內的 server 更可以達到 10Mbps!到白天基本上 bandwidth 就回落了。

Network bandwidth testing for Beijing server using munin