Security settings for a LAMP Server : Iptables

Security is the major concern for anyone hosting a website on the internet. These are the preliminary security settings to be performed to protect your server.

Our server stack is LAMP. Hence iptables as the firewall is the most natural choice. The requirements are like

1. Block everything except Ping, SSH, Apache, and SSL.
2. Enabled SSH only from the selected IP addresses.

The following script takes care of all iptables settings. (Idea copied from here)

Note: Please enter the command one by one. Make sure you replace IP1.IP2.IP3.IP4 with your own IP address.

# Establish a clean slate
iptables -P INPUT ACCEPT
iptables -F # Flush all rules
iptables -X # Delete all chains
# Disable routing. Drop packets if they reach the end of the chain.
iptables -P FORWARD DROP
# Drop all packets with a bad state
iptables -A INPUT -m state --state INVALID -j DROP
# Accept any packets that have something to do with ones we've sent on outbound
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# Accept any packets coming or going on localhost (this can be very important)
iptables -A INPUT -i lo -j ACCEPT
# Accept ICMP
iptables -A INPUT -p icmp -j ACCEPT
# Allow ssh
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow httpd
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# Allow mysql
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
# Allow SSL
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Block all other traffic
iptables -A INPUT -j DROP

I guess the above script should take care of the basic security issues. Hope it helps.

Apache Fix : NameVirtualHost *:80 has no VirtualHosts

I get this error every time I install apache web-server in an ubuntu machine. We use LAMP stack at Interviewstreet and this error was nagging me all the this while.

The error message shows up something like this.

root@interviewstreet:~# /etc/init.d/apache2 restart
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName
[warn] NameVirtualHost *:80 has no VirtualHosts ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName
[warn] NameVirtualHost *:80 has no VirtualHosts [ OK ]

After some googling, I found the actual solution at

The reason why this happens is because of having NameVirtualHost in more than one place. In this case, it occurs at 2 different files, sites-available/default and ports.conf.

So, this is how we fixed this issue.

1. Removed the line “NameVirtualHost *” from sites-available/default.
2. Changed “NamedVirtualHost *:80” to “NamedVirtualHost *” in ports.conf

Done. That fixes the problem. Now apache restart shows something like this.

root@interviewstreet:/etc/apache2/sites-available# /etc/init.d/apache2 restart
* Restarting web server apache2 ... waiting [ OK ]

This is sweet :)

The other day, I was poking a few sites on the web lazily, looking how they’ve designed the CSS, HTML etc blah blah blah..

I take a quick look at the tumblr source code and find this in the header πŸ™‚


3 interesting Codeigniter tips

Finally we’ve started doing all our development using a framework, Codeigniter. It has a small learning curve, simple to use and very flexible with how much you want to adhere to MVC pattern. You have the control to code every damn thing in the controller or have proper models and views to help the controller.

Three nice tips/tricks I found in Codeigniter after googling a lot.

1. How to print the last query executed by codeigniter when using active record?

The following function returns the sql query executed. You may need this for debugging purposes.


2. How to add a function in controller which can’t be accessed through URL?

Usually, if you add a function func in controller c, then it can be accessed by /c/func. If you want to code a function, which you don’t want people to access, then you need to name the function _func(). If you have a function named with a _ in front of it, then you can’t access it through the URL.

3. How to store the string generated by a view in a variable?

When you load a view using $this->load->view(‘view.php’, $data); the view gets rendered in the browser. But if you want to store the HTML string generated by the view in a variable, then add a third parameter TRUE, which will return the generated string.

The code will be
$output = $this->load->view("view.php", $data, TRUE);

Photolog 7…

Sambar Rice

Disclaimer :

  1. I didn’t cook this.
  2. This samba rice tastes like heaven!!!
  3. According to the person who made this, I’ve have been friend with a great person, coz she can cook this.
  4. This is called awesomeness πŸ˜‰

