Category: Ubuntu

  • How to restart NFS server on Ubuntu

     

    Once you set up your NFS exports by adding lines to /etc/exports you need to restart your NFS server; do this with the following:

     

    sudo /etc/init.d/nfs-kernel-server restart

     

    You should see output along the lines of:

     * Stopping NFS kernel daemon                 [ OK ]
    * Unexporting directories for NFS kernel daemon…           [ OK ]
    * Exporting directories for NFS kernel daemon…
    exportfs: /etc/exports [1]: Neither ‘subtree_check’ or ‘no_subtree_check’ specified for export “10.1.1.87/24:/nfs/sharedDir”.
    Assuming default behaviour (‘no_subtree_check’).
    NOTE: this default has changed since nfs-utils version 1.0.x

     

    Assuming no error messages pop up here you should now try to connect to your NFS share.

  • ZFS on Ubuntu error: Failed to load ZFS module stack

     

    If you see the above error in a fresh installation of ZFS on Ubuntu one cause may be that the package build-essentials wasn’t installed prior to installing the ubuntu-zfs package; run:

     

    sudo apt-get purge ubuntu-zfs

     

    then check for the remaining packages with the following:

     

    dpkg –list | grep zfs

     

    …and apt-get purge any remaining relevant ZFS packages.

     

    Then:

     

    sudo apt-get install build-essential

     

    …then install ubuntu-zfs as you did originally:

     

    sudo apt-get install ubuntu-zfs

     

    This time it should take properly. This isn’t the only cause of that error but on a fresh install with a new OS it’s one possibility.

  • Ubuntu: Clear terminal screen

     

    Sometimes you may wish to clear the terminal window, whether it be to hide what you’ve just done, clear some irrelevant/distracting output or any other reason. The best command to do this is simple:

     

    reset

     

    This completely clears the output shown in your terminal window but doesn’t log you out. If you want to keep your output in the buffer (i.e. so you can scroll back up to it) but still clear the terminal you can see you can use the following key combination:

     

    ctrl+L

     

    This pushes the output up above your prompt and puts the prompt at the top of your window.

     

     

  • Ubuntu: How to create a file or folder using today’s date

    This is a useful little trick to use in your scripts – particularly for things like periodic backups.

     

    For a file:

     

    touch $(date +%F)

     

    creates the file 2012-11-18

     

    For a folder, let’s add the time after the date:

     

    mkdir $(date +%F-%H:%M)

     

    creates the folder 2012-11-18-09:00

     

    We can use this in a command, like so:

     

    tar -cf $(date +%F).tar /path/to/files/

     

    This creates the tarball (archive) file 2012-11-18.tar from the files in the /path/to/files/.

     

    To see the other options, type man date or visit the Ubuntu webpage on date here.

  • Ubuntu: Securing your remote SSH logins with Denyhosts

    Being able to log in to your server remotely via SSH is an incredibly powerful way of remotely managing your system. With so many devices now able to support consoles (just about any current smartphone or current OS, really) you can check on things, update or make changes from just about anywhere.

     

    One of the less positive consequences of opening up your SSH port to the wider world is that you’re also exposing your server to everyone else in the world, not just yourself. There are many computers and virus-born botnets out there who scan IP addresses for open ports and try to brute-force their way in to steal data, generally cause destruction or create another bot. One good way of protecting yourself is installing a program which monitors the attempted logins via SSH and blocks any IP addresses which match an undesired pattern: Denyhosts.

     

    You can install denyhosts by entering the following:

     

    sudo apt-get install denyhosts

     

    This installs denyhosts on your system, which starts automatically once installed and also on boot. You can edit the settings with the following file:

     

    /etc/denyhosts.conf

     

    Blocked IPs are listed in:

     

    /etc/hosts.deny

     

    It’s not unusual to have hundreds of entries after a couple of months. The default settings are reasonably good; you do have the freedom to make them as lenient or paranoid as you care to which is handy for tailoring it to your specific needs (e.g. strict rules re: logging in as accounts that don’t exist or the root account). Be aware that if you mistype your own password enough times you may ban your ou cown IP address, which might be inconvenient if you don’t have physical access to the server or another IP to fix!

     

    Denyhosts is a quick, easy and powerful way to begin securing your SSH-accessible servers – as far as we’re concerned it or an equivalent program are a must if you’re opening up a SSH port to the outside world.

  • How to exclude results from grep

     

    Sometimes you may wish to further filter grep output, such as in the following situation:

     

    # zfs get all | grep compressratio

    backup01         compressratio         1.23x                  –
    backup01         refcompressratio      1.00x                  –
    backup01/data    compressratio         1.50x                  –
    backup01/data    refcompressratio      1.50x                  –
    backup01/photos  compressratio         1.05x                  –
    backup01/photos  refcompressratio      1.05x                  –

    Here we only really want to see the compressratio results, not the refcompressratio. We can pipe the grep output to another grep command, this time inverting the results with the -v switch.

     

    # zfs get all | grep compressratio | grep -v refcompressratio

    backup01         compressratio         1.21x                  –
    backup01/data    compressratio         1.50x                  –
    backup01/photos  compressratio         1.05x                  –

    This excludes any line containing refcompressratio, making the results easier to read. This is particularly helpful when you have a large number of results from grep.

  • DNS troubles with Ubuntu Server 12.04

    Some customers have been having DNS issues after setting a static IP on Ubuntu 12.04.1 where the server is no longer picking up the DNS settings as it was before; this can be easily fixed by adding the following to /etc/network/interfaces after the eth0 entry:

     

    dns-nameservers [ip.of.your.router]

     

    e.g., for a modem/router that’s 10.1.1.1 on your local network, your /etc/network/interfaces file might look like:

     

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    auto eth0
    iface eth0 inet static
    address 10.1.1.50
    netmask 255.255.255.0
    gateway 10.1.1.1
    broadcast 10.1.1.255

    dns-nameservers 10.1.1.1

    Restart your network with:

     

    sudo /etc/init.d/networking restart

     

    …then try pinging Google or something similar and you should have success 🙂

     

    It’s generally not advisable for Australians to use nameservers located elsewhere, e.g. Google’s public DNS’ 8.8.8.8 or 8.8.4.4 – some things which are unmetered by your ISP may be metered if you do so.

     

     

  • Ubuntu: How to view results of “ls” one page at a time

    If you’re listing the contents of a directory using the “ls -l” command in a terminal window you may find that the number of results cause pages of text to fly past your screen, leaving you with only the last page to look at. If you aren’t using a terminal which you can scroll back through this can be rather annoying; fortunately, there’s an easy fix.

     

    In a nutshell you can direct the output of the ls command to another command – less – which allows you to view the results one page at a time. We do this using a pipe: the | symbol.

     

    ls -l | less

     

    The less command shows you one screen at a time; to see the next screen, press the spacebar. If you would like less at once, you can see the next single line using the return key. You can go back a screen by pressing the “b” key or half a screen with the “u” key. There are plenty of other useful commands within less – you can see the manual for it by typing:

     

    man less

     

    You can navigate the manual in the same way – spacebar for another screen, u and b to move back up!

     

     

  • ZFS folders on Ubuntu not mounting after reboot

    After upgrading to 12.04 people seem to be finding that their ZFS shares aren’t mounting on boot; this has an easy fix, fortunately – edit your /etc/rc.local file and add:

     

    stop smbd

    stop nmbd

    zfs mount -a

    start smbd

    start nmbd

     

    Save and reboot and your shares should be intact. This has worked on all of the systems we’ve tested it on so far.

  • How to find kernel version in Ubuntu 12.04 Precise Pangolin

    Note: This also works in other versions of Ubuntu, such as 11.10, 11.04, 10.10, 10.04 and earlier.

     

    Sometimes you may wish to find out which kernel you’re  currently running; fortunately, this is quite easy to do with the uname command. If you’re running Ubuntu Desktop, open up a Terminal; if you’re using Ubuntu Server log in as per usual and then run:

     

    uname -v

    …for the kernel version, or:

     

    uname -r

    for the kernel release. You can combine the two and use:

     

    uname -rv

    to see both of those with the one command.