Category Archives: GNU/Linux

My tweet you just read says the long story short. In case you didn’t come across, Google made DNS a buzzing topic again with Google Public DNS. So I felt like trying a dns cache again. The logic is “If a better DNS server makes things better, DNS cache makes it even better.”

This is more of a note to self than a HOWTO. If your use case atches with mine, feel free to use this.

My use case: I use an HSDPA, mobile broadband connection on Ubuntu 9.04 Jaunty Jackalope.

Install pdnsd with,

$sudo apt-get install pdnsd

Now launch the text editor you hate and add following to /etc/pdnsd.conf

(By default all the parts are commented so just adding this was fine enough for me)


server {
ip=208.67.222.222 , 8.8.8.8;
timeout=5;
interval=30;
uptest=ping;
ping_timeout=50;
purge_cache=off;
}

global {
 perm_cache=5120;
 cache_dir="/var/cache/pdnsd";
 min_ttl=15m;       // Retain cached entries at least 15 minutes.
 max_ttl=1w;        // One week.
 timeout=10;        // Global timeout option (10 seconds).
}

I copied this piece from here and edited ;). Added the global field because defaults were not cool enough for me. And in ip field I’ve put respectively OpenDNS and Google DNS addresses. You can just add one address there. ‘man pdnsd.conf’ will teach you more about the content in the file.

Once you are done editing the configuration file restart pdnsd with

$sudo /etc/init.d/pdnsd restart

Now you should tell the network manager to look for pdnsd for it’s DNS needs.

Right click network manager icon and then follow Edit Connections > Mobile Broadband and choose to edit your preferred network connection.

In Editing <Your Network Connection> dialog box,
[1] Choose IPv4 Settings tab
[2] Choose Automatic Addresses (ppp) Only in Methods Dropdown box.
[3] Set DNS Servers field to 127.0.0.1 (which refers to pdnsd in our case)

And obviously, Apply Changes :P .

If everything went fine, you are now ready to enjoy DNS cache goodness with pdnsd.

You can check how good is it with dig command.

ex:
$dig yahoo.com

run this command twice and compare Query time field.

Note: If you followed all the steps but still it doesn’t work, try restarting pdnsd. If you get following error refer this page

/etc/resolv.conf must be a symlink

Update: Added the global settings for config file.

Hacking is always fun. That’s why I always lose focus on everything one interesting hack. That’s why I spent whole last night trying to figure out how to mimic Window focus event in a shell script. Though this is completely new to me, you maybe very much comfortable with implementing it :) . If so please let me know in comments.

Anyway here is my story.

I found this nice command line IM client called centerIM (Thanx @chathuraw for info). Once I got it set up I was just scanning on it’s documentation page & came across this interesting part “External actions & auto-responses“. I wrote a script right away for GUI notifications, inspired by notify.pl script for irssi. Here is the script if you are interested.

Since the load of IM messages was very high at a time & It was useless when the terminal window with centerIM was already focused (which means I’m chatting on centerIM) I was thinking of getting notifications only when centerIM window is not in focus. Few Google searches lead me to very limited resources & I chose xwininfo & xdpyinfo commands for my work.

Workaround: I’m using gnome for now & so gnome-terminal as my terminal emulator. I had to set edit > profilepreferences > Title & command option to keep initial title, in order to have “Terminal” as the terminal window name all the time.

And ran xininfo to get following output.

chanux@nim:~$ xwininfo -name Terminal

xwininfo: Window id: 0x3800003 "Terminal"

 Absolute upper-left X:&nbsp; 0
 Absolute upper-left Y:&nbsp; 52
 Relative upper-left X:&nbsp; 0
 Relative upper-left Y:&nbsp; 27
 Width: 1280
 Height: 691
 Depth: 24
 Visual Class: TrueColor
 Border width: 0
 Class: InputOutput
 Colormap: 0x20 (installed)
 Bit Gravity State: NorthWestGravity
 Window Gravity State: NorthWestGravity
 Backing Store State: NotUseful
 Save Under State: no
 Map State: IsViewable
 Override Redirect State: no
 Corners:&nbsp; +0+52&nbsp; -0+52&nbsp; -0-25&nbsp; +0-25
 -geometry 156x37+0+25

This can be used to get the window id of the windw which runs the script.

Then I can find the focused window at the moment as following.

chanux@nim:~$ xdpyinfo |grep focus
focus:&nbsp; window 0x3800004, revert to Parent

I fetched the window IDs with a little bit more work.

Anyway the problem I had is that, I get 0×3800003 (at this example) or likewise for the Terminal window id & even when the Terminal id is focused I get 0×3800004 as the focused window id. Yes I know with some more work I can manage to handle that & come to a point that I can compare those window Ids to check for the focused window. But I reall like to know why that difference come up. Anyone have an explanantion? Or anyone like to mess with this?