Social Life Limits

Social Networking sites like Facebook, Twitter, and Mail services like GMail, Yahoo Mail and Hotmail play a big role in our Internet Life.

What is the limits these sites impose on us? By how much can we push our internet life using these sites?


1. The maximum limit on the number of friends you can have on Facebook is 5,000.
2. A status update in Facebook is limited to 420 characters (including spaces).


1. A status update in Twitter is limited to 140 characters (of course, everyone knows this)
2. The maximum limit on the number of followers you can add in twitter is 1,000 per day.
3. The maximum limit on the total number of followers is 2,000 or 110% of your follower count, whichever is higher.


1. The maximum limit on the number of contacts you can have in Google is 10,000.
2. The maximum limit on the number of emails you can send from Gmail is 500 recipients per day for the Gmail web interface, or 100 recipients per day if you are using an email client software.
3. The maximum limit of the attachment size in Google Mail/Talk is 25MB.
4. There’s no limit to the number of people you can chat with in a group chat.


1. The maximum limit on the number of contacts you can have in Yahoo Messenger is 1,000.
2. The maximum limit on the number of emails you can send from Yahoo Mail is 100 recipients per hour.
3. A personal status message on Yahoo is restricted to 250 characters.


1. The maximum limit on the number of emails you can send from Hotmail is 100 recipients per day.
2. A personal status message on Windows Live Messenger is restricted to 128 characters.


1. The maximum limit on the number of participants you can have in a conference call in Skype is 25.
2. The maximum limit on the number of participants you can have in a public chat in Skype is 150.

Note: Of course, the numbers are bound to change. Please update in the comments if you want to add anything.

Advanced Bash Scripting – Part 1

Shell Script

Hello everyone, I’m planning to solve the problems in the Advanced Bash-Scripting Guide, say like one problem per week. Why am I doing this?

1. The problems there are very interesting.
2. Working in windows all the time, I feel I’m losing my shell scripting abilities. This will keep me updated.

The problem we are going to solve this week is “Testing Passwords”. The problem statement is as follows.

Write a script to check and validate passwords. The object is to flag “weak” or easily guessed password candidates.
A trial password will be input to the script as a command-line parameter. To be considered acceptable, a password must meet the following minimum qualifications:

1. Minimum length of 8 characters
2. Must contain at least one numeric character
3. Must contain at least one of the following non-alphabetic characters: @, #, $, %, &, *, +, -, =

Do a dictionary check on every sequence of at least four consecutive alphabetic characters in the password under test. This will eliminate passwords containing embedded “words” found in a standard dictionary.
Enable the script to check all the passwords on your system. These probably do not reside in /etc/passwd.

The command I’m planning to use for this is grep, with a few for loop constructs and string operations.

Let’s check the constraints one by one.

