Wednesday, July 20, 2011

ESX Server Tips and Tricks

1) To enable ssh access to the ESX server, do the following

    Configuration->Security Profile->Properties->
       ->Remote Tech Support(SSH)->Start Automatically

2)   To view the Direct Console UI through SSH,
    Configuration->Security Profile->Properties->
       ->Direct Console UI->Start Automatically

     ssh to the esx server and type the following command
     dcui

3) To enable telnet access to the VM's in ESX server, do the following

   a) Power off the vm

   b) Edit VM Settings-> Click Add-> Select Serial Port-> connect via Network->
       Select Server (VM listens for connection) -> Port URI: telnet://10.44.1.2:3 ->
      Finish

   c) Power on the vm

   d) Go to a terminal and type "telnet 10.44.1.2 3"







Friday, July 1, 2011

Well Known port numbers

Portnumber                                       Service

Port Number Description
1 TCP Port Service Multiplexer (TCPMUX)
5 Remote Job Entry (RJE)
7 ECHO
18 Message Send Protocol (MSP)
20 FTP -- Data
21 FTP -- Control
22 SSH Remote Login Protocol
23 Telnet
25 Simple Mail Transfer Protocol (SMTP)
29 MSG ICP
37 Time
42 Host Name Server (Nameserv)
43 WhoIs
49 Login Host Protocol (Login)
53 Domain Name System (DNS)
69 Trivial File Transfer Protocol (TFTP)
70 Gopher Services
79 Finger
80 HTTP
103 X.400 Standard
108 SNA Gateway Access Server
109 POP2
110 POP3
115 Simple File Transfer Protocol (SFTP)
118 SQL Services
119 Newsgroup (NNTP)
137 NetBIOS Name Service
139 NetBIOS Datagram Service
143 Interim Mail Access Protocol (IMAP)
150 NetBIOS Session Service
156 SQL Server
161 SNMP
179 Border Gateway Protocol (BGP)
190 Gateway Access Control Protocol (GACP)
194 Internet Relay Chat (IRC)
197 Directory Location Service (DLS)
389 Lightweight Directory Access Protocol (LDAP)
396 Novell Netware over IP
443 HTTPS
444 Simple Network Paging Protocol (SNPP)
445 Microsoft-DS
458 Apple QuickTime
546 DHCP Client
547 DHCP Server
563 SNEWS
569 MSN
1080 Socks




Network Debugging Tools

i) ARP - Address resolution Protocol

   arp -a
   (gives the name, IP address and Mac address of the neighbour
    systems that your system is aware of)
=====OUTPUT========
lenovo.inca.infoblox.com (10.32.0.115) at 00:1a:6b:cd:b5:06 [ether] on eth0
loaner-it-lx.inca.infoblox.com (10.32.0.101) at 00:1c:c0:2f:89:25 [ether] on eth0
eng_gw.inca.infoblox.com (10.32.0.1) at 00:04:96:10:8d:e0 [ether] on eth0
=============

2) traceroute - Traces the route a packet travels to reach the destination and list all the routers that it crosses

traceroute 10.34.90.110


====OUTPUT======
 traceroute to 10.34.90.110 (10.34.90.110), 30 hops max, 60 byte packets
 1  eng_gw.inca.info.com (10.32.0.1)  1.121 ms  1.155 ms  1.193 ms
 2  eng-switch.inca.info.com (10.255.34.2)  88.346 ms  88.535 ms  88.717 ms
 3  scmserver1 (10.34.90.110)  75.210 ms  75.315 ms  75.423 ms
==========


3) ping  - Basic way to check if  the host in a network is alive

=====OUTPUT======
ping 10.34.90.110
PING 10.34.90.110 (10.34.90.110) 56(84) bytes of data.
64 bytes from 10.34.90.110: icmp_req=1 ttl=62 time=9.63 ms
64 bytes from 10.34.90.110: icmp_req=1 ttl=62 time=9.85 ms (DUP!)
=================

   a) ping -c 3 10.34.90.110


       ping only three times





