Custom Search

How to change hostname in Ubuntu server

Change a hostname in Ubuntu server is very easy. From the command line terminal, type hostname newname. View the new hostname with hostname command. See the step by step example on how to change Ubuntu server hostname below:


1) View current hostname:

luzar@hitam:~$ hostname
hitam
luzar@hitam:~$


2) Change hostname and view latest hostname:

luzar@hitam:~$ sudo hostname ubuntu
luzar@hitam:~$ hostname
ubuntu
luzar@hitam:~$


See, that's how easy it is. Heh, don't fall for it. That doesn't change anything. The hostname is still the same as you can see at the prompt. Even reboot won't change anything. The exact method to change the hostname permanently is by editing /etc/hostname file. Here is the step:


1) Open /etc/hostname with your favorite text editor:

luzar@hitam:~$ sudo vim /etc/hostname
[sudo] password for luzar:


Here the vim /etc/hostname screenshot:




Now you can change hostname and save. The changed is permanent even after you reboot your system.

Important: You also need to edit the /etc/hosts file and apply the changes. Otherwise, you won't be able to use sudo after the reboot.

That's it.

Ubuntu tail log tutorial

Sometimes we need to view just a part of a big Ubuntu file. For example. when we are going to locate error or check system activity in Ubuntu system log. Ubuntu command that can be used to check for latest log generated by the system is tail command. The tail command by default displays last 10 lines in the file.

Here is part of tail manual page that describes the usage:

NAME
       tail - output the last part of files

SYNOPSIS
       tail [OPTION]... [FILE]...

DESCRIPTION
       Print  the  last 10 lines of each FILE to standard output.
       With more than one FILE, precede each with a header giving
       the file name.  With no FILE, or when FILE is -,
       read standard input.

If we are going to check latest system log, we can issue tail /var/log/messages command. See an example below:

luzar@ubuntu:/var/log$ tail /var/log/syslog
Feb 11 09:30:01 ubuntu console-kit-daemon[5150]: CRITICAL: 
cannot initialize libpolkit
Feb 11 09:30:01 ubuntu /USR/SBIN/CRON[5213]: (root) CMD ([ -x 
/usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Feb 11 09:32:12 ubuntu dhclient: DHCPREQUEST of 172.16.153.129 on eth0 
to 172.16.153.254 port 67
Feb 11 09:32:12 ubuntu dhclient: DHCPACK of 172.16.153.129 from 172.16.153.254
Feb 11 09:32:12 ubuntu dhclient: bound to 172.16.153.129 -- renewal in 899 seconds.
Feb 11 09:40:01 ubuntu console-kit-daemon[5260]: CRITICAL: 
cannot initialize libpolkit
Feb 11 09:40:01 ubuntu /USR/SBIN/CRON[5323]: (root) CMD ([ -x 
/usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Feb 11 09:47:11 ubuntu dhclient: DHCPREQUEST of 172.16.153.129 on eth0 
to 172.16.153.254 port 67
Feb 11 09:47:11 ubuntu dhclient: DHCPACK of 172.16.153.129 from 172.16.153.254
Feb 11 09:47:11 ubuntu dhclient: bound to 172.16.153.129 -- renewal in 883 seconds.
luzar@ubuntu:/var/log$

We can use tail to check latest messages generated by system log, we can issue tail /var/log/messages command. See an example below:

luzar@ubuntu:~$ tail /var/log/messages
Feb 11 09:06:04 ubuntu kernel: [    8.354312] lp0: using parport0 
(interrupt-driven).
Feb 11 09:06:04 ubuntu kernel: [    8.427308] Adding 489940k swap on /dev/sda5.
Priority:-1 extents:1 across:489940k
Feb 11 09:06:04 ubuntu kernel: [    8.462337] EXT3 FS on sda1, internal journal
Feb 11 09:06:04 ubuntu kernel: [    8.707586] ip_tables: (C) 2000-2006 
Netfilter Core Team
Feb 11 09:06:04 ubuntu kernel: [    8.746051] eth0: link up
Feb 11 09:06:04 ubuntu kernel: [   13.362431] NET: Registered protocol family 17
Feb 11 09:06:04 ubuntu kernel: [   20.601093] NET: Registered protocol family 10
Feb 11 09:06:04 ubuntu kernel: [   20.611324] lo: Disabled Privacy Extensions
Feb 11 09:26:09 ubuntu -- MARK --
Feb 11 09:46:09 ubuntu -- MARK --
luzar@ubuntu:~$

Remember that tail command is very useful command when troubleshooting error during Ubuntu server configuration.

Ubuntu w3m web browser tutorial

Ubuntu server default web browser is w3m. You may already know that Ubuntu server didn't come with x-window, that means no gnome or kde. So as you have guess, w3m is a text-based web browser. And when I said w3m is a default Ubuntu web browser, that means it's already in the system when you finished installed Ubuntu server.
Other than being a web browser, w3m also capable of viewing a text file or a local html file. That means w3m can be a pager too such as less or more command. Let's look at w3m syntax.

Syntax:
usage: w3m [options] [URL or filename]

The options is optional. To view a webpage, you just type w3m www.website.com. Here is a screenshot example of a google search engine opened using w3m:


To quit w3m, press q:

Do you want to exit w3m? (y/n)

Answer n to quit w3m.
Below are options available to use with w3m. You can view w3m options with w3m -help command.

luzar@ubuntu:~$ w3m -help
w3m version w3m/0.5.2, options lang=en,m17n,image,color,ansi-color,mouse,gpm,menu,cookie,ssl,ssl-verify,
external-uri-loader,w3mmailer,nntp,gopher,ipv6,alarm,mark,migemo
usage: w3m [options] [URL or filename]
options:
    -t tab           set tab width
    -r               ignore backspace effect
    -l line          # of preserved line (default 10000)
    -I charset       document charset
    -O charset       display/output charset
    -B               load bookmark
    -bookmark file   specify bookmark file
    -T type          specify content-type
    -m               internet message mode
    -v               visual startup mode
    -M               monochrome display
    -N               open URL of command line on each new tab
    -F               automatically render frame
    -cols width      specify column width (used with -dump)
    -ppc count       specify the number of pixels per character (4.0...32.0)
    -ppl count       specify the number of pixels per line (4.0...64.0)
    -dump            dump formatted page into stdout
    -dump_head       dump response of HEAD request into stdout
    -dump_source     dump page source into stdout
    -dump_both       dump HEAD and source into stdout
    -dump_extra      dump HEAD, source, and extra information into stdout
    -post file       use POST method with file content
    -header string   insert string as a header
    +           goto  line
    -num             show line number
    -no-proxy        don't use proxy
    -4               IPv4 only (-o dns_order=4)
    -6               IPv6 only (-o dns_order=6)
    -no-mouse        don't use mouse
    -cookie          use cookie (-no-cookie: don't use cookie)
    -pauth user:pass proxy authentication
    -graph           use graphic character
    -no-graph        don't use graphic character
    -s               squeeze multiple blank lines
    -W               toggle wrap search mode
    -X               don't use termcap init/deinit
    -title[=TERM]    set buffer name to terminal title string
    -o opt=value     assign value to config option
    -show-option     print all config options
    -config file     specify config file
    -help            print this usage message
    -version         print w3m version
    -reqlog          write request logfile
    -debug           DO NOT USE
luzar@ubuntu:~$