#Minimum length of 8 characters
if [ ${#password} -lt 8 ]
  echo "$password: $weakString"

#Must contain at least one numeric character
if [ `echo $password | grep -c -E "[0-9]+"` -eq 0 ]
  echo "$password: $weakString"

#Must contain at least one of the following non-alphabetic characters: @, #, $, %, &, *, +, -, =
if [ `echo $password | grep -c -E "[@#$%&*=+-]+"` -eq 0 ]
  echo "$password: $weakString"

#Do a dictionary check on every sequence of at least four consecutive alphabetic characters in the password under test. This will eliminate passwords containing embedded "words" found in a standard dictionary.
for((i=4;i<=${#password};i++)) do   for((j=0;j<=${#password}-$i;j++))   do     if [ `grep -c -E "^${password:$j:$i}$" dict.txt` -gt 0 ]     then       echo "$password: $weakString"       return     fi   done done

That's about it, we have checked all the constraints. Now, we will combine all the checks in one function and then we will pass all the command line parameters to this function one by one.

You can take a look at the final script here.

Can you make it any better or reduce the code size? Feel free to add it in the comments section.

Best Google Talk Status Awards :) :) :)

Trophy I’ve been watching (and storing) lots and lots of useful, fun and interesting Google Talk status messages for the last few months. It’s short, informative and the main reason why I never logout of Google Talk. So I was wondering what I might do IF I was given the responsibility to pick the top status messages like a film-fare festival and give away awards to the best ones.. So here we go…

We will begin the show with Brilliant Questions. There were way too many contenders for this category. It was very difficult to pick the best one. First, let’s take a look at the final 5 contenders who made it.

1. Abilash Prabhu - Why does Superman stop bullets with his chest, but ducks when you throw a revolver at him?
2. Dhruvkaran Meta - If electricity comes from electrons, does morality come from morons?
3. Akshay Kumar - I was the best man at the wedding. If I'm the best man, why is she marrying him?
4. JV - Why do couples hold hands during their wedding? ItÒ€ℒs a formality just like two boxers shaking hands before the fight begins!
5. Nitin Isloorkar - How do you see yourself five years down the line?" "If I had foresight, I wouldn't be here now, would I?

And the Best Brilliant Question Award goes to Dhruv for his electrons and morons question. What an idea sar ji! πŸ™‚

Next, we move on to Frustration category. Status message is first the place where people vent out their frustrations and we got ample messages to justify that.

1. Nitin Isloorkar - After Monday and Tuesday even calendar says W T F
2. Krithika Ravichandran - labs are like black holes.. once can never get out..
3. Lavanya Tejaswy - I want to see a ghost, real one!! *bored* with normal things.
4. Taggy - For want of a logo a night was lost. #photoshop

And the Best Frust status message goes to Krithika. It’s simple, but true. Happens to all of us all the time.

Next we have Funny Quotes status messages here.

1. Saurabh Gupta - Friendship b/w gals - A girl came home late, told dad she was at frnd's place.. Dad called 10 friends but all say she wasn't there... Friendship b/w boys - A boy didn't come home one night n told dad he was at frnd's flat... Dad called 10 of his frnds. 6 confirmed he had slept at their place... and 4 told he's still there.. ;)
2. Harishankaran - "I love Facebook. It's the only place I can talk to a wall and not look like an idiot"
3. PK- "Chuck Norris can parse HTML with regex"
4. Akshay Kumar - "Don't drink and drive. You might hit a bump and spill your drink."
5. Manish - 2b or not 2b is a decision you have to take when you enter 2nd grade

And the Best Funny Quote award goes to Akshay. The concern for the few drops of drink he might spill is mind blowing. πŸ™‚

Next, we will pick the best Interesting Links. Here again, we got hundreds of nominations at the first step. After filtering and filtering, we got the final 4

1. Ajitha - Lol......U gota be Kidding me!!!!!
2. Arun - Please don't click on this link
3. Interviewstreet - Resume vs CV - What's the difference?
4. Indus Khaitan - Who is an entrepreneur?

And the award goes to Indus Khaitan. Excellent presentation with awesome images. Congrats πŸ™‚

Next we will pick the best from Cricket. With an excellent 200 from Sachin, nothing else made to the top.

1. Abilash Prabhu - Reducing the number of atheists in India since 1989 - Sachin Tendulkar!
2. Swetha - Cricket. Sachin. Happiness. One guy- the ability to tug at the heartstrings of a billion. Divine!
3. Subbu - my only prospective achievement in life: when sachin scored a double century, i tweeted about it. #sachinisgod

And Abilash get’s the award. A fitting tribute to our little master blaster.

Now, we will pick the best from the Inspirational Quote

1. Sankara - To move quickly, go alone. To move far, go together." African Proverb
2. Poorna - Don't ever let somebody tell you... You can't do something. People can't do somethin' themselves, they wanna tell you you can't do it. If you want somethin', go get it. Period.
3. Sundarrajan : I look at my life as a seed investor.. I give seed capital for my interests.. knowing well that the odds are 1:10 for success.. but I am willing to do it.. coz.. that one in ten will become my passion

The best Inspirational Quote award goes to Poorna. I simply love that quote. In fact, I started storing status messages after I seeing that.

Finally, a few other special mentions in various other categories.

Madhu - I really don get y Mr.Cameroon waited so long.. I mean optical fibers were discovered a loooong time ago!!

Funny Quote
Lavanya Tejaswy - The fascination of shooting as a sport depends almost wholly on whether you are at the right or wrong end of the gun. P. G. Wodehouse

Job Offers
Manas Garg - Want to work for MS? Ping me.

Punch Dialogue
Karnan - I am not HANDSOME guy, but i can give my HAND to SOME guy who needs my help - ABDUL KALAM.

Personal Damage
Ajitha - Hari and his friends = Losers!!!!!
Doniv - You are a goat, why are you a goat ? Because you shout maee...

Bodhayan - Spider Annual Report 2008-09.. :) :)