4) lsof  - list open files
    Can be used to check if a port is in use or not and how many are used along with PID number


In the below example, 80 is the port number for http
=====OUTPUT======
[amurugan@amurugan-lx ~]$ lsof -i:80
COMMAND     PID     USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
firefox-b   469 amurugan   67u  IPv4 50922854      0t0  TCP amurugan-lx.inca.info.com:54066->solint3.sols.com:http (ESTABLISHED)
firefox-b   469 amurugan   81u  IPv4 65637618      0t0  TCP amurugan-lx.inca.info.com:37499->phx1-dw-xw-lb.cnet.com:http (ESTABLISHED)

===============

b) Type the following command to see IPv4 port(s), enter:
   # lsof -Pnl +M -i4

c) Type the following command to see IPv6 listing port(s), enter:
  # lsof -Pnl +M -i6


5) dmesg
    dmesg - print or control the kernel ring buffer
    Can be used to figure out the devices connected to USB

=========OUTPUT======
[3288265.502041] pl2303 ttyUSB0: pl2303 converter now connected to ttyUSB0
======================

6) ifconfig   -  Check if your interface is configured


=======OUTPUT========
ifconfig
eth0      Link encap:Ethernet  HWaddr 00:60:08:93:0E:05
          inet addr:128.42.14.176  Bcast:128.42.14.255  Mask:255.255.255.0
          EtherTalk Phase 2 addr:49600/201
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:33933225 errors:0 dropped:0 overruns:0 frame:0
          TX packets:38375051 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          EtherTalk Phase 2 addr:0/0
          UP LOOPBACK RUNNING  MTU:3924  Metric:1
          RX packets:3527806 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3527806 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0
====================

a) To set up an interface, issue the following command

    ifconfig eth0 128.42.14.176 netmask 255.255.255.0 up

b) deactive eth0


ifdown eth0
 
c) activate eth0 
 
ifup eth0 


 7) route
  Routing is just a set of rules that control how network traffic is directed

=======OUTPUT============
[amurugan@amurugan-lx ~]$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.32.0.0       0.0.0.0         255.255.0.0     U     1      0        0 eth0
0.0.0.0         10.32.0.1       0.0.0.0         UG    0      0        0 eth0
=========================

a) route add -net <naddr> netmask <maddr> gw <gaddr> eth0

b) route add default gw <gaddr> eth0
    or
    ip route add default via <gaddr> dev eth0

c) route add -host 10.0.0.1 gw 192.168.1.254 eth0

 d) ip route show
   ip route add 192.168.1.0/24 dev eth0
   ip route delete 192.168.1.0/24 dev eth0
   

If you wanted to add a route to an individual server, then the "-host" switch would be used with no netmask value. (The route command automatically knows the mask should be 255.255.255.255).


8)  Name resolution

This is the part of networking that maps www.yahoo.com onto an IP address. You'll need to have 3 files: /etc/host.conf, /etc/hosts, /etc/resolv.conf. Respectively, they should contain:

/etc/host.conf:
order hosts,bind
multi on
/etc/hosts:
127.0.0.1      localhost loopback
<yaddr>        this.host.name
If you don't have a hostname, then you can leave off the second line.
/etc/resolv.conf:
domain yourdept.yourcompany.com
search yourdept.yourcompany.com yourcompany.com
nameserver <daddr>
You can add additional 'nameserver <daddr>' lines if you have a secondary (or tertiary) DNS. The search line is just a list of domains to be searched when you type an incomplete hostname. The domain line corresponds to the domain that you belong to.

9) TCPDUMP

a)  tcpdump -i eth0 tcp port 80

This will monitor the interface eth0 for all traffic being sent to or from port 80

b) tcpdump -i eth0 tcp dst port 80 and src host 10.32.2.56

only watches outbound traffic to port 80, ignoring all inbound traffic on port 80

c) tcpdump -q -i eth0 tcp dst port 22 and src host 10.32.2.56

don’t need all the extraneous information and just want to see the connections directly

 
d) To capture all the packets related to dhcp, issue the below command



    tcpdump -i any port bootps or port bootpc
       or
    tcpdump -i any port 67 or port 68

e) To split a large pcap file into smaller 10Mb file

   tcpdump -r old_file -w new_files -C 10
 
The "-C" option specifies the size of the file to split into. Eg: In the above case new files size will be 10 million bytes each.

10) netstat

a) The netstat -nr command will provide the contents of the touting table. Networks with a gateway of 0.0.0.0 are usually directly connected to the interface. No gateway is needed to reach your own directly connected interface, so a gateway address of 0.0.0.0 seems appropriate. The route with a destination address of 0.0.0.0 is your default gateway.

]# netstat -nr

Kernel IP routing table
Destination     Gateway     Genmask         Flags MSS Window irtt Iface
255.255.255.255 0.0.0.0     255.255.255.255 UH    40  0      0    wlan0
192.168.1.0     0.0.0.0     255.255.255.0   U     40  0      0    wlan0
127.0.0.0       0.0.0.0     255.0.0.0       U     40  0      0    lo
0.0.0.0         192.168.1.1 0.0.0.0         UG    40  0      0    wlan0 
 
b) To list only the listening sockets 
 
       ]# netstat -ntl | grep <port number>
 
        or
       ]# netstat -l | grep http 
 
c) To show to Program and PID to which each socket belongs

          ]# netstat -ntlp | grep 389

     # netstat -tulpn | grep :80

d) ss is used to dump socket statistics

ss -ntlp | grep synergy
LISTEN     0      3                         *:24800                    *:*      users:(("synergys",2697,6))


11) snoop - coming soon



12) wireshark tips

   a) To see all the packets related to dhcp in wireshark GUI, apply the filter
       bootp

   b) tcpdump -i any port bootps or port bootpc
       or
       tcpdump -i any port 67 or port 68

  c) Filters for wireshark GUI,

     ip.src == 10.35.2.74

     ip.dst == 10.32.1.171

     ip.addr == 10.35.2.74

     ip.src != 10.1.2.3 or ip.dst != 10.4.5.6

     tcp.port == 25

     tcp.dstport == 25

     ip.src==192.168.0.0/16 and ip.dst==192.168.0.0/16

    smb || nbns || dcerpc || nbss || dns

    ip.src == 10.43.54.65 or ip.dst == 10.43.54.65

    ! ( ip.addr == 10.43.54.65 )

  To filter based on mac address

   eth.addr==00:30:48:bc:96:0f and eth.src== 00:30:48:bc:96:0f
and eth.dst==ff:ff:ff:ff:ff:ff

d) To filter based on dhcp option type number:
bootp.option.type==118

e) :X: You don't need to remember all the filters, Easy way is to select the particular field you want to filter, right click, select "apply as filter"  and click Selected.



13) nmap - Network exploration tool and security / port scanner

      a) To do a simple scan on the network or host

          nmap -sP 10.35.0.0/24  <= Ping Scan
          nmap –sP 192.168.0.1-255  <= Ping Scan

      b) nmap –sT 192.168.0.1
          simplest form of scanning. It connects to every open port on the target
          machine and lists the open ports

       c) nmap -O -v 10.x.x.x
           If you need more information about the host you are scanning.


14) arp-scan - The ARP scanner

       arp-scan  --interface=eth0 192.168.0.0/24


15) Netfilter - IP tables rules


a) List all rules
iptables -L

b) Flush all policies
iptables -F

c)Chain Drop all the input/output/forward packets

iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

d)Policy Allow only from particular source

iptables -A INPUT -i eth0 -s 10.32.0.0/16 -j ACCEPT
iptables -A INPUT -i eth0 -s 10.32.1.171 -j ACCEPT

iptables -A OUTPUT -i eth0 -s 10.32.0.0/16 -j ACCEPT
iptables -A OUTPUT -i eth0 -s 10.32.1.171 -j ACCEPT

e) Block outgoing traffic

# block outgoing traffic to ip 1.2.3.4
iptables -A OUTPUT -d 1.2.3.4 -j DROP