Following is the way I fetched window ids from above outputs

chanux@nim:~$ xwininfo -name "Terminal" | grep xwininfo | cut -d " " -f 4
0x3800003
chanux@nim:~$ xdpyinfo | grep focus | cut -d " " -f 4 | sed s/,//
0x3800004

It’s over. The fight against the dynamic DNS is over for me now. It took me so long to figure this simple thing out. But I don’t worry, even the big bro Goog couldn’t come up with a satisfying straight answer for my problem. So I myself searched under the mattress & found the pea which took my good night sleep (I’m neither a princess nor prince ;) ).

Sometimes back I had to come up with a pretty shitty solution for a shitty problem. No I didn’t won’t to show how bad my thinking or coding is. But wanted to show how shitty is the service of my ISP. But however the right way to fix all those are here with me. And I’m gonna share it with you.

If you use wvdial to dial up (Ok, now only seven people at most will continue reading this) for your internet connection, and you hate the DNS servers come your way automagically, here’s what to do.

Open /etc/ppp/peers/wvdial with your favorite text editor & comment the line usepeerdns. I mean make it look like #usepeerdns. Now wvdial won’t ask pppd to fetch those crappy DNS addresses again.

So go and edit your /etc/resolv.conf file and add you favorite DNS servers there. Mine looks like following.

nameserver 127.0.0.1
nameserver 208.67.222.222
nameserver 208.67.220.220

Wonder why I use 127.0.0.1 there? That’s because I’m a happy user of dnsmasq (I recommend you to use it). I used this simple HOWTO to install it on Ubuntu. There should be other guides & HOWTOs which might match you (In case that one doesn’t fit). Just ask big bro Goog.

And other nameservers are of the nice free DNS service OpenDNS.

For me Ubuntu is Linux *even* for idiots, not Linux for human beings. I do not hate Ubuntu. It’s an all time great GNU/Linux distribution. It’s only fault is not mentioning GNU. No I can’t see it on CD covers or anywhere. Maybe it’s there on a very small font size.

Yes I know Mark Shuttleworth is in GNU’s side & I’m pretty sure that he has never imagined that the mistake of not mentioning GNU would go this far. Ubuntu is ubiquitous & that’s very good. that’s very good if everyone who gets hands on it also get to know that it’s there because of the “freedom”. The freedom which Linux(the kernel) gives us. The freedom the GNU gave life to.

In my humble opinion Linux (Let’s call it just Linux for now) has come so far only because of so called freedom. Even Unix is great. The only problem with it is “it’s. just. not. free. Like GNU/Linux” So make it clear now that Linux they are quarreling that should ever remain just Linux, is there for them because the freedom & that freedom came with GNU. Is that clear enough?

In case of Ubuntu, the problem with Ubuntu as I see is it’s promising to be idiot friendly. Thanx to that effort, the Window$ fanbois who are inspired by dumped away hacking tuts & dumb hacking films & want to use Linux(They don’t know it’s Gnu/Linux) are having the chance of using it the idiot way they like. That’s the main problem with ubuntu..oh I’m extremely sorry..It’s not the fault of Ubuntu..it’s the fault of those idiots who desperately wanted to use *Linux*…somehow. So called idiots don’t know how that heavenly ease has come to them. They don’t know that it is there thanks to not only GUI but also hundreds of GNU tools lying under the beauty.

Ubuntu comes Free of charge thanks to the freedom I mentioned before & hell yeah thanks to mark shuttleworths brilliant dedication. Those windows & Mac users(not necessarily fanbois) who knows money is precious, come to Ubuntu because it’s great & free with hell a lot of advantages than their former OSs. But they don’t know why & how Ubuntu came free.

What I wanted to mention here is that Ubuntu had to mention GNU somewhere which every Ubuntu user would see. Then every one gets to know how Ubuntu came to their desktop. Maybe the users won’t ever think why GNU is there. But now there’s nothing wrong with Ubuntu at least.

Again I say Ubuntu is great. No wonder Donald E. Knuth is also using Ubuntu (No wonder those idiots don’t know who is Knuth). But why the hell I raise finger only at Ubuntu? No I’m not. All the Linux distros who use GNU to make it really an OS & do not mention GNU, should have a finger raised at them :evil: . Ubuntu is special because it’s ubiquitous. Just that.

If someone desperately want to use just Linux & s(he) hates GNU, there’s always another way. Try kicking off all GNU stuff. And. Have. FUN. ROTFL

Let me conclude. GNU is great, Linux is Great, Ubuntu is great. And so Ubuntu GNU/Linux is Great :).

(And recently I heard of Ubuntu fans who don’t hate windows. Yes they had mentioned it so bold. We GNU/Linux lovers too don’t hate Windows. We just know/believe it’s not the best OS out there. Just not the reason of those idiot fanbois)