Want to add more? Add them in the comments here. πŸ™‚ Keep them coming.. πŸ™‚

My Bangalore Trip

This is a personal post. It is all about me and what I did in the last 3 days. If you don’t know me at all, I strongly advise you to stop reading here and I apologize for taking your time. If you are geek like me and prefer to read a technical post, rather than this boring post, you checkout my post on chess interview questions.

I had a great weekend at bangalore and felt like blogging about it. I’ve also planned to write here at least once a week. So that too adds as a strong factor to write this post here. This post is much longer than I expected it to be. So please proceed when you are totally jobless.

The reason why I planned this trip is totally arbitrary. I just wanted to take a small break from work and meet my friends in Bangalore.

1. Latika (my IBM friend) always keeps us inviting to her place for meetup and we have loads of fun everytime we go there. Mortal Kombal, Raiden vs Bo Rai Cho, Dhani vs (Hari, Nandini, Latika, Shilpa), T20 match, “shopping” at lifestyle and lots more makes us go there again and again. Even if latika doesn’t invite us, we somehow make her do that πŸ˜› (at the loss of some maaanam)

2. Lavanya bought a new scooty and she was too excited about it. Exctied about skidding in front of forum, caught by a policeman for wrong u turn and loads and loads of stories. This time she promised for a long ride when I come there (thank god she is one of the people who is ok with others riding her bike)

3. Been a long time since I’ve met manu, alagu, suren, sahil, anshu, ankit, preeti, balli, pk, donatello and others. These guys are the people I ping/bug for any technical/non-technical related queries. In fact, most of the important decisions we decide at interviewstreet, I brainstrom with these people and the outside perspective adds lots of value and even refines the way we think. These guys aren’t MBA marketing wiz but they are smart people and any decision or idea they suggest usually has a good logical reasoning behing it.

I got a mail saying there is bigthinkers talk series at leela palace. The bigthinkers talks are usually very good and the food they provide after the talk is YUMMY. πŸ™‚ So, I decided this is the only chance to go to Bangalore and I grabbed it :). And it so happens, the OCC meet is also on sunday.

Was a little skeptical about going to bangalore with no well planned schedule ahead. Usually when I go there, I will have a tight packed schedule with at least 3 meetings per day and squeeze in visiting friends in between these meetings. So, this time I thought I’ll have a peaceful time at bangalore with spending most of my time in my bed. Alas, it doesn’t happen that way when you have too many many good friends to meet and too little time.

Friday morning, I went to Vemana Institute of Technology to propose for a one day talk about interviewstreet and how to tackle interview and stuff. We had given the same talk at Karpaga Vinayagam College near Chennai the previous day and were thrilled about the response we got. But things didn’t move that fast here. Everyone from HOD to the lecturers seemed to be busy with their own work. Guess this will need another trip to get things moving faster. Keeping my fingers crossed on what they are going to respond today. I’ll be very glad if this doesn’t need one more trip.

