MoonPoint Support Logo

Geeks.com - Free Shipping



Advanced Search
February
Sun Mon Tue Wed Thu Fri Sat
     
8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      
2012
Months
FebMar
Apr May Jun
Jul Aug Sep
Oct Nov Dec


Sun, Nov 13, 2011 3:03 pm

Determining the Network Interface Card (NIC) in a Linux System with lspci

I found that a network interface card (NIC) in a system was not picking up an IP via DHCP. When I checked the IP configuration for the card, I saw it had an invalid MAC address of all zeros.
$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:19 Base address:0xdead

The system had an Ethernet controller built into the motherboard. In such cases you can determing what Ethernet controller is being used by opening the system case or you can use the lspci command.

$ lspci | grep Ethernet
00:04.0 Ethernet controller: Silicon Integrated Systems [SiS] 190 Ethernet Adapt
er

On Linux systems, the lspi command displays information about Peripheral Component Interconnect (PCI) buses in the system and devices connected to them.

In the above case I could see that the system needed a Linux driver for a SiS 190 Ethernet Adapter.

NAME
       lspci - list all PCI devices

SYNOPSIS
       lspci [options]

DESCRIPTION
       lspci  is  a  utility for displaying information about PCI buses in the
       system and devices connected to them.

       By default, it shows a brief list of devices. Use the options described
       below  to  request  either a more verbose output or output intended for
       parsing by other programs.

       If you are going to report bugs in  PCI  device  drivers  or  in  lspci
       itself,  please  include  output  of "lspci -vvx" or even better "lspci
       -vvxxx" (however, see below for possible caveats).

       Some parts of the output, especially in the highly verbose  modes,  are
       probably  intelligible only to experienced PCI hackers. For exact defi
       nitions of the fields, please consult either the PCI specifications  or
       the header.h and /usr/include/linux/pci.h include files.

       Access  to  some  parts of the PCI configuration space is restricted to
       root on many operating systems, so the features of lspci  available  to
       normal  users  are limited. However, lspci tries its best to display as
       much as available and mark all other information with  <access  denied>
       text.


