Pages

Friday, 14 February 2014

Create a 1GB random file

dd can be used to wipe out the file, whole drive or partition permanently.
 
dd if=/dev/urandom of=sample.txt bs=1G count=1
 
dd if=/dev/zero of=sample.txt bs=1G count=1 
 

Thursday, 13 February 2014

SSH Login with password

Host A / User A ---login---> Host B / User B

Generating public / private rsa key pair

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Copy the public key from A:id_rsa.pub to B:authorized_keys 

a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password: 
 

SSH Login without password

a@A:~> ssh b@B hostname
B 

route and route table

[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.95.0     *               255.255.255.0   U     1      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
default         172.16.95.1     0.0.0.0         UG    0      0        0 eth0


The server is sitting on the subnet 172.16.95.0. Add a route to the route table. The route will be rolled back next reboot. 

The gw has to be the ip directly reachable from your subset.
[root@localhost ~]# route add -net 192.168.102.0 netmask 255.255.255.0 gw 172.16.95.2


[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.102.0   172.16.95.2     255.255.255.0   UG    0      0        0 eth0
172.16.95.0     *               255.255.255.0   U     1      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
default         172.16.95.1     0.0.0.0         UG    0      0        0 eth0

[root@localhost ~]# route del -net 192.168.102.0 netmask 255.255.255.0 eth0
[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.95.0     *               255.255.255.0   U     1      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
default         172.16.95.1     0.0.0.0         UG    0      0        0 eth0


Add the route permanently, network restart is needed.
[root@localhost ~]# echo "192.168.102.0/24 via 172.16.95.2" >> /etc/sysconfig/ne
twork-scripts/route-eth0

[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.102.0   172.16.95.2     255.255.255.0   UG    0      0        0 eth0
172.16.95.0     *               255.255.255.0   U     1      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
default         172.16.95.1     0.0.0.0         UG    0      0        0 eth0

Wednesday, 12 February 2014

SNMP and its linux command

SNMP basic components and its functions:

    The SNMP architecture consists of
    The SNMP Manager
    A managed device
    An SNMP Agent
    Management Information Databases (otherwise known as Management Information Bases or MIBs)

    The SNMP Manager - (Usually the Network Management System - NMS) communicates with the multiple SNMP Agents implemented in the network.

    A managed device - or the network element is a part of the network that requires some form of monitoring and management e.g. routers, switches, servers, workstations, printers, UPSs, etc..

    An SNMP Agent - is a program that is bundled within the managed device. Enabling this agent allows it to collect the Management Information Database from the device locally to make it available to the SNMP Manager on request. These Agents could be standard (e.g. Net-SNMP) or specific to a vendor. (e.g. HP Insight Agent). The agent listens at port 161. TODO: UDP or TCP?

    Management Information Base / database - The commonly shared database between the Agent and the Manager is called Management Information Base (MIB). In short, MIB files are the set of questions that the SNMP Manager can ask the Agent. The Agent collects these data locally and stores it, as defined in the MIB.

    The MIBs contain a standard set of statistical and control values defined for the managed devices on a network. The SNMP protocol also allows the extension of these standard values with values specific to a particular Agent through the use of private MIBs. So the SNMP Manager should be aware of these standard and private questions for every type of Agent.
     
     
     

Linux Command 

One can simply issue one snmpwalk request on the root node of the sub-tree and the command gets the value of every node in the sub-tree.

[root@localhost ~]# snmpwalk -v 2c 169.254.0.8 -c FortiManager | grep OID
...
SNMPv2-SMI::mib-2.47.1.2.1.1.3.1 = OID: SNMPv2-SMI::enterprises.12356
...
[root@localhost ~]# snmpwalk -v 2c 169.254.0.8 -c FortiManager SNMPv2-SMI::enterprises.12356
...
SNMPv2-SMI::enterprises.12356.101.4.1.6.0 = Gauge32: 0
SNMPv2-SMI::enterprises.12356.101.4.1.7.0 = Gauge32: 0
SNMPv2-SMI::enterprises.12356.101.4.1.8.0 = Gauge32: 9
SNMPv2-SMI::enterprises.12356.101.4.1.9.0 = Gauge32: 80
SNMPv2-SMI::enterprises.12356.101.4.1.10.0 = Gauge32: 254764
SNMPv2-SMI::enterprises.12356.101.4.1.11.0 = Gauge32: 0
SNMPv2-SMI::enterprises.12356.101.4.1.12.0 = Gauge32: 0
SNMPv2-SMI::enterprises.12356.101.4.1.13.0 = Gauge32: 0
SNMPv2-SMI::enterprises.12356.101.4.1.14.0 = Gauge32: 0
...

[root@localhost ~]# snmpget -v 2c 169.254.0.8 -c FortiManager SNMPv2-SMI::enterprises.12356.101.4.1.8.0
SNMPv2-SMI::enterprises.12356.101.4.1.8.0 = Gauge32: 11