SIOCSIFADDR: No such device eth0 in Ubuntu

$ ping www.google.com
connect: Network is unreachable

This is how my week #43 started.

Imagine you are suppose to reply a very important mail(s) and you are not able to connect to network… grrrrr…

Well if  you are in a same situation you may choose to continue reading. Have tried lots of thing to solve the issue. I am sure you will get the solution for the same.

Ok.. So the following are the things which I started with.

First, I thought it was an issue with the LAN cable. So tried connecting it another cable. But no use. That was not an issue. The LAN cable was just working fine.

Second possible issue, Network Interface Card. That could be a problem as I have ran into similar issue previously and changing the Motherboard have worked. But unfortunately this time NIC was not the issue.

Changed the networking configurations…Restarted the system….phewwww

Tried connecting to other LAN ports. No use. Change the hard-drive and connected to the one which has dual boot available. Then thought of booting it from another operating System. In this case it was WinXP. Booted through it and then tried connecting it to internet. But efforts were in vain until a pop-up showed up on the right bottom of the screen which read “Unable to find drivers”. After reading this I installed the LAN drivers from the intel CD-ROM and everything worked fine. For the first time I was thankful to windows (XP). Restarted the system to boot it from ubuntu. Bingo!!! everything worked fine.

Hmmm, so now the problem was identified. The issue was with the drivers. Connected my hard-drive which has only linux.  As it is said everything is a file in linux, one of the file used for networking could be corrupted.

Ok, but which file? How do I know that? So what I did was fired an “ifconfig” command and found that there was only loopback configuration. I restarted the networking for eth0 something like this:

error image

Bingo… got the filename: SIOCSIFADDR: No such device

Tried the following:

Trial #1

echo "" > /etc/udev/rules.d/z*_persistent-net.rules.
After doing this restart networking

This didn’t worked for me. 

Trial #2

root@ubuntu64:# sudo vi /etc/network/interfaces
Changed all the eth0 to eth1
Save the file. Now run the dhclient as follows:
root@ubuntu64:# dhclient
Restart networking.

This worked for me.

Hope this helps!

How does google animates doodle

Thinking about animation, the first thing which comes to mind is Flash.

Well, this is not the case with most of the google doodle. Google has an interesting way of animating the doodles. It uses CSS sprites along with javascript for animation.

As this being the first post, will explain how did google animated this.
Will be explaining this only using jquery and CSS. Lets keep it simple.
Later in this post will be sharing some of the tools that can be used for animation.

As it is rightly said you should ask the right questions, lets begin with finding answers for the following questions:

  • What is CSS Sprite?
  • How to generate it?
  • How to change a CSS property using javascript?
  • Complete HTML, CSS and JS code.
  • Demo
  • Understanding the Javascript.
  • Why use CSS sprite and not use flash?
  • Any Tools to create CSS Sprite?

What is CSS Sprite?

- It’s just combining 2 or more images into a single image and transferring the one big image to the client’s browser. By doing this we save bandwidth and the number of http requests. This also helps in reducing page loading time. For more detailed information and stats read here.
- CSS Sprite is mostly used for changing the background of a button when the mouse is hovered over the button or when the button is clicked.
- One of the image which google uses is

- As can be seen, every image which is combined is a state or a frame in the animated doodle.

How to generate CSS Sprite?

- Any tools which is capable of combining images can be used to generate it. If you know photoshop, then it can be created in a matter of seconds.
- Well for those who prefer online tools, can refer here to create their sprite. Just make your frames and upload it, the tool will create sprite for you.

How to change CSS property using javascript?

- Well this is really easy using jquery.
- Lets say you want to change the background color of a div tag with id as my-content you just need to do the following:

$("#my-content").css("background-color", "red");

- Google uses the background-position property of css to change the background of the div.

Complete HTML, CSS and JS code

<html>
<head>
<style>
#my-content{
    width:46px;
    height:144px;
    background:url('http://www.google.com/logos/2011/henson11-hp-6ea-lr.png') 0 0;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
	var scrollSpeed = 120;
	var step = 45;
	var current = 0;
	var imageWidth = 2925;
	var headerWidth = 0;		

	var restartPosition = -(imageWidth - headerWidth);

	function scrollBg(){
		current -= step;
		if (current == restartPosition){
			current = 0;
		}
		$('#my-content').css("background-position",current+"px 0");
	}
    $(document).ready(function(){
        $("#my-content").click(function(){
        	setInterval("scrollBg()", scrollSpeed);
        });
    });
</script>
</head>
<body>
    <div id="my-content">
    </div>
</body>
</html>

Demo

  • Copy the above code and paste it in a file.
  • Save it as an html file.
  • Open it in a web browser.

Understanding the Javascript

Following is the code which animates the above character.

<script type="text/javascript" charset="utf-8">
	var scrollSpeed = 120;
	var step = 45;
	var current = 0;
	var imageWidth = 2925;
	var headerWidth = 0;		

	var restartPosition = -(imageWidth - headerWidth);

	function scrollBg(){
		current -= step;
		if (current == restartPosition){
			current = 0;
		}
		$('#my-content').css("background-position",current+"px 0");
	}
    $(document).ready(function(){
        $("#my-content").click(function(){
        	setInterval("scrollBg()", scrollSpeed);
        });
    });
</script>

- The above code just changes the background every 120 ms. It basically shifts the background image by 45px to the left every 120 ms.
- Have used setInterval function of javascript to have a delay of 120ms between every image shift.

Why use CSS sprite and not use flash?

There is a lot of debate on this question.
Why not to use flash?

  • Its heavy to use flash for such small animations. The site loading time increases.
  • Its not SEO friendly.
  • Needs plugin to run it.

Whats the future?
- The answer is very straight forward. The future of internet is HTML5!

Adobe has recently created a site completely in HTML5 known as “The Expressive Web”
This site is completely a non-flash website.

Any Tools to create CSS Sprite?

Yes there are many tools to create / animate images.

  • Generate CSS Sprite images using : http://csssprites.com/
  • To animate your css image use http://spritely.net/
    • This is really good plugin used for animation.
    • Example of the same will be in the upcoming posts.
  • Photoshop is always a web developers friend.

Conclusion

The whole idea of writing this post was just to

  • Encourage developers to develop non-flash based websites.
  • Use javascript for animations.
  • Explore the power of HTML5.

Thanks for reading.