I was out of Vemana by 2 and the bigthinkers at leela is from 3 to 5 PM. Unfortunately, some 5 to 6 people who promised they will come with me to Leela ditched me at the last moment. So, I was thinking whether to go all alone or bunk the event. Reaching leela 10 mins before the event, I was saw Nithya from there. It was really a sweet surprise. Nitya and Prateek from Muziboo are really really sweet people who spent more than 2-3 hours with us last time discussing about interviewstreet, what we can do, why we should focus more on online marketing and many other things. I can never forget her jumping from her chair saying “we also did the same mistake.. You are exactly at the same position where we were 2 years back. Don’t do this“. It was almost like a mom trying to convice her kid that dogs are dangerous and they will bite you if you go near them. πŸ™‚ I was a little surprised to see her remember me and next 3 hours was discussion on muziboo, SEO, college visits and every single doubt I had in my mind at that time.

The talk by Rayleigh on the marketing reasearch was amazing. The number of factors he has considered so that external factors doesn’t affect his experiment is too good and made me think if I can do something on a smaller scale at interviewstreet.

After the talk, met friends of nitya and others who had come for that event. I realised that as an entrepreneur, you are never alone in any meetup. All you need is to say I’m X working for Y, exchange cards and talk to that person as if you know that person for months. It’s so simple.

Done with the networking at leela, met ankit, preeti and lavanya at pizza hut. Lavanya took the spotlight of the meetup with all the “extraordinary” things she has done. We can even call this as her “experiments”. To make a long story short, when you have lavi, it’s fun fun and fun. πŸ™‚

Done with the dinner, planned for the next day. Me and lavi decided to got to nandi hills (thought this turned out to be a “well tried” attempt). With so many meetups and travel, I was dead tired when I reached home and was shocked to know that the SEO talk by Steve Wiideman is at 2.30AM. Played cricket with my friends for an hour, slept at 11.30 and got up by 2.25 to attend the SEO call (remember, this was supposed to be a break from work. sigghhh).

Done with the call and got interviewstreet reveiwed by him. Slept again at 3.30 and was woken up by lavi at 4 for the nandi hills trip. Thankfully, she suggested we cancel the trip, since none of knew the way to nandi hills and to make things worse, she didn’t even know how to come to my place. :D. Went back to sleep again and got up at 12 for lunch. This is one thing I love at bangalore. Getting up at 12 or 1 or 2 and skipping lunch after that. :D.

Reached latika’s place by 2 and we ordered pizza’s and started our mortal kombat game series. This time, we weren’t able to kick dani’s ass like how we did last time. But I was able to kill shilpa every single time:). Had lunch, played games again, met ankur, played games again and when I left from their place, it was 9.30 :O. Should thank latika for putting up with us all the time. Her place has become the standard place for our IBM gang to hang out whenever I come to bangalore. :).

Done with meeting and chatting with my IBM friends, met lavanya again since she lives in the same apartment. Went to corner house, but this time no DBC. πŸ™‚ Can’t afford to do the same mistake again. Was literally shocked when she told me she knew that I don’t booz. I’m still clueless what went wrong in my whole plan. Again, back to home by 11, this time watched IPL highlights with friends (thanks to youtube) and slept at around 12. Had OCC and few other meetups planned for the next day and had to sleep early for that (yes, 1 is early)

Got up at around 8 on sunday, and was ready to OCC by 9. Lavanya also wanted to come for this. So went with her to OCC and talk Sharad gave was excellent. Especially, the way he puts things forward is simply awesome. With 25 years experience, he is full of success and failure stories and each one of them was well put there. Done with the event, had lunch and met donatello, pk, balli and suren to discuss if we can use their codechecker at interviewstreet. The way they are developing the product right now is very exciting and I’m 99% sure interviewstreet will use their codechecker and am actually waiting for their first stable release, so that we can use it in our production servers. πŸ™‚ Have to test their current beta version.

