Wednesday, October 19, 2011

Default DHCP on xen

Xen has its own DHCP server which uses virbr0 bridge,

For DHCP server to be ready, you need to make sure that libvirtd service is running.

To use any VM as dhcp client on Xen :

In the vm.cfg add the below entries :
========================
dhcp = "dhcp"
vif = ['bridge=virbr0,mac=00:16:3E:76:D6:7D,type=netfront']


mac is the mac address of eth0 configured in Virtual Machine.

Always hardcode the mac address by defining it in the
/etc/sysconfig/network/ifcfg-eth0 script in the VM machine

The line would be :

HWADDR=00:16:3E:76:D6:7D
BOOTPROTO=dhcp













Tuesday, October 18, 2011

Allowing DHCP for a particular client

Allowing only a particular dhcp client :
 ===========================
               
#  /sbin/modprobe ipt_mac
                
#iptables -A INPUT -p UDP --dport 67 --sport 68 -m mac --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT



DHCP server runs on UDP port 67
DHCP client runs on UDP port 68

Here mac-source is dhcp client mac address.               

Monday, October 17, 2011

How To DHCP on a Private Network with VM's :

How To DHCP on a Private Network with VM's :
====================================

Hypervisor : - Hypervisor-Host

DHCP Client : - Host-DHCP-Client

DHCP Server : Host-DHCP-Server

DHCP server:(Imp files/command)
Config file : /etc/dhcpd.conf
Pid file :  : /var/run/dhcpd.pid

The DHCP daemon can be configured with command line options by using the /etc/sysconfig/dhcpd file.
For security, DHCP can be bound to an interface so the allocation of addresses are only available to the private internal network
# cat /etc/sysconfig/dhcpd
# Command line options here
DHCPDARGS=eth0




DHCP client :(Imp files/commands)
/var/lib/dhclient/dhclient-eth0.leases ( To check lease obtained)

[root@Host-DHCP-Client ~]# ps -elf |grep dhclient
1 S root      1509     1  0  75   0 -  1692 -      19:45 ?        00:00:00 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient-eth0.leases -pf /var/run/dhclient-eth0.pid eth0



For Dhcp Client vm.cfg under Hypervisor:

/var/ovs/mount/70B7E79628294FF8A7C92D6EFCD506FA/running_pool/2374_Host-DHCP-Client

Add the below line :
--------------------------------------------------------------
dhcp = "dhcp"
vif = ['bridge=xenbr0,mac=00:16:3E:48:E1:3E,type=netfront']
--------------------------------------------------------------


mac addres is the address of eth0 in dhcp client Host-DHCP-Client

Started vm again
bash$xm create ./vm.cfg




Configuration in DHCP server :
=============================

1) Edit /etc/dhcpd.conf

[aime1@crm-ohs dhcpd]$ cat /etc/dhcpd.conf
ddns-update-style none;
#local7.* /var/log/dhcpd.log;
option domain-name-servers 144.20.190.70, 138.2.202.15, 130.35.249.41;

default-lease-time 86400;
max-lease-time 604800;

authoritative;

subnet 192.168.1.0 netmask 255.255.255.0 {
#        interface eth0:1;
        range 192.168.1.128 192.168.1.254;
         option subnet-mask  255.255.255.0;
        option broadcast-address 192.168.1.255;
#        option routers 192.168.1.10;

}
[aime1@crm-ohs dhcpd]$



2) start dhcp server

dhcpd eth0

Please Note dhcp runs only on eth0 or eth1 and it wont run on aliases like eth0:1

3) Check the status :

[root@crm-ohs ~]# /etc/rc.d/init.d/dhcpd status
dhcpd (pid  17607) is running...
[root@crm-ohs ~]#

4)  Added a (Virtual IP just to check )

$ifconfig eth0:1 192.168.1.10 netmask 255.255.255.0 up


eth0:1    Link encap:Ethernet  HWaddr 00:16:3E:41:46:00 
          inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1



Configuration in DHCP Client :
==============================

1)

[root@Host-DHCP-Client ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Xen Virtual Ethernet
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
[root@Host-DHCP-Client ~]#


2) restart network (or better reboot host)

/etc/rc.d/int.d/network restart

3) Now chekc the Ip obtained is in 192 series :

[root@Host-DHCP-Client ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:48:E1:3E 
          inet addr:192.168.1.254  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:fe48:e13e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:377865 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12622 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:91226762 (87.0 MiB)  TX bytes:8154809 (7.7 MiB)
         
         
         
         
         

Tuesday, October 4, 2011

Find files more than 10 MB

$ find . -type f -size +10000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

 Output will be like :


./soa/bam/applications/oracle-bam.ear: 63M
./soa/bam/applications/oracle-bam-was.ear: 63M
./soa/rcu/integration/bam/sql/sqlserver/icommand2.sql: 22M
./soa/rcu/integration/bam/sql/db2/icommand2.sql: 22M
./soa/rcu/integration/bam/sql/oracle/icommand2.sql: 22M
./soa/jdk/jre/lib/fonts/ALBANWTT.ttf: 25M
./soa/jdk/jre/lib/fonts/ALBANWTJ.ttf: 26M
./soa/jdk/jre/lib/fonts/ALBANWTS.ttf: 25M
./soa/jdk/jre/lib/fonts/ALBANWTK.ttf: 26M

Monday, September 12, 2011

ssh-keygen - password less login

To login From HostA To HostB Hostc, HostD HostE etc .... with out password.


On HOSTA (From where you connect)

$ ssh-keygen -t rsa

This will create a file
id_rsa.pub inside /home/user/.ssh

File:-  id_rsa.pub is a Public Key
File:-  id_rsa is a Private Key ( No need to copy this)



Now need to copy the id_rsa.pub(inside /home/user/.ssh/) to all hosts you want to login password less (for eg. to login to HostB,HostC,HostD,HostE etc...)

Enter password after prompting on below commands once.
$ssh-copy-id -i /scratch/aime/.ssh/id_rsa.pub oracle@hostb.us.oracle.com
$ssh-copy-id -i /scratch/aime/.ssh/id_rsa.pub oracle@hostc.us.oracle.com
$ssh-copy-id -i /scratch/aime/.ssh/id_rsa.pub oracle@hostd.us.oracle.com
$ssh-copy-id -i /scratch/aime/.ssh/id_rsa.pub oracle@hoste.us.oracle.com


Now Try:

$ ssh oracle@Hostb
Last login: Mon Sep 12 17:23:06 2011 from dhcp-singapore-test-1-vpnpool-10-191-74-134.vpn.hosta.com
[oracle@hosta ~]$

Likewise try:
$ ssh oracle@hostc

$ ssh oracle@hostd

$ ssh oracle@hoste

This will connect without password.
















Friday, September 2, 2011

For changing all .htm files in directory to .html files

sriram@ubuntu:~/scripts$ for file in *.htm; do mv "$file"  ${file%.htm}.html; done
sriram@ubuntu:~/scripts$ ls
10.html  2.html  4.html  6.html  8.html  test
1.html   3.html  5.html  7.html  9.html
sriram@ubuntu:~/scripts$

Killing all Stopped Jobs

$Jobs (Command shows 4 jobs all stopped , after I did a (Ctrl+z), Now i want to kill all that.

To List all jobs with pid's

bash-3.2$ jobs -p (will list all the pid's of jobs)

To kill those pid's
bash-3.2$kill -9 `jobs -p`