Tuesday, January 18, 2011

Enable Mail Notification for CVS Commit on CVS Server

Ever wanted to be notified by email to know about who has committed which files and when in specific project in CVS ? Well, Following is the configuration and procedure to enable email notification on CVS Server for cvs commit.

Step 1 : Add the following line in " loginfo" file in the respective CVSROOT ( e.g. /home/cvs/CVSROOT/loginfo) to enable logging of commit for the respective repository

^repositoryname             (echo "At `date`, `whoami` has modified/added following file(s)."; echo "New Versions are :" %v . ; cat ; ) | grep -v -w "In directory " >> /var/log/cvslog/commitlog


In above line " ^repositoryname " is a repository name for which you want to enable logging. The remainder line is containing the command or filter program to execute whenever any matches found ( i.e. any commit has been made to the specified repository ) . Explanations for each switch used in above command are as follows.

        "  s = file name "
        "  V = old version number (pre-checkin) "
        "  v = new version number (post-checkin) "

So, in simple words what above line will do is whenever any user make cvs commit to that repository, it will collect information such as username, date and time when it is committed, new version numbers, names, etc. and put it into one file ( /var/log/cvslog/commitlog in this case) and it will append the same file for all commit made to that repository

Now we will set one script to simply send that log file to the specified email as shown in below and we will put this script in crontab to run at 6:00 PM everyday

Step 2 :Create cvsmail.csh file on your CVS Server linux machine and add following contents into it and save it

[root@CVS ~]# vi /home/cvs/cvsmail.csh

#!/bin/csh
if ( `ll /var/log/cvslog | grep -w commitlog | wc -l` > 0 ) mail -s " CVS Commit Notification for repositoryname" abc@example.com < /var/log/cvslog/commitlog && if ( `ll /var/log/cvslog | grep -w commitlog | wc -l` > 0 ) rm -rf /var/log/cvslog/commitlog

[root@CVS ~]# chmod +x /home/cvs/cvsmail.csh
[root@CVS ~]# su - cvs

Step 3 :Create Crontab entry to schedule email notification at 6:00 PM daily. add following contents into it and save it.

[cvs@CVS ~]$ crontab -e

00  18 * * * /home/cvs/cvsmail.csh

[cvs@CVS ~]$

What above line will do is it will check if any commit made to any file in specified repository by checking if commitlog log file exists or not , if it is then it will send that log file to the specified email id and then remove that log file. Mail will be sent from id cvs@cvs.com

-
Sumit

Saturday, January 1, 2011

Configure Linux Server as a Router / Gateway


We can configure Linux Server as a Router or Gateway so that we can establish connection between two different networks which are not directly connected with each other without any use of Routing/Gateway Device.
 
Objective
·         We will create two subnet and will establish connection with two machines which are having different subnet’s IP Address and are not directly connected to each other. We will use Linux  Operating System in both PCs and will also use Linux PC which will act as a Router to establish connection between two different networks
·         We should be able to ping both machines from each other successfully
Requirements:
·         Three Linux PCs. Two Linux PC with One NIC and One Linux PC with two NICs
·         2 No. of 8 Port Unmanaged Network Switch
Network Diagram

Configuration Details
·         PC1 is connected to 8 port Switch as shown in network diagram.
·         PC2 is connected to another 8 port Switch as shown in network diagram.
·         ROUTERPC is connected to 8 port switch through ETH0 as shown in network diagram.
·         ROUTERPC is connected to another 8 port switch through ETH1 as shown in network diagram.
·         Network1  : 10.100.53.0/24
·         Network2  : 10.100.50.0/24
·         PC1 IP Address : 10.100.50.254
·         PC2 IP Address : 10.100.53.254
·         ROUTERPC’s ETH0 IP Address : 10.100.50.15
·         ROUTERPC’s ETH1 IP Address : 10.100.53.16
Configuration Steps:
1)      Assign IP Address 10.100.50.254 to PC1 as shown in below screenshot


2)      Assign IP Address 10.100.53.254 to PC2 as shown in below screenshot


3)      Assign IP Address 10.100.50.15 to ETH0 interface of ROUTERPC



 4)      Assign IP Address 10.100.53.16 to ETH1 interface of ROUTERPC


5)      Open /etc/sysctl.conf file in vi editor and set net.ipv4.ip_forward = 1 . This will enable IP forwarding/Routing on ROUTERPC as shown in below screenshot




 6)      Add static route on PC1 as shown below.


7)      Add static route on PC2 as shown below.


Expected Results:
1)      PC1 should be able to get ping reply from ROUTERPC
2)      PC1 should be able to get ping reply from PC2
3)      PC2 should be able to get ping reply from ROUTERPC
4)      PC2 should be able to get ping reply from PC1
5)      PC1 should be able to traceroute to PC2 through ROUTERPC
6)      PC2 should be able to traceroute to PC1 through ROUTERPC

Testing:
·         Ping from PC1 ( 10.100.50.254 ) to ROUTERPC’s ETH0 interface IP ( 10.100.50.15) and Ping from PC1 ( 10.100.50.254 ) to ROUTERPC’s ETH1 interface IP ( 10.100.53.16) as shown in below screenshot

 

