19 April 2014

Change The RHEL/CentOS Linux Time Zone

After Linux server has been installed and you noticed that time zone has not been set correctly, here is how to do it:

1. Check the current time zone:

# cat /etc/sysconfig/clock
ZONE="America/New_York"

# date
Thu Jul  9 06:46:14 EDT 2013


2. You can find the list of available time zones under /usr/share/zoneinfo:

# ls /usr/share/zoneinfo
Africa      Atlantic   Chile    Eire     Factory  GMT-0      Iceland      Jamaica    Mexico   NZ        posix       ROC        Universal  zone.tab
America     Australia  CST6CDT  EST      GB       GMT+0      Indian       Japan      Mideast  NZ-CHAT   posixrules  ROK        US         Zulu
Antarctica  Brazil     Cuba     EST5EDT  GB-Eire  Greenwich  Iran         Kwajalein  MST      Pacific   PRC         Singapore  UTC
Arctic      Canada     EET      Etc      GMT      Hongkong   iso3166.tab  Libya      MST7MDT  Poland    PST8PDT     Turkey     WET
Asia        CET        Egypt    Europe   GMT0     HST        Israel       MET        Navajo   Portugal  right       UCT        W-SU


# ls /usr/share/zoneinfo/Europe/
Amsterdam  Berlin      Chisinau    Helsinki     Kiev        Madrid     Moscow     Prague      Sarajevo    Tallinn   Vatican    Zagreb
Andorra    Bratislava  Copenhagen  Isle_of_Man  Lisbon      Malta      Nicosia    Riga        Simferopol  Tirane    Vienna     Zaporozhye
Athens     Brussels    Dublin      Istanbul     Ljubljana   Mariehamn  Oslo       Rome        Skopje      Tiraspol  Vilnius    Zurich
Belfast    Bucharest   Gibraltar   Jersey       London      Minsk      Paris      Samara      Sofia       Uzhgorod  Volgograd
Belgrade   Budapest    Guernsey    Kaliningrad  Luxembourg  Monaco     Podgorica  San_Marino  Stockholm   Vaduz     Warsaw


3. Change it to your desired time zone:

# vi /etc/sysconfig/clock

ZONE="Europe/Berlin"


4. Create a backup of current localtime file and create a new one as a symbolic link to the zone file:

# mv /etc/localtime /etc/localtime.old

# ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime

# ls -l /etc/localtime*


5. Time zone has been changed now:

# cat /etc/sysconfig/clock
ZONE="Europe/Berlin"

# date
Thu Jul  9 12:59:39 CEST 2013

But you can reboot the server in order for other applications running on the server use the new time zone. 





5 April 2014

Linux Routing table

We can check current Linux route table with netstat command

# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         12.96.176.1     0.0.0.0         UG        0 0          0 eth2
5.72.185.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0
12.96.154.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1
12.96.176.0     0.0.0.0         255.255.255.0   U         0 0          0 eth2
13.122.288.72   5.72.185.1      255.255.255.240 UG        0 0          0 eth0
127.0.0.0       0.0.0.0         255.0.0.0       U         0 0          0 lo
135.188.0.0     5.72.185.1      255.255.0.0     UG        0 0          0 eth0
135.188.45.153  5.72.185.1      255.255.255.255 UGH       0 0          0 eth0
174.65.146.0    5.72.185.1      255.255.255.0   UG        0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0


Q: How to add a new route?

To add a single host destination:
# route add $Host_IP gw $Gateway

e.g:
# route add 12.153.4.22 gw 6.64.215.1

To add a network destination:
# route add –net $Network_IP netmask $MASK gw $Gateway

e.g:
# route add -net 12.153.4.0 netmask 255.255.255.248 gw 6.64.215.1


Q: How to delete route?

# route del –net $Network_IP netmask $MASK gw $Gateway



Q: How to check the default gateway?

In routing table, the row start with 0.0.0.0 has gateway IP which in this example is 12.96.176.1

# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         12.96.176.1     0.0.0.0         UG        0 0          0 eth2
5.72.185.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0
12.96.154.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1
12.96.176.0     0.0.0.0         255.255.255.0   U         0 0          0 eth2
13.122.288.72   5.72.185.1      255.255.255.240 UG        0 0          0 eth0
127.0.0.0       0.0.0.0         255.0.0.0       U         0 0          0 lo
135.188.0.0     5.72.185.1      255.255.0.0     UG        0 0          0 eth0
135.188.45.153  5.72.185.1      255.255.255.255 UGH       0 0    
      0 eth0
174.65.146.0    5.72.185.1      255.255.255.0   UG        0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0

and finally to set default gateway we can use following command:

# route add default gw 192.168.1.254 eth0