13 Aug 2014

How to create a persistent network configuration on a Linux machine

Leave a Comment
In this article I will show you how to configure a persistent network configuration on your Linux machine. Note that you will need to edit the network adapter configuration file. If you choose to configure your server using other methods (DHCP or bash commands), the network parameters will not persist upon reboot. You can also add those commands in one of the initialization files but, I prefer editing the network adapter configuration file directly.
The location of the network configuration file may differ from one Linux distribution to another. For the following example I will be using two virtual machines running CentOS named VM2 and VM3. The network configuration file on a CentOS Server, can be found in /etc/sysconfig/network-scripts/ifcfg-eth0. If you are using a machine with multiple interfaces, there will be several confg files in the same location so make sure to edit the right file. 
If you have downloaded the OS image from http://www.centos.org/, your Server will be configured to obtain it's IP configuration from a DHCP Server this is why, the following lines would normally appear:
  • DEVICE=interface_name; - physical interface name
  • BOOTPROTO=protocol; - protocol used to obtain IP configuration

            the specified protocol can be one of the following:
                 none — no boot-time protocol will be used
                 bootp — BOOTP protocol will be used. 
                 dhcp — DHCP protocol will be used.
  • ONBOOT=yes/no - will enable the interface upon reboot.
I've opened the ifcfg-eth0 on VM2 using a text editor. You will need to add the following lines on your CentOS machine:

Note that the HWADDR,TYPE,UUID and NM_CONTROLLED parameters are configured automatically by the System so, you will not need to worry about those. I've added the IP Address, Network Mask, Gateway and Network Address parameters. 
This is how your configuration file should look like:
Linux static IP configuration

Now we will make similar configurations on the second Server:
How to create persistent network configuration

The only thing left to do is to restart the network service on both Servers. To achieve this result, you must run the following command: service network restart
Linux service command

There are several ways to test the network connectivity between these two servers but, one of the most common methods is by using the ping command:
Linux ping command

Now it's time to test our persistent configuration by rebooting both machines. Simply type reboot on each server:
Linux reboot command

For verifying your IP configuration use ifconfig or ip addr show commands. Note that you can configure a static IP address using these two commands but, these will not persist upon reboot. The ouput of these commands are as follows:
Linux Ifconfig command

                                          ip addr show
Linux IP command

As you can see these commands have similar output so choose whatever method you desire. For verifying the default gateway, use the route command:
Linux route command

That's it for this article folks, I hope you've understood how to configure a persistent IP configuration on your Linux machine. Note that I'm still in the process of learning Linux this is why there may be things that I cannot explain yet. Please feel free to post any question related on this topic and I will try to respond as soon as possible. Wish you all the best and stay tuned for the following articles from IT training day.
Read More
7 Aug 2014

Hyper-V Virtual Machine validation error

Leave a Comment
Hello folks,
Hyper-V Virtual Machine validation error
I want to show you how to fix an Hyper-V validation error that may occur when Installing this Server Role on a Virtual Machine. I've stumbled upon this error when trying to install and configure Hyper-V on a VMware Server and after searching for a while I've discovered the solution for this problem. The wizard displayed the following error "Hyper-V cannot be installed: A hypervisor is already running" when using Server Manager Console:

Virtual Machine configuration file
The first thing you must do is to shutdown the virtual machine because we need to modify its configuration file. Open Powershell and type shutdown /s /t 0 to turn off the Server immediately. Navigate to the VM's location and open the *.vmx file using your favorite text editor: 

At the end of the file we'll need to add the following lines:
hypervisor.cpuid.v0 = “FALSE” - informs the OS that is being hosted on a Virtual Machine. The Hyper-V Installation will verify if the Server runs of a Virtual Machine so this setting must be added
Hyper-V installation problem
mce.enable = “TRUE” - enables Machine Check Exception (MCE) which is used to detect CPU hardware errors. You can read more about MCE on Wikipedia.

vhu.enable = “TRUE” - enables Nested virtualization
Once the lines have been added, save and close the file

There is one more thing we need to configure. Open the VM's Settings page, navigate to the Processors section and enable the following features:

Virtualize Intel VT-x/EPT or AMD-V/RVI.
Virtualize CPU Performance counters.

Fixing Hyper-V Virtual Machine problem