Done with the long feature discussion and demo of his codechecker, interviewstreet’s admin interface, architecture design and everything, got a 15 mins to nap and again, had to meet the LRSL (Last row of Sun Lab) guys. Unfortunately, appaji, sahil and taggy couldn’t make for this event. I have no clue how the next 4 hours flew. We discussed linux, web, hacking, cracking, google, yahoo, fedora, ubuntu and what not. (everything you can expect from a lrsl guy).

With a full dinner done, I was in no mood to pack and leave bangalore. Came back home with anshu and had long and fruitful discussion with him on how we can make facebook, orkut and blog widgets for interviewstreet which can be fun and useful. This is one main reason why I discuss stuff with techies. They have a logic behind their decisions. Got many many useful ideas from anshu and reached home like at midnight 12.

Almost did everything I wanted to do in bangalore. Now blogging on my way to chennai. Back to interviewstreet, interviews, analytics, customer call, college visit, ROI, analytics analysis, project graph curve path, figure out the reason why numbers came down, check where to do speed/SEO optimizations, how to increase pageviews/vists, increase articles and prep-kits, remove bugs. Phew!!!. That’s the long list of tasks I do almost everyday :O… Can’t believe I was the carefree software engineer, WFH almost 3 days week in IBM.

Guess that’s about it. See ya next week. Bfn. πŸ™‚ Regards

I am still alive

ThatÒ€ℒs true. My last post was exactly 3 months ago and I’ve posted only 2 posts in the last 6 months, but I’m alive. Lots and lots of new stuff has happened during these 6 months. Things which took up all my time and didn’t even let me think about blogging. Probably this is what happens, when you do something you love., the online platform to attend mock interviews from expert professionals and practice tests is shaping up very well. What I’ve learnt in the past 6 months is huge and impressive. I still have lots to learn and goals to reach. And I’m very sure I’ll reach it sooner.

Quick updates on what happened in the last 6 months (in no particular order)

1. Interviewstreet’s very first newsletter.

Don’t know why it took us 6 months to come up with a newsletter. Probably, we were waiting for the right time, design and content (also called as procrastinating). But from now on, you’ll get our newsletter on the first week of every month.

You can checkout our newsletter here. In this newsletter, you can check out what’s new in the job market, our special interview with kavya from microsoft, more updates from interviewstreet and a cool puzzle which has some exciting prizes to grab.

I should thank Geetanjali, Manas, Lavanya and Ajitha here. The time and effort they put in to make our newsletter better was priceless.

2. Articles.

Our articles section has grown by leaps and bounds. Many thanks to all the content writes who made this possible. The quality of the articles is wonderful. We are looking for more content writers who want to contribute for our articles section. If you are interested, contact me at hari at

3. Online recruitment software

This is still under the hoods and we haven’t released for it public yet. But it’s always exciting to share a feature which is yet to be released. We have created an awesome tool to help you recruit “good” people. Don’t waste your time interviewing people who can’t even clear the first level.

Shared some of the screenshots here.. This is currently used by a few startups to make their hiring process efficient. Again, if you want to check it out, drop me a mail.

Interviewstreet Recruitment Software

Interviewstreet Recruitment Software

4. Topcoder

Finally managed to reach Div 1 in TC. It shouldn’t have taken this long. But better late than never. πŸ™‚

5. Trips

Going to KVC college this wednesday for a one day session on how to crack interviews, algorithm puzzles. It’s going to be fun and it’s always exciting to meet new people. Going to bangalore to meet my friends this weekend. Kind of excited to meet everyone there. πŸ™‚

6. Knowledge

In the last few months, I’ve worked on SEO, Smarty, Jetty, Solr, Site Speed Optimizations, JQuery, Selenium, Django and more stuff I can’t even remember now. As always, it feels awesome to learn something new. πŸ™‚