# block outgoing traffic to port 5678
iptables -A OUTPUT -p tcp –dport 5678 -j DROP

# block outgoing traffic to 1.2.3.4:5678
iptables -A OUTPUT -p tcp -d 1.2.3.4 –dport 5678 -j DROP


f) To save and restore iptables

    i) saves the current iptables rules to a file

       iptables-save > rules.txt

    ii) To restore the iptables rules from a file
 
       iptables-restore < rules.txt



Note:
  -A: Append to the INPUT/OUTPUT/FORWARD chain
  -i : interface
  -s: Source address (Layer 3)
  -d: Destination address (Layer 3)

  -j : Jump or Target ACCEPT/DROP/DENY/REJECT/LOG
  [Layer4] --sport(source port), --dport(destination port),
                 -p (protocol tcp/udp)

 iptables commands
  1. name of chain - action(what to do to the chain(Append/Insert/Replace)
  2. name of table(filter), - mangle/nat/user-defined
  3. layer3 object(source/destination address) -s/-d
  4. optionally layer4 object (tcp/udp protocols/ports) -p, --sport/--dport
  5. Jump/Target -j - ACCEPT/DROP/DENY/REJECT/LOG

============================
16)  vmstat

1. Execute vmstat
    # vmstat 1

 2. Execute vmstat ‘X’ seconds and (‘N’number of times)
     #vmstat 2 6


3. Vmstat with timestamps
vmstat command with -t parameter shows timestamps with every line printed as shown below.

]$ vmstat -t 1 5

4. Statistics of Various Counter

vmstat command and -s switch displays summary of various event counters and memory statistics.

]$ vmstat -s

      1030800  total memory
       524656  used memory
       277784  active memory
       185920  inactive memory
       506144  free memory
        26864  buffer memory

5. Disks Statistics

vmstat with -d option display all disks statistics.

[tecmint@tecmint ~]$ vmstat -d

disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
ram0       0      0       0       0      0      0       0       0      0      0
ram1       0      0       0       0      0      0       0       0      0      0

6. Display Statistics in Megabytes

The vmstat displays in Megabytes with parameters -S and M(Uppercase & megabytes). By default vmstat displays statistics in kilobytes.

[root@tecmint ~]# vmstat -S M 1 5

7. Display CPU and I/O statistics

iostat without arguments displays CPU and I/O statistics of all partitions as shown below.

[root@tecmint ~]# iostat

Linux 2.6.32-279.el6.i686 (tecmint.com)         09/03/2012      _i686_  (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.12    0.01    1.54    2.08    0.00   96.24

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               3.59       161.02        13.48    1086002      90882
dm-0              5.76       159.71        13.47    1077154      90864
dm-1              0.05         0.38         0.00       2576          0

8. Shows only CPU Statistics

iostat with -c arguments displays only CPU statistics as shown below.

[root@tecmint ~]# iostat -c

9. Shows only Disks I/O Statistics

iostat with -d arguments displays only disks I/O statistics of all partitions as shown.

[root@tecmint ~]# iostat -d

10. Shows I/O statistics only of a single device.

By default it displays statistics of all partitions, with -p and device name arguments displays only disks I/O statistics for specific device only as shown.

[root@tecmint ~]# iostat -p sda

11. Display LVM Statistics

With -N (Uppercase) parameter displays only LVM statistics as shown.

[root@tecmint ~]# iostat -N


12. iostat version.

With -V (Uppercase) parameter displays version of iostat as shown.

[root@tecmint ~]# iostat -V

=================================================




Friday, June 24, 2011

General Computer tips


1) How to avoid wireless not detected while waking the computer from sleep in Win 7?

i) Go to Control Panel
    type wireless
    Select Device Manager
    Network Adapters
      Intel Wireless - Double click
       Power management
         Disable "Allow the computer to turn off this device to save power"

ii) Go to Control Panel
    type power options and select it.
    power saver -> change plan settings
   change advanced power settings
   Wireless Adapter settings
    power saving mode,
    on battery: select maximum performance


  