Once you power on your Server, you should be able to install Hyper-V without problems. Hope this article will serve you well in fixing this Hyper-V installation eror. Wish you all the best and stay tuned for the following articles.
Read More
30 Jul 2014

Introduction to Hyper-V

Leave a Comment
Hyper-V tutorial

This article will serve as an introduction to Hyper-V and its main features. First of all what is Hyper-V and what are the elements that are part of this technology? Hyper-V is Microsoft's virtualization tool which allows you to build Virtual Machines on both X32 and X64 architectures. Unlike its predecessor (Virtual Sever 2005), Hyper-V is built directly in the OS and can be installed as any other Server Role by using the Manager Console. Several features were added into this tool to allow Sysadmins to optimize their VMs and the overall network performance: 
  • Using Virtual Machines within your network you reduce the hosting costs for your infrastructure. By creating multiple Servers for hosting VMs you consolidate the whole hardware performance and provide an efficient way to allocate resources to your machines. Imagine that when implementing DNS, IIS or DHCP Servers you would rather create individual Virtual Machines that use the same hardware resources than installing and configuring physical Servers for each Server Role. 
  • Reliability is one important component of Hyper-V because you can create Server clusters for hosting your Virtual Machines. This technology allows you to limit downtime caused by hardware failures because resources are automatically allocated to the remaining machines. Further more, you can use hot swappable components (RAM, CPU and Hard drives) to ensure that your Systems can be easily repaired.
  • By allocating resources for each machine based on their necessities, you can increase the hardware capacity of Systems that need higher performance. The process of increasing/decreasing hardware specifications of a Virtual Machines becomes really fast and easy.
  • If needed, you can easily deploy multiple Virtual Machines and the process of decommissioning them becomes much faster rather than using physical Servers.
  • Using backup technologies (like shadow copies) and snapshots you can ensure that data is saved in case of hardware or network failures. Snapshots allows you to backup a Server anytime and offers a fast way to rollback a machine when problems are encountered. Hyper-V can store multiple snapshots for each VM so you can restore multiple versions of the same Server.
  • Virtual Machines can be easily moved from one host to another if needed so, in terms of portability, this technology offers huge advantages than physical machines. 
   Of course you need to take into consideration the Virtual Machine's purpose and hardware necessities. Because Virtual Machines use shared resources, a machine which requires high CPU, memory and disk performance is not suited for virtualization. Database Servers are usually not deployed within virtualized environments and instead physical Servers are used to satisfy their requirements. A physical Server will always perform better than a Virtual Machine with the same hardware specifications this is why planning is really important when deciding to go for virtualized environments.
   There are several ways to move your physical machine after deciding to migrate your infrastructure to Hyper-V. You can either install and configure new Virtual Machines for each Server or virtualize the existing physical Servers. Microsoft provides tools to virtualize physical Servers such as System Center Virtual Machine Manager and VSMT (Virtual Server Migration Tool). The difference between these two solutions is that the first one supports the management of large numbers of Servers and it's fully integrated into Powershell while the second one is mostly used when there is a small number of Servers that need to be virtualized.
Note that all virtualized Servers need to have a valid Microsoft Server License so, you'll need to ensure you have the right number of licenses.
That's about it for this introductory article, we will continue discussing about Hyper-V in future posts and you will discover more interesting things about this awesome technology. I will show you how to install and configure Hyper-V and how to deploy Virtual Machines within your network. Please share your thoughts about this article and don't forget to share it to others. Wish you a great day!
Read More
25 Jul 2014

Links and metacharacters in Linux

Leave a Comment
Links and meta characters in Linux   We will continue our Linux journey by talking about two important components of the File System:
links (soft and hard links) 
This would be an important step to further understand how this OS works and what are the main concepts behind its functionality. I will try as best as I can to explain these two concepts so please post a comment if you think that things were not described properly.
   Besides the actual data contained in each file within the File System, the Operating System will also store specific information for each one. Files are described by multiple attributes and we've seen some of them when we've learned about the ls -la command in this article. Attributes like file type, group and user ID, file permissions, file size, last modification date, creation date, etc, must be stored somewhere in the File System. In Linux, all this information is stored within inodes (Index-nodes). An inode will keep all data regarding a particular file except its name and each one will be identified by a unique number. They also store a list with all data blocks that are part of the same file and where is each block located on the hard disk. We will later see how you can view and interact with inodes. Basically, for every file there will be an associated inode allocated.

   A Linux partition is composed of several elements. In the following section I will try to explain the role of each component:
