Setting static IP address and DNS nameserver to network interfaces

If you’re installing an Ubuntu server, and you need set to it a static IP address and some nameservers, you can use the power of bash for it :). To set a static address for an interface, eth0 for instance, you can do this:

And put in this file the lines as below:

Pay attention for two last lines, those lines will be up your interface using those DNS nameservers. With it you don’t need to set a nameservers on /etc/resolv.conf, once on Ubuntu’s boot you erase all your modifications on it.

Comparing to CentOS, the boot process doesn’t replace dns-nameservers of /etc/resolv.conf, particularly I like it, I don’t see no reasons to Ubuntu clean this file.