Tuesday, November 29, 2011

Static IP's in linux

If you're like me, you like centralized control of your configurations in Linux.  I'm not a big fan of letting gui tools manage things like my network settings and stuff. Especially on a server. So a friend of mine recently asked how to set a static IP for a box. So here's how I do it in the core config files for linux networking.

(Note that if you want to try static DHCP, you can do that with Netgear SOHO routers. I'm not sure about other brands (Belkin, Linksys, Dlink,etc. static DHCP is where the client still asks the DHCP server/router for an address but the DHCP server/router is configured to always give that client MAC address the same IP rather than whatever is first available out of the pool. It's a simple way to manage static IP's and lets your DHCP server/router still handle controling the other information including DNS servers. If you change DNS servers, for example, then you only need to change the info in the DHCP server/router.)

First you need to understand that if you are using DHCP to get info and change to static, you'll need more than just an IP configured. You'll also need other info that the DHCP server gives out when you lease an IP address: netmask, gateway, and DNS servers. I'm only going to discuss IP4 here since most SOHO applications will still be using that for a while. I use Ubuntu/Debian so some of the locations here may be specific to that distribution however, there are similar files in RedHat/CentOS that are configured the same.

The files I want to modify are located in /etc and all need to be modified as root. I recommend doing this from terminal since if you restart the box and it doesn't come up, you'll

First lets setup our IP address, gateway, and netmask.

Use vi, nano, emacs or whatever to edit the file /etc/networks/interfaces. You should at least have an eth0 interface. So lets set that up.

auto eth0
iface eth0 inet static
   address  10.0.0.5
   netmask  255.255.255.0
   gateway  10.0.0.1

So address will be whatever you want to give your box. IMPORTANT: Do not give it an address that is in your DCHP pool. This will cause big problems. Netmask is typically that unless you're doing something unique. Gateway is typically set to your router.

One additional thing we need to setup is the DNS info since we won't be getting it handed to us from the DHCP server. Look at your server and find out what the DNS server IPs should be. This could be a local DNS server if you have one on your network. It could be your internet provider's DNS servers. Or you can use openDNS servers. I prefer openDNS over internet providers. I actually run my own DNS caching server locally but it forwards out to openDNS servers. There are two basic IPs for openDNS server pools: 208.67.220.220 and 208.67.222.222. So I'll use those here to configure in my example.

We now want to edit /etc/resolv.conf to say the following:

nameserver 208.67.220.220
nameserver 208.67.222.222

It's important to at least list two nameservers in case one isn't reachable. You can use any number of servers and it will try them in the order listed. Therefore, you may combine your internet providers DNS servers with the open DNS servers and list them all if you like. If you run a local DNS list it first, then list an external DNS. While the local DNS should always respond and should forward out to another DNS on the internet for lookups it doesn't know, it's safe to have that backup one listed on your server too. That way if local DNS is down, your server still has a backup to ask.

With that, a restart of the network service or rebooting, and you should be back up with your static IP. I recommend rebooting the box if you can and testing. Never hurts to make sure that it'll work if it does end up rebooting. You don't want to have to troubleshoot that when you're in a crunch trying to bring a box back up after a power failure or something.

One additional note, if you have multiple nics, you may try bonding them. This works pretty easily with the current linux kernel, there are a bunch of resources on how to do this and I may right this up in the future for what I did. You can bond them in a round robbin way that will provide redundancy and some network boost. I have not been successful at bonding wireless nics. (whether bonding wireless to wired or wireless to wireless) I've read that due to the way WPA/WPA2 encryption works that it's likely impossible. If you decided to try to bond wireless, be prepared for a long path with many hours of trial and error and lots of internet research. But if you succeed, please post a tutorial somewhere for those of us who weren't successful.

Tuesday, October 4, 2011

Want to do SMART analysis on a USB hard drive?

If you've ever run into a problem with an external hard drive, you've probably tried to run a variety of checks against it and likely decided at some point that plugging it in internally would be easier to run some checks. SMART helps monitor drives and allows you to run some basic tests against them (when not mounted).  So you can run SMART commands over USB! So before you go grab that screwdriver, give this site a read and try to run some checks against the drive over USB.

SMARTmontools over USB

Monday, September 26, 2011

Saturday, September 24, 2011

Raid and LVM ... more info

Here's some links for more information on Raid and LVM. Personally, I have no problems running Raid without LVM, but I'd never run LVM without Raid. Make sure you fully understand both before you start using them. I am not using LVM on my rebuild, just the 4x40 Raid10 and 2x80 Raid1 setups.(Note: Raid0 and LVM are similar except that Raid0 has no snapshots or redundancy; I would never use Raid0 to be honest. Raid10 is basically Raid0 + Raid1; much better option because it provides the redundancy.)

Besides redundancy, Raid can possibly increase performance of read access to the disks. Just make sure your disks for your raid array are on different channels.

Raid is not a substitute for backups! It only protects against hard drive failure; not against filesystem corruption. LVM has the ability to do snapshots at filesystem level but still that's not a replacement for a good backup system. Make sure you have a good backup system in place. A good disaster recovery system includes at minimum Raid, snapshots, and offline backup strategies.

Here are some links to some more information on LVM and RAID:




Thursday, September 22, 2011

Kicking off with a server rebuild

So I thought I'd kick this off with a server rebuild I'm doing. Have and old webserver that was setup back in 2002-2003 and has been running solid for years. Ran CentOS 4 on it. Problem was, it had minimal disk space in it to begin with (was just put together out of spare parts). As time went on, hard disks got added and new mount points and move data and eventually we ended up with a lot of stuff spread out over a lot of disks in a somewhat random format because not much thought was put into it. So time to rebuild and I figured I'd move to Ubuntu server (I'm not really partial to one version of Linux or another; I move between them pretty easily so it doesn't bother me what its running).  So Ubuntu 11 server here we come.

First was to copy all of the important data off. Obviously backup /var, /etc/, and /home. dumped all of that to a hard drive internally and then pulled it. Stuck it in a USB enclosure and fired it up on a desktop to verify that everything was there. Ok so we're good to go now.

Next was to map out what I wanted as far as drives and add software raid this time around. So I grabbed my box of hard drives and set to work mapping out what it would look like and ended up with this. I have 4 IDE channels in this computer (2 onboard, 2 PCI).

  • sda
    • /boot  (yes I'm old fashioned and still give boot it's own partition tucked away on a separate drive)
    • swap
    • extra space (this can be used to make a quick partition that can be mounted to copy some stuff over to that's not part of the system)
  • md0 
    • 80GB / partition
    • raid10 array of 4x40GB disks
    • each disk is on a different IDE channel
  • md1
    • 80GB /var partition
    • raid1 array of 2 80GB disks
    • each disk is on a different IDE channel
  • sr0
    • cdrw/dvd on one of the IDE channels 
    • after install this may get swapped out for a spare 80GB that could be added to md1 as a hot spare
So after taking some time to map out what I wanted, I'm ready to go. I'd always recommend mapping out before you start. If you want to do raid 1, 5, or 10, make sure you put them on different channels/controllers if possible. It'll help prevent one channel from bogging down while writing. If you have a spare box of hard drives lying around (like I do) you can grab them all out, write their sizes down on small pieces of paper and then on a bigger sheet draw out a map of your setup. Then you can move the small pieces of paper around on your "map" until you get the setup you like. This visualization exercise can help if you have a hard time doing it in your head. Here's my "map"

                    Onboard                                                    PCI
        Primary               Secondary                    Primary            Secondary
Master    Slave         Master       Slave       Master    Slave     Master   Slave

A few questions may arise from why I did what I did with my set. Let me state a few things:
  1. This is only a production system for me personally. I'm not dealing with multiple users. 
  2. /var is more important to me than /home.  this is because no other users are using this server so nothing is really getting stored in /home other than a few tarballs of programs that I may download to install. So this is why it gets its own 80GB setup.
  3. raid10?  cause I have 4x40GB lying around and I figure that making / on that will insure that the system as a whole can come up.
  4. Why no LVM?  that's a whole additional layer of complexity to build LVM on raid. it requires detailed planning and lots of hard drives. Also, I don't for my need foresee needing to add more space  and if I do, I'll need a bigger power supply and a sata card as there are no channels left on the IDEs.
Next time, we'll look at getting her up and running.