boot block - the location of the boot loader. We've described the Linux bootloader in a previous article.
super block - contains information like number of data blocks, mount-points, File system type, Size, Status, Information about other metadata structures, etc.
inode list - the list of inodes contained by a partition. Note that this is a finite number.
data blocks - this is where file content is stored. A file can contain one ore more data blocks and inodes are the ones who store the information about where is each data block located.

   In Linux, one file can be seen in multiple locations without multiplying its content. Practically, you can view the same resource in multiple locations but, all will have the same source file. This feature is handled in Linux using links. When talking about links in the UNIX/Linux Systems, we'll need to specify the two concepts behind this technology:

soft link also known as symbolic link - it's a redirection from one file to another. They have similar functionality as Windows shortcuts. To create a new symbolic link you'll need to use the following command:
ln -s existing_file new_file
This command will create a new "shortcut" to the file that already exists in the File System.
hard link - an association between file name and inode. As we've talked previously, the name information is not stored in the inode but, instead it's located in the directory which contains the file. If you want to create a new hard link for an existing file you'll need to use the following command: 
ln existing_file new_file
The command will basically create a new association which will contain another name and the existing inode.
To view the number of hard links for a file you can use the ls -l command (we've talked about this in a previous article)

Metacharacters are mainly used for filtering the output of a command. By parsing information before manipulating a command's result, offers System Administrators a powerful way to manipulate data within the File System. You will see that there are special characters reserved in the OS which have a distinct functionality and can often be used to simplify administrative operations. Regex (regular expressions) are build using metacharacters so, this part may sound familiar. I will try to explain the role of each metacharacter within the OS, please add more if you think are relevant on this topic:

> Used to redirect the output of a command to file. If the file does not exist, it will create a new one, if the file already exists its content will be replaced
>> Redirects the output of a command but, unlike the > character, it will append the new results to an existing file.
< used to redirect input
* wildcard used to substitute 0 or more characters. Example ls -al f* will output any file which begins with f
wildcard used to substitute only one character. Example: ls -al f??e will output any file that starts with "f", contains any two characters and then ends with "e"
[ ] will substitute any character between brackets. Example: ls -al f[iad]e will output fie fae fde
^ any other character except the ones indicated when used between []. Example: ls -al f[^a-c]e will not output fae, fbe ,fce
; used to separate multiple commands that are written on the same line
Predefined metacharacter class:
[[:alnum:]] - alphanumeric characters
[[:alpha:]] - alphabetic characters
[[:blank:]] - SPACE or TAB keys
[[:digit:]] - numeric characters
[[:upper:]] - upper letters
[[:lower:]] - lower letters
|| OR conditional execution
&& AND conditional execution
# used to specify comments within files
\ if you use this character in front of any other metacharacter, the output will use that particular symbol and not its special functionality. Example: 300\$ = 300$
. filters one character. Example d.g = dog, dag, deg
"$    preceeds the name of a variable to be expanded.
The variables are either assigned using  "="  or are one of the pre-defined variables (which cannot be assigned to):
$0  name of the shell or the shell script being executed.
$# number of the positional parameters to the command
$1  the value of the first positional parameter passed to the command. $2 is the second positional parameter passed to the command. etc. up to $9.
$*    expands to all positional parameters passed to the command
$@   expands to all positional parameters passed to the command, but individually quoted when "$@" is used. " from About.com
I've found this interesting article which describes regular expressions and metacharacters you can read it to discover more information on this topic. You can also use man bash command to discover more things about metacharacters.
That's about it for this article folks, please share your thoughts about it and don't forget to share it to others. Enjoy this wonderful day and stay tuned for the following articles from IT training day.
Read More
24 Jul 2014

Linux user administration

Leave a Comment

Linux user administration tutorialIn today's article we will talk about user administration in UNIX/Linux distributions. If you are familiar with Windows user administration then, this lesson will be much easier to digest. A Linux account is composed of several components: username, password, home directory and environment. You'll need to know that each username is identified by an UID (User ID) which is a unique number in the users database. The correspondence between UID and username is made to make things easier for System Administrators to identify System users.
   Users are organized into Groups to allow multiple accounts to interact with resources within the Linux File System. Each group is identified by a unique GID (group ID). Remember that each user can be part of one primary group and up to 15 secondary groups
   Just like in Windows, each file will have permissions assigned for several entities. In Linux, these entities are: owner, group and others. It's important to understand that each file will have these three permission categories assigned. Further more, each process running in Linux is executed using an UID and GID which basically sets the process permissions within the OS.
   The UID is a unique number that is below or equal to 2147483647. UID can be divided into three categories:
0 - super user account (root)
100, 500 or 1000 - depending on the distribution standard services and applications will require a service user to execute them. Remember that these accounts will normally not support interactive login and are used to serve as service accounts only.
above 1000 - Standard user accounts

There are several files which are responsible for storing the username, password and group information:
Linux passwd file/etc/passwd – username database
/etc/shadow – users password database
/etc/group – group database
/etc/gshadow – group password database
You can view the contents of any of these files by executing the cat command. Let's take for example passwd file which stores the System usernames: cat /etc/passwd

Each database entry is composed of several elements:
  • x - password field used in older Linux distributions, System passwords are now stored in /etc/shadow database
  • comment - used to add a description for a particular user
  • login_shell - default shell used by users when interacting with the Operating System.
Let's take a look in the password file using the same command: cat /etc/shadow
Each entry in the database is composed of several items:
    Linux shadow file
  • loginID - username which corresponds to an entry in the passwd file
  • password - password hash
  • latchg - the last date when the password was changed
  • the min, max values are the minimum and maximum days that must pass before the password can/must be changed
  • warn - a warning message can be set before the password expires
  • inactive - number of inactive days before the account is locked
  • expire - account expiration date
Linux group file
The group database includes secondary groups for each account. Type cat /etc/group to visualize its content.

As you can see from the command's output, each entry is composed of the following fields:
The username-list contains users that are part of that particular group.

Below you will find the main commands used to interact with usernames, groups and passwords
useradd,userdel,usermod – add/delete/modify users
groupadd, groupdel, groupmod – add/delete/modify groups
passwd – tool to change user's passwords
The following commands are used to interact with specific fields from the shadow and passwd databases: chfnchpasswdchagechsh

Useradd - command supports multiple parameters, I will point out some of these parameters:
-s - default shell used by the user
-c - additional comment can be set
-g - primary group of the user

-G - secondary groups

-u - sets the user's UID
-d - specifies the personal directory of the user
-m - creates the home directory
-U - creates a group that has the same name
Example: useradd -u 2014 -d /home/user1 -m -s /bin/bash -U user1
To explore all parameters for this command type man useradd or useradd --help:
Useradd command

Linux useradd command
We can set default parameters used when executing useradd command by editing the /etc/default/useradd file. You can used the -D parameter to visualize and interact with the default parameters used with this command. The command also supports so called skeleton directory which contain default configuration file for the user's environment. The skeleton directory can be set using SKEL=/etc/skel or useradd -k /path/to/skel. You can configure standard configuration files for different applications: bash,

.bashrc, .bash_history, .bash_profile, .inputrc, .vimrc, etc.

The usermod command supports similar parameters as useradd and it's used to change different fields from the username database. It would be good to remember the following parameters:
Usermod command
-U - unlock user account.
-L - lock user account. When a user is locked, a "!" symbol will be placed before its password in the /etc/shadow file. When a user is unlocked, the "!" character disappears:
Linux Usermod command
Linux passwd command

To change a user's password type passwd username. Let's take the newly created user and set a new password: passwd user1

Linux Userdel command
To delete an existing username, execute the following command: userdel username. The command with any parameters will delete the user from the passwd and shadow files but, will not delete its home directory. To include the home directory deletion in the command execution, add the -r parameter

That's about it for this article folks, please share your thoughts about it and don't forget to share it to others. If you have any suggestions regarding this topic don't hesitate to use my comments dedicated section. Wish you all the best and don't forget to enjoy your day!
Read More
© 2014 All Rights Reserved.
IT training day & Powered By BloggerHero