2) How to have fast remote connection from Windows to fedora?

    Go to Fedora, Install the following

    i) yum install xrdp.i686
   ii) /etc/init.d/xrdp start
   iii) Go to Windows, Open Remote Desktop connection
         Enter Fedora IP address, click connect

         Enter Fedora username and password


3) If your keyboard gets num locked(abcdefgh51230n6*qrst4vwxyz), try the following
 
  i) press NumLk or
  ii) press Fn + NumLk or
  iii) Press Shift + NumLk


4) How to kill all the background Firefox process in windows 7

   open the cmd prompt and type
   taskkill /IM firefox.exe /F

Type "taskkill /IM firefox.exe /F" to the right of the command prompt and then press "Enter." This kills all running Firefox processes on the computer.


Monday, May 16, 2011

Helpful Linux commands

1) To start the GUI interface in linux

    startx &

2) To install unrar(extract .rar package) in a fedora desktop, do the following

su -c "rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm"

su -c "rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm"

su -c "yum install unrar"


 3) How to Restart the Apache Server?
      /etc/init.d/httpd restart

4) How to mount iso image on linux?
    # su -
    # mkdir /mnt/test
    # mount file.iso -o loop -t iso9660  /mnt/test  

5) How to Re-Mount /etc/fstab without Restarting?

You have added new entry in your /etc/fstab file to mount a drive or partition. To mount those new partitions you would normally reboot your PC. There is a simple way which will Re-Mount the drives in your /etc/fstab file. Run as root.

    mount -a 

6) To set environmental variables for vi Editor

     i) cd
     ii) vi .exrc
               set ic    #(to ignore case while searching the vi editor)
               set paste #(to avoid intending and commenting while copy pasting from web)


b) To delete particular lines based on search criteria in an vi editor

Using vi global commands
Using vi, you can issue global commands from command mode. If you are not sure of the case used, you can issue this command from vi command mode before you make the global change:
:set ic
(set ignorecase)
:g/outdated/d
This command tells vi to do a global search for "outdated" and to delete any line containing that text.
:g/out dated/d
This command tells vi to do a global search for "out dated" and to delete any line containing that text--including the space. 

7) General

1) For clearing java cache.
rm -fr ~/.java

-----------------------------------
3) Replace the bracket contents in shell

:%s/step:\([^ ]\)/step: \1/cg

-----------------------------------
4) Commands

which syslog-ng

yum search syslog-ng

yum install syslog-ng.i386

pkill syslog-ng

------------------------------------
7) To restore last known good configuration in windows xp
   i) Press F8


-----------------------------------
8) Replace a text with enter character

 %s /></> </cg

press Ctrl+V and Ctrl+M

-------------------------------------10) lineBreaker command

 grep "admin" -ir * | lineBreaker

will display the lines with linebreak.

------------------------------------

12) To generate CA Certificate using GUI
   tinyca2


--------------------------------

13) To trace a process using pid, use the following


strace -p 13890


-------------------------------
14) Command to increase date by 3 days

date --set='+8 days'

--------------------------------

16) To insert space before a paragraph

 - Cntrl+V select the space
 - Shift+Delete
 - u - Undo
 - Shift+P for pasting

-----------------------------------
19) To capture tcpdump

 tcpdump -i eth0 -w linux.cap

----------------------------------

20) To view the files in apache,
  check the logs in
/etc/httpd/logs/error_log

/etc/httpd/modsecurity.d/modsecurity_crs_50_outbound.conf

/etc/init.d/httpd restart

/etc/httpd/modsecurity.d/modsecurity_crs_50_outbound.conf

/etc/init.d/httpd restart

--------------------------------
-------------------------------22)

To set ignore case in vi automatically


vi ~/.exrc

:set ic
--------------------------------

1) To view APACHE Error Logs:
    su -
    tail -f /var/log/httpd/error_log

2) Linux: How to send email in command line?
    cat ~/license.dat | mutt -s "license 10.32.2.56" arul@infoblox.com

3)  How do you check whether a port currently being used?

     i) netstat -a | grep http
     or
     ii) lspf -i: 80
         (list open files)

4) Command to exit from login prompt in telnet:

    Cntrl + ]

5)  Command to check the latest usb connected to the linux OS   
     dmseg 
     (print or control the kernel ring buffer)

6) Make an ISO Image on Linux

To make an ISO from your CD/DVD, place the media in your drive but do not mount it. If it automounts, unmount it.
dd if=/dev/dvd of=dvd.iso # for dvd
dd if=/dev/cdrom of=cd.iso # for cdrom
dd if=/dev/scd0 of=cd.iso # if cdrom is scsi
To make an ISO from files on your hard drive, create a directory which holds the files you want. Then use the mkisofs command.

mkisofs -o /tmp/cd.iso /tmp/directory/
This results in a file called cd.iso in folder /tmp which contains all the files and directories in /tmp/directory/.

7) Vncviewer display problems

   When you connect to Centos linux using vncviewer and you see grey screen
   with three options, you need to do the below

   vi ./.vnc/xstartup

   Uncomment the below lines
   unset SESSION_MANAGER
   exec /etc/X11/xinit/xinitrc



   Add the following at the end of the file

   startkde &

8) Error SIOCADDRT: No such process
  
    Solution: Most probably, the gateway is wrong, set it correctly and the error
    message will go away.

-------------------------------------------------------------
9) IPv6

a) Re-booting removes IPv6 address solution:

IPv6 Configuration in linux from command line:



# vi /etc/sysconfig/network
NETWORKING_IPV6=yes
 
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
 
IPV6INIT=yes
IPV6ADDR=2607:f0d0:1002:0011:0000:0000:0000:0002
IPV6_DEFAULTGW=2607:f0d0:1002:0011:0000:0000:0000:0001
 
#route -n -A inet6
 
    
b) Add IPv6 address
 
 
#sudo ifconfig eth0 inet6 add 2001:db8:a20::6666/64
or
#ip addr add 2001:db8::1/64 dev eth0
 
c) Add IPv6 Default route 
 
 
#ip -6 route add default via  2001:db8:a20::1 dev eth0

d) To see the IPv6 route
#/sbin/ip -6 route show dev eth0
or
#/sbin/route -A inet6

or

 # route -n -A inet6
e) To delete IPv6 Default route

 # ip -6 route del default via fe80::4255:39ff:fee6:ba3f dev eth0

f) Add IPv6 route 

#/sbin/route -A inet6 add 2000::/3 dev eth0

or

# /sbin/ip -6 route add 2000::/3 dev eth0 metric 1

g) IPv6 tools

 # ping6
 # traceroute6
 # tracepath6
 # ip -6
 # tcpdum ip6

========================================================================

10) Command to set/see what services will start during boot
      su -
      ntsysv

 =====================================


11) How to burn ISO image to a bootable DVD/CD in Fedora 14+

       You can use GnomeBaker to do it.
        Go to Tools->Burn DVD/CD image-> Select ISO image->click ok->click Start

 =====================================

12) To view the total diskspace in Linux,

      Execute the following command
      a) To view in GUI
            palimpsest & 
      or
      b) Command line view
            df -h
      or
      c) Command line view
            fdisk -l | grep Disk


=======================================

13) To list the rpm installed in your linux
       

      rpm -qa

       To grep for particular installed package (qa = query all)

#     rpm -qa|grep -i "ldap"

      To list where it is installed

       (ql = query list)
#       rpm -ql openldap-clients

==========================================

14) To check the linux version in command line

      # cat /etc/issue


==========================================

15) Linux command to convert video .mov files to .avi files
       #yum install ffmpeg

       #ffmpeg -i path/video1.mov path/movie2.avi

===========================================

16) To query MX/SRV records using nslookup command in Windows

C:\Users\arul>nslookup

> server 10.34.8.70
Default Server:  [10.34.8.70]
Address:  10.34.8.70

> set q=srv
> srv2.http.del.infoblox.com
Server:  [10.34.8.70]
Address:  10.34.8.70

Non-authoritative answer:
srv2.http.del.infoblox.com      SRV service location:
          priority       = 0
          weight         = 0
          port           = 0
          svr hostname   = 7.7.7.7
>
> set q=a
> c2.infoblox.com
Server:  [10.34.8.70]
Address:  10.34.8.70

Name:    a1.del.infoblox.com
Address:  1.1.1.1
Aliases:  c2.infoblox.com

===================================================
17) Perl Getopt and Getopts summary:

use Getopt::Std;
getopt('oDI'); # -o, -D & -I take arg. Sets $opt_* as a side effect.
getopt('oDI', \%opts); # -o, -D & -I take arg. Values in %opts
getopts('oif:'); # -o & -i are boolean flags, -f takes an argument
                       # Sets $opt_* as a side effect.
getopts('oif:', \%opts); # options as above. Values in %opts

==================================================

18) How to enable ssh in latest Fedora 17, Fedora 18 and above

i) ]#service sshd start
        ii) [root@fedora ~]# chkconfig sshd on
   Note: Forwarding request to 'systemctl enable sshd.service'.
           To start sshd service upon boot, you can use this command
     chkconfig sshd on
      iii) When you reboot your Fedora, sshd service will be loaded automatically.
           You can check if sshd running using this command
    ]#service sshd status

==================================================

19) Basic Awk scripts


 
a) awk 'pattern {action}' input-file > output-file

b) awk '{ print $5 }' table1.txt > output1.txt
 

If the column separator is something other than spaces or tabs, such as a comma, you can specify that in the awk statement as follows:


c) awk -F, '{ print $3 }' table1.txt > output1.txt
 
 
The list of statements inside the curly brackets ('{','}') is called a 
block. If you put a conditional expression in front of a block, the 
statement inside the block will be executed only if the condition is 
true.

d) awk '$7=="\$7.30" { print $3 }' table1.txt 


 
You can also use regex as condition. For example:

e) awk '/30/ { print $3 }' table1.txt
 
 
Ex: 
/sbin/ifconfig p34p1 | awk '/inet/ { print $2 } '
 
 

f) awk '{ print ($2 * $3) + $7 }'
 
 
==================================================

20) Basic Sed scripts

i) a) 
      sed 's/6.30/7.30/' songs.txt > songs2.txt
 
To find and replace within the same file 
 
b) 
 
sed 's/6.30/7.30/' -i /tmp/songs.txt 
 
ii) date | sed 's/20/30/'

Thu Mar 14 15:10:11 PDT 3013
iii) To filter lines in a file or stream. For example if you only want see the lines 
      containing "day" you could use:

sed -n '/day/p' week.txt > days.txt
 

==================================================
21) To skip searching particular directories in find command

If you want to search for file name 'meminfo' recursively in the current directory but want to skip the directorys "./import" and './mnt', use the following command


find . -path ./import -prune -o -path ./mnt -prune -o -name "meminfo"


find [source dir] -path [source dir]/[sub dir 1] -prune -o -path [source dir]/[sub dir 2] -prune -o -name [filename]
 ==================================================

22)
To avoid the below warning when using LWP:Useragent against a HTTPS site:
*******************************************************************
 Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
 is depreciated! Please set SSL_verify_mode to SSL_VERIFY_PEER
 together with SSL_ca_file|SSL_ca_path for verification.
 If you really don't want to verify the certificate and keep the
 connection open to Man-In-The-Middle attacks please set
 SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
 
If you are worried about mitm attack, Use the following in LWP::UserAgent construction:

my $ua = LWP::UserAgent->new(
                         ssl_opts => {
                             verify_hostname => 0, 
                             SSL_verify_mode => 0x00 
                            }); 
 
============================================================================================== 

23) To view the output as well as capture it, use tee command

tcpdump -i p34p1 | tee dat


============================================================================================== 

24) To disable selinux on Fedora
       vi /etc/selinux/config
       SELINUX=disabled

To check status
/usr/sbin/getenforce

        #setenforce 0

       Use Enforcing or 1 to put SELinux in enforcing mode.
       Use Permissive or 0 to put SELinux in permissive mode.



============================================================================================== 
 25) In Fedora, if gnome has crashed and you want to login to command prompt, press
    Cntrl + Alt + F6
 
===============================================================================================
 
 26) Find a certain word from all of the directories in current path recursively
 
find . -name "$1" | xargs grep -is "$file"


===============================================================================================
 
26) To get the snmp traps

snmptrapd -m SMI-MIB.txt:TRAP-MIB.txt -d -Lf ./snmp.log -F "%v %w %W"
 
 
 ===============================================================================================
27) To install Fedora from usb drive on linux os

     a) Download fedora to the local drive on linux
     b) su -c 'yum install liveusb-creator'
     c) Open liveusb-creator GUI
     d) Select iso from hard disk
     e) On the target, select usb stick and click create live usb
     f) Once it is done 100%, reboot the linux os and select the
         option to install from usb stick
     g) Continue to install new fedora os from usb
==================================================
28) Windows:

Copy Files recursively from inside directory to outside using batch file
Execute the following command from your folder: 
for /r /d %F in (*) do @copy /y "%F\*"
 
 ============================================================================================
 
29) Wget command to download songs
 
wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off -i ~/mp3blogs.txt 
 
 
wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off "http://songsdownload.com"

====================================================================================

30)  tee command

The following command (with the help of tee command) writes the output both to the screen (stdout) and to the file.
 # ls | tee file
By default tee command overwrites the file. You can instruct tee command to append to the file using the option –a as shown below.
# ls | tee -a file
You can also write the output to multiple files as shown below.
$ ls | tee file1 file2 file3
==========================================================================
31)

Many times you must have observed that clipboard operations like copy/cut and paste suddenly stops workings with the vncviewer. The main reason for this there is a program called as vncconfig responsible for these clipboard transfers. Some times the program may get closed because of some bug in vnc or some other reasons like you closed that window.
To get those clipboard operations back you need to run the program "vncconfig &".
After this your clipboard actions should work fine with out any problems.
============================================================
32) ifconfig deprecated. ip command line examples

1. How to Assign a IP Address to Specific Interface
# ip addr add 192.168.50.5 dev eth1

2. How to Check an IP Address
# ip addr show

3. How to Remove an IP Address
# ip addr del 192.168.50.5/24 dev eth1

4. How to Enable Network Interface
# ip link set eth1 up

5. How to Disable Network Interface
# ip link set eth1 down

6. How do I Check Route Table?
# ip route show

7. How do I Add Static Route
# ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0

8. How to Remove Static Route
# ip route del 10.10.20.0/24

9. How do I Add Persistence Static Routes
# vi /etc/sysconfig/network-scripts/route-eth0
10.10.20.0/24 via 192.168.50.100 dev eth0

# /etc/init.d/network restart

10. How do I Add Default Gateway
# ip route add default via 192.168.50.100

11. How do I delete Default Gateway

# ip route del default gw 192.168.50.100

==============================================

33) To set indentation to 4 spaces for each tab
vi ~/.vimrc 
set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab 

===========================
34) To find your public ip using curl

curl ifconfig.me
78.22.13.44
==========================
35) To get the laptop model information
sudo dmidecode | grep -A 9 "System Information"

'-A 9' option is to get 9 lines after "System Information"
'-B 9' option is to get 9 lines before "System Information"

==========================
36) How to Setup Ubuntu vncserver for remote viewing and avoid grey screen
https://poweruphosting.com/blog/setup-vnc-server-on-ubuntu/

i) sudo apt install xfce4 xfce4-goodies tightvncserver
ii) vncserver
iii) vncserver -kill :1
iv) mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
v)  vi ~/.vnc/xstartup
     #!/bin/bash
     xrdb $HOME/.Xresources
     startxfce4 &
vi) sudo chmod +x ~/.vnc/xstartup
7) If you see grey screen, add the following

 #!/bin/sh
def
export XKL_XMODMAP_DISABLE=1
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &

8) apt-get install ubuntu-gnome-desktop -y

9) vncserver -kill :1
10) vncserver
=============================