·         Ping from PC2 ( 10.100.53.254 ) to ROUTERPC’s ETH0 interface IP ( 10.100.50.15) and Ping from PC2 ( 10.100.53.254 ) to ROUTERPC’s ETH1 interface IP ( 10.100.53.16) as shown in below screenshot

  
 
·         Ping from PC1 ( 10.100.50.254 ) to PC2 ( 10.100.53.254 ) and  Traceroute to PC2as shown in below screenshot and 

  
·         Ping from PC2 ( 10.100.53.254 ) to PC1 ( 10.100.50.254 ) Traceroute to PC1 as shown in below screenshot

Above exercise may helpful to all newbies who have just started using linux and want to gain more knowledge on linux.  We can also use iptables to apply ACLs and security restrictions between two networks.

--
Sumit


Tuesday, December 28, 2010

Windows Tips and Tricks: Access / Mount Linux NFS share under Windows 7

Access / Mount Linux NFS share under Windows 7:
Windows 7 has inbuilt Client for NFS..

Configure Linux Samba Server as a Primary Domain Controller

We can use Samba as a Primary Domain Controller and can add windows machines in that domain. Following is step-by-step guide to configure Samba as a PDC.

Step 1 : Configure Samba as PDC ( Primary Domain Controller ) and allow samba to act as a Domain Controller
To allow Samba to act as a Primary Domain Controller, we need to set certain options in smb.conf file. Open /etc/samba/smb.conf file and under  [global] section, set options as mentioned below.

==================================================
[global]
workgroup = smb      ###Give your desired netbios domain name here e.g. TESTDOMAIN or ABC (without ".com " ) ###
netbios name = eildap    ### This will be netbios name of your samba server  ###
server string = Samba PDC Server   ### You can set your own description here ###
security = user 
encrypt passwords = yes
hosts allow = 127. 192.168. 172.16.   ### List down all networks which you want to allow to access samba services ###
log file = /var/log/samba/%m.log    ### To enable machine specific log  for troubleshooting  ###
max log size = 50   ### To keep log size limited to 50 KB ###
local master = yes
os level = 65
domain master = yes
preferred master = yes
domain logons = yes   ### This option will actually enables samba to be a PDC and will act as a domain controller ###
wins support = yes   ### WINS Support - Tells the NMBD component of Samba to enable it's WINS Server ###
username map = /etc/samba/smbusers
==================================================
Comment out all other options in [global] section if enabled and keep only above mentioned options.
Restart samba service by command /etc/init.d/smb restart

Step 2 : Set /etc/hosts file to resolve names properly
Open /etc/hosts file and make sure you have entries for hostname and samba domain name so that it can resolve names properly without any issue.

Step 3 : Set samba password for root so that we can join computer in domain with this username
From Linux Terminal type the following command to set the samba password for user root
[root@testdomain local]# smabpasswd -a root ### This will enable  samba account for user root which we will use to join windows xp computer in domain###

Step 4 : Add computer account on samba server
When we add windows machcine to any Active Directory domain, machine account gets created automatically in  OU called Computers in Active Directory, But  here in Samba we must add machine account manually on samba server before attempting to add your windows xp client to samba PDC domain .

For example, If I want to add one windows xp machine named " testclient "  in samba PDC domain, then I will need to execute following commands on samba server  from terminal

[root@testdomain local]# useradd -s /bin/false testclient$   ### Make sure to suffix " $ " with computername ###
[root@testdomain local]# smabpasswd -a -m testclient$ ### This will add this machine account name in smbpasswd file ###

Step 5 : Configure Windows XP Client to add to Samba PDC domain
  • If you are serving IP addresses through DHCP server then , you can configure your dhcp to set WINS Server IP on client machine.

  • If you are not running dhcp server and giving static ip to client machine , Go to Control Panel--> Network Connections --> Right click on " Local Area Connection " and click on Properties. It will open network properties.
  • Now select "Internet Protocol ( TCP/IP) and click on properties --> click on " Advance " --> click on "WINS" . Now add WINS Server ( IP of Samba PDC Domain Server )  as shown below. Also click " Enable Netbios over TCP/IP "



  • To force Windows XP Professional clients to accept Samba as a PDC, we need to use Group Policy Editor. Go to Start--> Run--> Type " gpedit.msc " and press ENTER. It will open group policy console.
  • Expand Computer Configuration --> Windows Setting--> Security Settings--> Local Policies--> User Rights Assignments and Make sure to disable the following policies
Domain Member: Digitally encrypt or sign secure channel data (always)
Domain Member: Digitally sign secure channel data (when possible)



Now we are good to go ahead and add this particular windows xp machine in samba pdc domain

Step 6 : Add Windows XP machine in Samba PDC Domain
  • Right Click on " My Computer " icon and click on Properties --> Go to "Computer Name " tab --> Click on "Change" button
  • Select " Domain " radio button and  type Samba PDC Name which we configured earlier in smb.conf, in this case it is       " SMB " and click on OK , it will prompt you to enter username and password , give username as " root " and password which we configured in Step 3  and click on OK.
  • You should then receive welcome message e.g. " Welcome to SMB domain " , click on OK button and restart your computer.
  • After restart you should be able to see CTRL + ALT + DEL screen at logon and you should be able to login to domain !!

This way you can use Linux Samba Server to act as Primary Domain Controller and  at some extent we can implement Group Policy to restrict/allow various access to local computer.!!

--
Sumit