OPTIONS
   Basic display modes
       -m     Dump  PCI  device data in a backward-compatible machine readable
              form.  See below for details.

       -mm    Dump PCI device data in a machine readable form for easy parsing
              by scripts.  See below for details.

       -t     Show  a tree-like diagram containing all buses, bridges, devices
              and connections between them.


   Display options
       -v     Be verbose and display detailed information about all devices.

       -vv    Be very verbose and display more details.  This  level  includes
              everything deemed useful.

       -vvv   Be  even  more  verbose  and  display  everything we are able to
              parse, even if it doesn't look interesting at all  (e.g.,  unde
              fined memory regions).

       -k     Show kernel drivers handling each device and also kernel modules
              capable of handling it.  Turned on by default when -v  is  given
              in  the  normal  mode of output.  (Currently works only on Linux
              with kernel 2.6 or newer.)

       -x     Show hexadecimal dump of the standard part of the  configuration
              space (the first 64 bytes or 128 bytes for CardBus bridges).

       -xxx   Show  hexadecimal  dump of the whole PCI configuration space. It
              is available only to root as several PCI devices crash when  you
              try to read some parts of the config space (this behavior proba
              bly doesn't violate the PCI standard, but  it's  at  least  very
              stupid).  However,  such  devices are rare, so you needn't worry
              much.

       -xxxx  Show hexadecimal dump of the extended (4096-byte) PCI configura
              tion space available on PCI-X 2.0 and PCI Express buses.

       -b     Bus-centric  view. Show all IRQ numbers and addresses as seen by
              the cards on the PCI bus instead of as seen by the kernel.

       -D     Always show PCI domain numbers.  By  default,  lspci  suppresses
              them on machines which have only domain 0.


   Options to control resolving ID's to names
       -n     Show  PCI  vendor and device codes as numbers instead of looking
              them up in the PCI ID list.

       -nn    Show PCI vendor and device codes as both numbers and names.

       -q     Use DNS to query the central PCI ID database if a device is  not
              found  in the local pci.ids file. If the DNS query succeeds, the
              result is cached in ~/.pciids-cache and it is recognized in sub
              sequent  runs  even if -q is not given any more. Please use this
              switch inside automated scripts only with caution to avoid over
              loading the database servers.

       -qq    Same as -q, but the local cache is reset.

       -Q     Query the central database even for entries which are recognized
              locally.  Use this if you suspect that the  displayed  entry  is
              wrong.


   Options for selection of devices
       -s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]
              Show  only devices in the specified domain (in case your machine
              has several host bridges, they can either  share  a  common  bus
              number  space  or  each  of them can address a PCI domain of its
              own; domains are numbered from 0 to ffff), bus (0 to  ff),  slot
              (0  to  1f) and function (0 to 7).  Each component of the device
              address can be omitted or set to "*", both meaning "any  value".
              All  numbers  are  hexadecimal.  E.g., "0:" means all devices on
              bus 0, "0" means all functions of device 0  on  any  bus,  "0.3"
              selects  third  function of device 0 on all buses and ".4" shows
              only the fourth function of each device.

       -d [<vendor>]:[<device>]
              Show only devices with specified vendor and device ID. Both ID's
              are  given  in  hexadecimal  and may be omitted or given as "*",
              both meaning "any value".


   Other options
       -i <file>
              Use    <file>    as    the    PCI    ID    list    instead    of
              /usr/share/misc/pci.ids.

       -p <file>
              Use  <file> as the map of PCI ID's handled by kernel modules. By
              default, lspci uses  /lib/modules/kernel_version/modules.pcimap.
              Applies only to Linux systems with recent enough module tools.

       -M     Invoke  bus  mapping  mode which performs a thorough scan of all
              PCI devices, including those behind misconfigured bridges,  etc.
              This option gives meaningful results only with a direct hardware
              access mode, which usually  requires  root  privileges.   Please
              note that the bus mapper only scans PCI domain 0.

       --version
              Shows lspci version. This option should be used stand-alone.


   PCI access options
       The  PCI  utilities  use  the  PCI  library to talk to PCI devices (see
       pcilib(7) for details). You can use the following options to  influence
       its behavior:

       -A <method>
              The  library  supports  a  variety  of methods to access the PCI
              hardware.  By default, it uses the first  access  method  avail
              able, but you can use this option to override this decision. See
              -A help for a list of available methods and their descriptions.

       -O <param>=<value>
              The behavior of the  library  is  controlled  by  several  named
              parameters.   This  option allows to set the value of any of the
              parameters. Use -O help for a list of known parameters and their
              default values.

       -H1    Use  direct hardware access via Intel configuration mechanism 1.
              (This is a shorthand for -A intel-conf1.)

       -H2    Use direct hardware access via Intel configuration mechanism  2.
              (This is a shorthand for -A intel-conf2.)

       -F <file>
              Instead of accessing real hardware, read the list of devices and
              values of their configuration registers from the given file pro
              duced  by  an  earlier run of lspci -x.  This is very useful for
              analysis of user-supplied bug reports, because you  can  display
              the  hardware configuration in any way you want without disturb
              ing the user with requests for more dumps.

       -G     Increase debug level of the library.


