Boosting network for your PC – DNS settings

Do you think your web browser is not so fast as you expected? I decide to write a series of articles to support you speeding up your network. Follow me to tune your settings and get joys surfing the net!

This article is written on Linux, especially I am using Ubuntu 9.04, but I will try to mention notices for other distributions and platforms.

This is the first peice in ‘Boosting network for your PC’, the topic is DNS settings. One question, does your ISP ship low quality DNS service?

At first place, I recommend you to use OpenDNS, whose slogan is ‘Safer, Faster and Smarter’. Let me tell the reason why to turn form your ISP’s service to this one. OpenDNS is a free service, and there is many features other providers cannot give you, such as a smarter site guide, spell checking, and smart cache to keep your query while the requested site’s name server is not working properly, phishing and malware site bloking … Somebody might say we can use client-based tools to do most of them, but do you think it’s a better way to keep the annoyance away from the source? There is more features provided and I haven’t listed one by one, but it worth a try.

It is not difficult to turn to OpenDNS, set main DNS server to 208.67.222.222 and backup server to 208.67.220.220 on your PC’s connection setting or on your router. Generally we can change it in resolv.conf on a Linux machine, but GNOME users should do it on network-manager if you use it because it will rewrite resolv.conf automatically. For those who use xDSL, edit your DSL setting, you can find IPv4 option tab, change the method to PPPoE Address Only, and input the two DNS server addresses in order “main, backup”.

If you have a static IP address, then you should register on https://www.opendns.com, add your network’s IP address to your dashboard, then set your own settings for content filtering, enable the SmartCache, block internal IP addresses to avoid DNS Rebinding Attacks, thus these features are not enabled or can be customized. If you use a dynamic IP address, for example, you are a xDSL user, don’t worry about you cannot have your own account and your custom settings. All you need to do more is install a client to update your address to OpenDNS’s server, and enable the dynamic update feature in you dashboard. On Windows and Mac, they provide their client programs, you can just install can configure it easily according to the guide; on Linux/Unix, you can use ‘ddclient’ which is a free software, you can download it from its homepage on http://ddclient.sourceforge.net, or you may find it just lying in your distribution’s repository. I recommend you to install it as a service, or called daemon. Here is a example for what I have done on my Ubuntu box:
1. Install ddclient using apt, or synaptic, or whatever package manager you like, here is what I ran in a terminal:

sudo aptitude install ddclient

You don’t need to care about what you have chosen on the debconf interface, soon we’ll chage the configuration file.

2. Configure ddclient via editing its configuration file, use whatever editor you like to edit /etc/ddclient.conf first, for example I run this command:

sudo vi /etc/ddclient.conf

Then make your file look like this:

daemon=600
syslog=yes
ssl=yes
pid=/var/run/ddclient.pid
protocol=dyndns2
use=web, web=whatismyip.com
server=updates.opendns.com
login=your-account-name
password='your-account-password'
your-lable-in-account-settings

The first line without # at its start intends to tell ddclient refresh information to the server every 600 seconds if it is running as a daemon. This section is not needed for Ubuntu user in fact, because it is configured in the other file we’ll look at, just a note here for others who many use it. I think 600 is a suitable value for most network, or you can adjust it to meet your actual needs. Update the information too frequently is a waste of resource, having a too long interval time may let your service not working so properly sometimes.

The second line intends to make every update logged at syslog, you can delete this line if you don’t want to.

The third line is for turning on ssl support, in other word we can transfer our account information using an encrypted route.

The forth line is the PID file path, don’t change it unless you know what your are doing exactly.

The fifth line tells what protocal you use, OpenDNS requires dyndns2 protocal.

The sixth line is the way you get your current IP address for transferring to the server, the defaut value was “use=if, if=”, than means you can set a net interface such as eth0 here and ddclient will send eth0’s address. When we are using PPPoE or other virtual connection protocal, this configure may be damnned, so we set it using web to check you real IP, whatismyip.com is the host provide such service, you can change it to something you like, but I think copy-and-paste this line to your configuration is the best choice.
The next three lines is the information about the server and your account, you should copy the server address, and fill in your account name and password there. Don’t worry about your account’s security here, the ddclient.conf is only accessable for root user by default, and we have chosen to use ssl at the begging of this configuration.

The last line is the LABLE you have set in your dashboard, they are something might be Home, Office, etc.

Next, we should enable daemon mode for ddclient, edit /etc/default/ddclient.conf with root privilege:

sudo vi /etc/default/ddclient.conf

Make sure the following lines are just look like what have shown below:

run_ipup="true"
run_daemon="true"
daemon_interval="600"

The first line is whether ddclient does an update while a new ppp conection is establed, this is useful for those who use a xDSL, or other dial-on-demand connections.

The second line is whether ddclient run as a daemon, we change it to true here. Only run as a daemon, it can perform the set actions automaticlly.
The last line is how long should it takes from one update to another, I was explained before in the first line of previous configuration file.

3. Restart ddclient to make everything into effect.

sudo /etc/init.d/ddclient restart

We have finished configuring OpenDNS till here, visit https://www.opendns.com/welcome/ to check!

Second, use DNS cache to speed up the look up action. This is for Linux/Unix users, I don’t know if there is any good replacement for other platforms. I introduce dnsmasq here to do this task.

1. Install dnsmasq, you can find it in main aspect of distributions‘ repository.

For Ubuntu, perform the following action:

sudo aptitude install dnsmasq

2. Edit /etc/dnsmasq.conf to fit our use:

sudo vi /etc/dnsmasq.conf

And make sure the following line is uncommented:

listen-address=127.0.0.1

You can choose to change other settings if you are interested in the file, there is enough comments for you to know what every options sense, but leave it there is a good solution.

3. Restart dnsmasq

sudo /etc/init.d/dnsmasq restart

4. Add 127.0.0.1 to you DNS list. We can edit resolv.conf to make that line at first of ns servers, or change in network-manager.

5. Restart networking, you don’t need to restart your computer.

sudo /etc/init.d/networking restart

So close and re-open your web browser, do you feel web pages load faster?

Third, tune your firefox(if you use it). Input about:config in your firefox location bar, filter the following items and change their values to ‘true’:

network.http.pipelining
network.http.proxy.pipelining
plugin.expose_full_path

And change the following item’s value to 8 or 10:

network.http.pipelining.maxrequests

Add these items to the list via right click and choose ‘Add -> Interger’, note to set the value according to the last number listed below:

nglayout.initialpaint.delay 0
content.notify.backoffcount 5
ui.submenuDelay 0

If you don’t have IPv6 connection, also change this item’s value to ‘true’:

network.dns.disableIPv6

Restart your firefox will make it effect.

In Ubuntu 9.04, the IPv6 support was built in kernel, if you compile kernel by yourself, you can uncheck this feature if you don’t need it.

Differences among several kernel signals

Here is the final summary.

Today I was fuzzied by the help content of the command ‘timeout’, as its name suggest, it a COMMAND, and kill it if still running after a specified period of time. Because of its termination action, I met something related to signals. Googled and finally make a summary here, that is, what’s the differences among HUP, INT, KILL, TERM, USR1 signal.
Everytime when we shutdown our Linux box, it will show “Sending all processes the TERM signal” then “Sending all processes the KILL signal”. Definatly, the TERM signal can be more graceful than KILL, but the best thing we should do now might be looking up the manual page.
In the manual page of kill(7), we get something like this (I’ve ignored things not closely connected to our topic, same below):
Name    Num    Action    Description
————————————————————-
HUP        1        exit
INT        2        exit
KILL        9        exit        cannot be blocked
TERM    15        exit
USR1            exit
Seems not so much information provided. Anyway, we can know they are all related to the process exit action,and the KILL (9) signal cannot be blocked, in other words it cannot be caught by a process so they don’t have the chance to have actions to block it.

Then I searched Google and found some hints from Apache httpd documentation.In the section of Stopping and Restarting, we can see content which have the meaning like this (all signals should be sent to a parent process in this place):
TERM – stop now: The parent immediately attempt to kill off all of its children. It may take it several seconds to complete killing off its children. Then the parent itself exits. Any requests in progress are terminated, and no further requests are served.
USR1 – graceful restart: The parent “advise” the children to exit after their current request (or to exit immediately if they’re not serving anything). The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration, which begins serving new requests immediately.
HUP – restart: The parent kill off its children like in TERM, but the parent doesn’t exit. It re-reads its configuration files, and re-opens any log files. Then it spawns a new set of children and continues serving hits.

But things provided still cannot explain our question. Ah, from the last line of manual page of kill(7) we can see there should be another page named ‘signal’. Okay, look up into it and here is what we get :
Signal    Value    Action    Comment
—————————————————
SIGHUP    1        Term    Hangup detected on controlling terminal or death of controlling process
SIGINT    2        Term    Interrupt from keyboard
SIGKILL    9        Term    Kill signal
SIGTERM    15        Term    Termination signal
SIGUSR1    30,10,16    Term    User-defined signal 1
SIGUSR2    31,12,17    Term    User-defined signal 2
Hoo! More information are displayed!

Finally, we can have a short summary:

TERM – Terminate – This signal you send if you want to end a process. It allows the process to clean up nicely though, not like the -9 option (KILL) which just ends everything.
INT – Interrupt – This is a permission which for instance can be used in an NFS environment. If a process hangs, you can interrupt it with say the Ctrl C option.
KILL – exactly what it says. It kills a process without allowing it to clean up, meaning, end all threads, kill child processes etc. It just stops it and can leave either files or other processes in an inconsistant state.
HUP – Hang UP – What this signal does is, when you send it to say the inetd process, it basically tells inetd to go reread it’s configuration file as certain changes have been made which you have to incorporate now. The process doesn’t actually stop, it just, like stated, rereads it’s config.
USR1 – This is a user defined signal. For instance, on our Tru64 systems, we use this signal to tell say the binary log daemon to go save it’s current log file, archive it, and then start a new one. I imagine though it could be used for many other things, thus user defined.

Reference:

1.Manual pages kill(1), signal(7).
2.Apache HTTP Server Documentation Version 2.2 – Stop and Restarting

Split .ape files with cue and convert to flac

Split .ape files with cue and convert to flac format is not so difficult.

We do it on an Ubuntu box for example:

First, install the dependency of shntool, flac, mac, cuetools

sudo aptitdue install flac shntool cuetools

and download mac package in form of deb or tarball.

Run the following command in a terminal:

shntool split -f FileName.cue -t '%n. %t' -o flac FileName.ape

and the output .flac files’ name follows this sequence:

1. Track1name.flac

2.Track2name.flac

Update:
2011-02-20:
FFmpeg supports decoding APE format since 0.5 release, and it’s very easy to convert APE to FLAC now:
ffmpeg -i Filename.ape -acodec flac Filename.flac
And Clementine supports CUE+APE/FLAC natively.

This work by Aron Xu is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported.