Archive for the ‘Geek stuff’ Category

Setting your hostname, IP address, netmask, gateway, DNS server via files

It is sometimes helpful to know what is going on behind the scenes or if you want to modify the network configuration via changing files.

For example, assume you want to modify the network configuration by modifying files with the following:

hostname: server
domainname: demo.eu
Static IP address: 10.0.1.23
Netmask: 255.255.255.0
Gateway: 10.0.1.254
Primary DNS server: 10.0.1.1
Secondary DNS server: 10.0.1.253

    Networking is set up in these files:

    /etc/sysconfig/network
    /etc/sysconfig/network-scripts/ifcfg-eth0
    /etc/resolv.conf

    First, add your host to the /etc/hosts file:

    # The next line "127.0.0.1" is needed. Do not remove it.
    127.0.0.1       localhost.localdomain localhost
    10.0.1.23       server
    

    Your /etc/sysconfig/network file would be:

    NETWORKING=yes
    HOSTNAME=server
    GATEWAY=10.0.1.23

    Your /etc/sysconfig/network-scripts/ifcfg-eth0:

    DEVICE=eth0
    BOOTPROTO=static
    BROADCAST=10.0.1.255
    IPADDR=10.0.1.23
    NETMASK=255.255.255.0
    NETWORK=10.0.1.0
    ONBOOT=yes

    DNS servers are set in: /etc/resolv.conf. An example:

    domain demo.eu
    search demo.eu
    nameserver 10.0.1.1
    nameserver 10.0.1.253

    Using ifconfig and route

    You normally would not need to use ifconfig or route unless you want to change your IP address, disable the Ethernet interface, etc. change your gateway, etc. This is sometimes helpful, so the information is here. To set an ip address:

    ifconfig eth0 10.0.1.23 netmask 255.255.255.0 up
    

    To set a default route or gateway (“gw” = “gateway”):

    route add default gw 10.0.1.254 eth0
    

    Troubleshooting

    If your system is saying there is no Ethernet card found, make sure the card is in the kernel.

    Type:

    modprobe eth0
    dmesg | less
        Look for any info about eth0 to help track down the problem.
        
    cat /etc/modules.conf
        Look for a line line this:
        alias eth0 driver-name-like-wdi or 3c503
    

    Source: http://www.linuxmigration.com/quickref/install/network.html

    The dd utility can be successfully used to create a backup of a filesystem (in lack of more specialised backup utilites).

    dd if=/dev/sdaX | gzip > /backup/sdaX.gz

    where sdaX is the partition you want to backup, and the /backup folder is located on a different disk/partition than the one you’re backing up..

    Only note that dd does not care whether a sector is used or not, it will copy it to the image file nonetheless. Zeroing out all free space before backup up is a good way to keep wasted backup space to a minimum (since the backup will be compressed)

    Zero out free disk space

    Author: lucian

    This function comes in handy when you want to make a compressed sector-by-sector backup of the filesystem and you don’t want to include/waste space with the unused sector (which still have information on them)

    Running

    nice cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill

    before the actual backup will make sure all unused sectors contain zero (so they will not waste any space in the archives).

    If you ever need to count the occurences of a character in all (or some) files, this next series of commands would come in handy:

    for f in `ls`; do cat $f; done | awk ‘{ for ( i=1; i<=length; i++ ) arr[substr($0, i, 1)]++ }END{ for ( i in arr ) { print i, arr[i] } }’ | grep X

    Replace X with the character in question. The command is all in one line. “ls” can be replaced with a more specific list (eg: “ls *.c“)

    Two days ago I’ve just bought myself a new UPS, which comes with a nice little handy app that displays useful technical data. The UPS is an Alberex Vesta Pro 1500, and the monitoring software is named Emily2 (alternative download v2.01, v2.031).

     

    The good thing about it is that it stores all data in its log, a MS Access database file named Data.mdb.  So I thought it’s a nice ideea to include all this data as graphs in my already-running System Network Monitor page.

    So I write this nice little module that reads data from the log and includes it in SNM.

    The only pre-requisite is that you’ll have to install mdbtools on your Linux (for the module to be able to export the necessary table out of the database to a text file)

    To use, include it in your graphs.xml as a

    cntUps::sensor( 'sensor_id', 'mdb log file' [,'table name'] );

    where sensor_id can be one of

    involt, outvolt, load, freq, bat, temp

    and “mdb log file” is the full path of the Data.mdb file (this file can also be accessed through network shares)

    ‘table name’ is optional, and is needed only if you renamed the default Machine0 field in Emily2′s configuration to something else.

    The perl file can be viewed/downloaded here.

    Now my SNM displays two more nice graphs :)

    You know how when you select an item in explorer, the color of the text for the highlighted item is white on dark-blue.

    When you have an item selected in explorer and you switch to another program (but can see the explorer selected text still due to window overlap arrangement), you see that the selected item color changes to black on very-light-grey. This is very close to black on white (like all of the unselected items).

    Any bad light conditions at all make this selection really difficult to see but I can’t find a Display properties color change selection for this.

    This color is read from the HKEY_CURRENT_USER\Control Panel\Colors\ButtonFace registry key (as a Red Green Blue set), and changing it requires a restart for the setting to take effect.

    If you’ve ever needed to expand and restore multiple files from the Windows Xp CD (and don’t want to run expand for each file by hand), the following batch file might come in handy:

    @echo off
    setlocal
    set List=X:\path\*.ex_
    for /f “delims=” %%a in (‘dir /b “%List%”‘) do expand %%a %%~na.exe

    You’ll need to change “X:\path\” into the right path (where the source files are located. You should copy the files in question from the Xp CD to a folder on the hard disk).

    Then replace *.ex_ (in that same line) with the right file type (for example *.dl_ – you can only expand one filetype at a time, since “expand” expects you to manually specify the output filename).

    Finally, replace the %%~na.exe with the right output extension, for example %%~na.dll.

    Enjoy.

    Issue: The Grub boot loader is not working and now you try to run grub-install command to restore Grub in master boot record. But you are etting an error that read as follows:
    /dev/sda does not have any corresponding BIOS drive

    How do you fix this problem?

    Solution. grub-install is used to install GRUB on your drive. If you are getting error try to recheck device map.

    Type the command as follows:

    # grub-install –recheck /dev/sda

    Where,

    • –recheck: Probe a device map even if it already exists
    • /dev/sda : Replace /dev/sda with your actual device name.

    Above command should fix the problem.

    (Source: http://www.cyberciti.biz/faq/error-devhdx-does-not-have-any-corresponding-bios-drive-and-solution/)

    There are times when you inadvertently overwrite your Master Boot Record. The end result being that you are unable to boot into Linux. This is especially true when you are dual booting between windows and Linux OSes. Once when I was working in Windows XP, I accidentally clicked the hibernate button instead of shutdown. And windows somehow overwrote my MBR which housed the GRUB boot loader. At such times, it pays to have this cool tip at hand.
    This is what you do to restore the GRUB boot loader when faced with the above problem. First you need a Linux distribution CD. If you are using Fedora (RedHat) then the first CD is sufficient. But you may also use any of the live CDs like Knoppix, Ubuntu Live CD and so on.

    With Fedora CD

    Boot your computer with the first CD of Fedora in your CD drive (You have to enable your PC to boot from the cdrom, which you can set in the BIOS settings). At the installation boot prompt that you get, enter the following command:

    boot: linux rescue

    … and press Enter. The installer will ask you a few questions like the language you would like to use, the type of keyboard etc. Then, if you have linux previously installed on your machine, the Fedora installer will automatically detect it and mount it in the /mnt/sysimage directory. Once the linux partition is mounted, you are dropped into the command shell prompt. The next step is to make your newly mounted directory the root (or parent) directory. This you do by running the chroot command as follows:

    # chroot /mnt/sysimage
    # _

    Now you are in the shell with respect to the parent directory which is the linux partition on your harddisk.
    From here, the steps needed depends on which bootloader you are using. You have to have a fair idea what is the device node of your harddisk partition housing your MBR. In most cases, it is /dev/hda if you have an IDE harddisk. But if you have a SCSI harddisk, it will be /dev/sda.

    Restoring GRUB
    Execute the following command :

    # grub-install /dev/hda

    … to install GRUB boot loader on to your MBR. And then type exit to reboot the machine. Now your GRUB boot loader is fixed.

    Restoring LILO

    LILO stands for LInux LOader which was the boot loader used before GRUB was developed. It is fairly cryptic and is the default bootloader prior to and in RedHat 7.0 .

    Here you just type the command :

    # /sbin/lilo

    … to install the bootloader on to the MBR.

    If you don’t have a Fedora CD, then you need not despair. You can also repair the boot loader using one of the numerous live CDs available.

    Using Knoppix CD to repair the boot loader

    Here you have to boot into knoppix (either GUI mode or text mode). Once you are logged in, fire up a terminal (in GUI mode) and type the following commands:

    $ su -
    # fdisk -l

    This will list your hard disk partition information. From the listing, you can know in which partition you have linux installed. Now you have to mount the partition which contains the linux filesystem. For the sake of this discussion, let us assume it is /dev/hda3 .

    # mount -t ext3 -o rw /dev/hda3 /mnt
    #_

    Now your linux partition is mounted at /mnt . Next you have to use the chroot command as follows:

    # chroot /mnt
    #_

    The rest of the steps are the same as listed above for Restoring GRUB and LILO boot loaders.

    Update (August 01 2007) : Many have said when they run the grub-install command after following the above steps, they get an error saying that /dev/hda is missing. The most probable reason is that when you chroot to the mount location, it does not have a copy of the device nodes on your machine. Here is a solution for that. If you have installed Linux with /boot, /usr and / in different partitions then the above method may not get the desired results and running the grub-install /dev/hda command after running chroot might give the error that there is no /dev/hda. This is because you have mounted only one of the partitions which houses ‘/’ . And the error tells you that it cannot find the device nodes. In this scenario you can do the following :

    Lets say I have Linux installed with / in /dev/hda2, /boot in /dev/hda1 with an ext3 filesystem. I boot using a Live CD as described above and then mount the partitions as follows :

    # mount -t ext3 /dev/hda2 /mnt
    # mount -t ext3 /dev/hda1 /mnt/boot

    Remember that you are mounting the boot partition into the boot directory inside /mnt. Now mount the proc filesystem of your liveCD as follows (This is really an optional step):

    # mount <span style=”font-weight: bold”>-t proc</span> none /mnt/proc

    Finally bind the device nodes build by your liveCD to the /mnt/dev location as follows :

    # mount <span style=”font-weight: bold”>-o bind</span> /dev /mnt/dev

    Now you can chroot to the /mnt location and run the grub-install command as described above.

    # chroot /mnt
    # grub-install /dev/hda

    Please note: This updated method is applicable only if you have a Linux installation spread across multiple partitions. If you have installed Linux in a single partition, the first and second step works flawlessly.

    (Source: http://linuxhelp.blogspot.com/2005/11/how-to-repair-corrupt-mbr-and-boot.html)

    This error might occur if Windows Management Instrumentation (WMI) components are missing or not registered correctly.

    This error manifest itself, among others, by not displaying any more processor information in System Properties, and by returning a “Class no registered” error message after running the “systeminfo” command.

    Registering the WMI components ought to resolve the problem:

    The .dll and .exe files used by WMI are located in %windir%\system32\wbem. You might need to re-register all the .dll and .exe files in this directory. If you are running a 64-bit system you might also need to check for .dll and .exe files in %windir%\sysWOW64\wbem.

    To re-register the WMI components, run the following commands at the command prompt:

    cd /d %windir%\system32\wbem
    for %i in (*.dll) do RegSvr32 -s %i
    for %i in (*.exe) do %i /RegServer

    Restart Windows. If that does not help, you may try repairing the WMI using the comprehensive rebuild method provided in article Repairing and re-registering the WMI. (http://windowsxp.mvps.org/repairwmi.htm)

    Stop ACTA
    own-nightwish