MACHINE READABLE OUTPUT
       If you intend to process the output of lspci automatically, please  use
       one of the machine-readable output formats (-m, -vm, -vmm) described in
       this section. All other formats are likely to change  between  versions
       of lspci.


       All  numbers  are always printed in hexadecimal. If you want to process
       numeric ID's instead of names, please add the -n switch.


   Simple format (-m)
       In the simple format, each device is described on a single line,  which
       is  formatted  as  parameters  suitable  for passing to a shell script,
       i.e., values separated by whitespaces, quoted and escaped if necessary.
       Some  of the arguments are positional: slot, class, vendor name, device
       name, subsystem vendor name and subsystem name (the last two are  empty
       if  the  device  has no subsystem); the remaining arguments are option-
       like:


       -rrev  Revision number.


       -pprogif
              Programming interface.


       The relative order of positional arguments and  options  is  undefined.
       New  options can be added in future versions, but they will always have
       a single argument not separated from the option by any spaces, so  they
       can be easily ignored if not recognized.


   Verbose format (-vmm)
       The  verbose  output is a sequence of records separated by blank lines.
       Each record describes a single device by a sequence of lines, each line
       containing  a single `tag: value' pair. The tag and the value are sepa
       rated by a single tab character.  Neither the  records  nor  the  lines
       within a record are in any particular order.  Tags are case-sensitive.


       The following tags are defined:


       Slot   The    name    of    the   slot   where   the   device   resides
              ([domain:]bus:device.function).  This tag is always the first in
              a record.


       Class  Name of the class.


       Vendor Name of the vendor.


       Device Name of the device.


       SVendor
              Name of the subsystem vendor (optional).


       SDevice
              Name of the subsystem (optional).


       PhySlot
              The  physical  slot  where  the  device resides (optional, Linux
              only).


       Rev    Revision number (optional).


       ProgIf Programming interface (optional).


       Driver Kernel driver currently handling  the  device  (optional,  Linux
              only).


       Module Kernel  module  reporting  that  it  is  capable of handling the
              device (optional, Linux only).


       New tags can be added in future versions, so you should silently ignore
       any tags you don't recognize.


   Backward-compatible verbose format (-vm)
       In  this mode, lspci tries to be perfectly compatible with its old ver
       sions.  It's almost the same as the regular  verbose  format,  but  the
       Device  tag is used for both the slot and the device name, so it occurs
       twice in a single record. Please avoid using this  format  in  any  new
       code.


FILES
       /usr/share/misc/pci.ids
              A list of all known PCI ID's (vendors, devices, classes and sub
              classes). Maintained at http://pciids.sourceforge.net/, use  the
              update-pciids utility to download the most recent version.

       /usr/share/misc/pci.ids.gz
              If  lspci is compiled with support for compression, this file is
              tried before pci.ids.

       ~/.pciids-cache
              All ID's found in the DNS query mode are cached in this file.


BUGS
       Sometimes, lspci is not able to decode the configuration registers com
       pletely.  This usually happens when not enough documentation was avail
       able to the authors.  In such cases, it at least prints the  mark to
       signal that there is potentially something more to say. If you know the
       details, patches will be of course welcome.

       Access to the extended configuration space is currently supported  only
       by the linux_sysfs back-end.


SEE ALSO
       setpci(8), update-pciids(8), pcilib(7)


AUTHOR
       The PCI Utilities are maintained by Martin Mares <mj@ucw.cz>.



pciutils-3.1.7                  31 January 2010                       lspci(8)

[/os/unix/commands] permanent link

Sun, Nov 13, 2011 10:46 am

lsusb

To see a list of all USB devices connected to a Linux computer, use the lsusb command.
# lsusb
Bus 005 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 001 Device 002: ID 0781:5530 SanDisk Corp.
Bus 001 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000

Note: if you type lsusb and get a "command not found" message, the command may not be in your path. It may be in /sbin, so try specifying the path /sbin/lsusb.

To see more details on the USB devices attached to the system, use lsusb -v. If you don't specify a particular device you are interested in, you will get quite a bit of information. To restrict the information to a particular device, e.g., the SanDisk flash drive in the list above, you can specify a device and bus number, e.g., bus 001 and device number 002 in the above case, using the -s option.

# lsusb -v -s 1:2

Bus 001 Device 002: ID 0781:5530 SanDisk Corp.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x0781 SanDisk Corp.
  idProduct          0x5530
  bcdDevice            1.00
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           32
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk (Zip)
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               1
can't get device qualifier: Connection timed out
can't get debug descriptor: Connection timed out

If you move the USB device to another USB port on the system, you will see the bus number and device number combination change.

# lsusb
Bus 005 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 001 Device 007: ID 0781:5530 SanDisk Corp.
Bus 001 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000

The full list of options for the command is shown below.

# lsusb -h
lsusb: invalid option -- h
Usage: lsusb [options]...
List USB devices
  -v, --verbose
      Increase verbosity (show descriptors)
  -s [[bus]:][devnum]
      Show only devices with specified device and/or
      bus numbers (in decimal)
  -d vendor:[product]
      Show only devices with the specified vendor and
      product ID numbers (in hexadecimal)
  -D device
      Selects which device lsusb will examine
  -t
      Dump the physical USB device hierarchy as a tree
  -V, --version
      Show version of program

References:

  1. Linux / Unix Command: lsusb
    Linux Operating System and Linux Distributions

[/os/unix/commands] permanent link

Fri, Nov 11, 2011 2:04 pm

Creating a tar file from a list of files

If you wish to create a tar file using a text file which contains the list of files to be archived, you can do so using the xargs command.
$ cat filenames.txt | xargs tar -cvf allfiles.tar

If the list of file names contains spaces in file names or in the directory paths, you should put double quotes at the beginning and end of each line before you run the tar command, which you can do with the sed command.

$ sed -i 's/^/"/' filenames.txt
$ sed -i 's/$/"/' filenames.txt

[/os/unix/commands] permanent link

Tue, May 18, 2010 4:17 pm

Id Command

If you need to determine your user identifier (uid) and group identifer (gid) on a Unix or Linux system, you can use the id command.

[/os/unix/commands] permanent link

Fri, Mar 06, 2009 5:57 pm

Group Membership Under Unix/Linux

To see the groups to which an account belongs, you can use the command groups

# groups jsmith
staff code210

To place an account in an additional group, you can use the command usermod --groups newgroup account.

# usermod jsmith programmers

References:

  1. Managing Group Access on Linux and Unix

[/os/unix/commands] permanent link

Fri, Nov 30, 2007 11:00 pm

Mounting a Dirty NTFS Volume

If you try to mount an NTFS volume on Linux that was used on a Windows system and get the message below, then Windows was not shut down properly. E.g. the system may have crashed or there was a power failure.
$LogFile indicates unclean shutdown (0, 0)
Failed to mount '/dev/sda1': Operation not supported
Mount is denied because NTFS is marked to be in use. Choose one action:

Choice 1: If you have Windows then disconnect the external devices by
          clicking on the 'Safely Remove Hardware' icon in the Windows
          taskbar then shutdown Windows cleanly.

Choice 2: If you don't have Windows then you can use the 'force' option for
          your own responsibility. For example type on the command line:

            mount -t ntfs-3g /dev/sda1 /mnt/hdd -o force

    Or add the option to the relevant row in the /etc/fstab file:

            /dev/sda1 /mnt/hdd ntfs-3g defaults,force 0 0
Presuming the volume is /dev/sda1 and you want to mount it at /mnt/hdd, you can mount the volume read-only with mount -r /dev/sda1 /mnt/hdd. Or you can force a mount in read-write mode with mount /dev/sda1 /mnt/hdd -o force. But it might be best to run Windows chkdsk or a utility with similar functionality first, since the fact that the dirty bit is set could indicate corruption to the volume's file structure.

[/os/unix/commands/mount] permanent link

Fri, Aug 10, 2007 9:01 pm

mii-tool

If you want to know the speed at which a system has connected to the LAN, e.g. the system can autonegotiate its speed and you need to know which speed it is using, you can use the mii-tool command to check the status of Ethernet devices in the system.

# mii-tool
eth0: no autonegotiation, 10baseT-HD, link ok

From the above output from the command on a Linux system, I can see that the Ethernet device, eth0, is not using autonegotiation to determine its speed and is set to 10 Mbs half duplex.

If you want more details for Ethernet devices in the system, you can use -v or --verbose as a parameter to the command.

# mii-tool -v
eth0: no autonegotiation, 10baseT-HD, link ok
  product info: vendor 00:10:18, model 23 rev 7
  basic mode:   autonegotiation enabled
  basic status: autonegotiation complete, link ok
  capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
  advertising:  100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control

From the above, I can see that eth0, though it is set for a 10baseT connection, i.e. 10 Mbs, can support a 100baseTx, i.e. 100 Mbs, connection.

The device is capable of the following port speeds:

Port SpeedDescription
10baseT-HD 10 megabits/s half duplex
10baseT-FD 10 megabits/s full duplex
100baseTx-HD 100 megabits/s half duplex
100baseTx-FD 100 megabits/s full duplex

mii-tool manpage

References:

  1. B.5. mii-tool
    Guide to IP Layer Network Administration with Linux

[/os/unix/commands] permanent link

Wed, Jun 06, 2007 9:03 pm

Backing Up a Specific Filetype with Tar

To backup a specific filetype, e.g. all PHP files in the current directory and all subdirectories beneath it, you can use the following command:

tar -cvf example.tar $(find . -name "*.php")

The find command will find all of the PHP files and pass them to the tar command. You can see that all of the PHP files are in the tar backup file, example.tar with the command below:

tar -tvf example.tar

You can add HTML files to the backup using the -u option for tar to update the archive file as below:

tar -uvf example.tar $(find . -name "*.html")

References:

  1. tar find ssh
    May 2004
    Computing.Net

[/os/unix/commands] permanent link

Sun, Apr 15, 2007 4:53 pm

Stopping an Attacker with the Route Reject Command

You can use KRIPP to monitor FTP dictionary attacks where an attacker tries to guess a userid and password combination to break into an FTP server. You can block the attacking system with the route command, e.g. route add 202.123.213.3 reject to block all packets from 202.123.213.3. When the attacker has moved on to other targets, you can remove the routing table entry with route del 202.123.213.3 reject.

[ More Info ]

[/os/unix/commands] permanent link

Sat, Mar 10, 2007 10:09 pm

Finding a String with a Recursive Grep

If you need to find a specific string in all files of a particular type in the current directory and all directories beneath it, you can use a command similar to the following:


find . -name "*.php" -exec grep "noindex" {} /dev/null \;

In this case I want to find all of the PHP files where I have included the string "noindex" in a META tag.

References:

  1. Greg Hinkel's UNIX Tip of the Week for March 3, 1996

[/os/unix/commands] permanent link

CompuVest - Notebooks

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo