Linux Networking Basic Commands

Embed Size (px)

Citation preview

  • 7/29/2019 Linux Networking Basic Commands

    1/8

    Linux Important Commands Basic plus Networking

    Files and Directories Management ls Lists files and directories content, I usually use ls -la to have a long listing with all the details and hidden

    files

    cd move from the current directory to a different folder

    pwd lists your current location

    mv this command can either change the name of a file, or move it to a different location.

    locate find any file on the Linux server, to get an updated index of files (if for example you just installed awhole bunch of RPMs) run the commandupdatedb

    ln create a shortcut to a file or folder

    tar create or extract files out of a storage file. with the correct arguments it will also compress the files

    Editing and Viewing tail lists the last 10 lines of a file, but you tell tell it to show any number of last lines

    vi the best command line editing software a little hard to learn how to work this one at first, buts its worth theeffort

    cat list the content of the file. better know how long is the file you are running this command on, or you will get

    a very long scrolling of lines that will fill up your screen

    A Very Good Linux Administration BookNetwork

    nslookup very important networking tool this will show you where a DNS name is pointing to which IP or toanother DNS

    wget get a file from the web from the command line if you need to download some RPM directly to thecommand line without a browser, this is the command you need

    ping I think its one of the most used commands, you can check the time it takes you to get via the network toa remote server, whether that server is available, how many packets are getting to the server, etc

    Installing linux on ps3

    General history lists the last used commands on your Linux server

    make when compiling a software from source, this command will create the binaries

    id who am I right now? besides the philosophical angle, this command will show you as which user you will berunning commands, I use this to check what is my status, and then sudo to the user I need

    sudo execute a command as another user although usually use it to change to root

    ps list the running processes on the server, it give more info like the process id, the parent process id, runningtime and much more

    man displays a manual page, whenever you are not sure about a specific command or config file, you shouldrun man command to get info about it. to search the man database use whatis command to find which manfile has the info you need

    df report file system disk space usage, use df -h to get a human formatted listing

    1. For anyone whos interested in seeing their own top twenty you can run the following:cat ~/.bash_history | tr \|\;\& \n | sed -e s/^ //g | cut -d -f 1 | sort | uniq -c | sort -n | tail -n 20Its not perfect but will give you a rough idea.On my own computer I get:timp@shammah:~$ cat ~/.bash_history | tr \|\;\& \n | sed -e s/^ //g | cut -d -f 1 | sort | uniq -c | sort -n | tail -n 208 dig8 fbsetbg8 make9 cvs10 do10 done10 for11 pwsafe11 wget12 rm

    http://yonitg.com/linux-commands/ls/http://yonitg.com/linux-commands/cd/http://yonitg.com/linux-commands/cd/http://yonitg.com/linux-commands/pwd/http://yonitg.com/linux-commands/pwd/http://yonitg.com/linux-commands/mv/http://yonitg.com/linux-commands/mv/http://yonitg.com/linux-commands/locate/http://yonitg.com/linux-commands/locate/http://yonitg.com/linux-commands/updatedb/http://yonitg.com/linux-commands/updatedb/http://yonitg.com/linux-commands/ln/http://yonitg.com/linux-commands/ln/http://yonitg.com/linux-commands/tar/http://yonitg.com/linux-commands/tar/http://cc019iwdsjemas9e1xr9r9omcu.hop.clickbank.net/?tid=LINTO20http://yonitg.com/linux-commands/ls/http://yonitg.com/linux-commands/cd/http://yonitg.com/linux-commands/pwd/http://yonitg.com/linux-commands/mv/http://yonitg.com/linux-commands/locate/http://yonitg.com/linux-commands/updatedb/http://yonitg.com/linux-commands/ln/http://yonitg.com/linux-commands/tar/http://cc019iwdsjemas9e1xr9r9omcu.hop.clickbank.net/?tid=LINTO20
  • 7/29/2019 Linux Networking Basic Commands

    2/8

    13 ./test.sh13 vim15 cat15 svnadmin16 grep19 su25 ssh55 svn

    83 ls96 cdA couple of things of note:dig is similar to nslookupYou can also see that I often work with version control: svn, svnadmin, and cvs; I like VIm over vi; I use ssh a lot; and thatits not unusual for me to use Bashs builtin for loops (do, done, and for)

    10 Most important Linux networking commands

    Linux is most powerful operating system which often needs to usecommandsto explore it effectively.Some of the commands are restrictedto normal user groups as they are powerful and has more functionality involved in it.Here we summarized most interesting and useful networkingcommands which every linux user are supposed to be familiar with it.

    1.Arp manipulates the kernels ARP cache in various ways. The primary options are clearing an address mapping entry and manuallysetting up one. For debugging purposes, the arp program also allows a complete dump of the ARP cache.ARP displays the IP address assigned toparticular ETH card and mac address

    [fasil@smashtech ]# arpAddress HWtype HWaddress Flags Mask Iface59.36.13.1 ether C eth0

    2.Ifconfig is used to configure the network interfaces. Normally we use this command to check the IP address assigned to thesystem.It is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning isneeded.

    [fasil@smashtech ~]# /sbin/ifconfig

    eth0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:126341 errors:0 dropped:0 overruns:0 frame:0TX packets:44441 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000

    3. Netstat prints information about the networking subsystem. The type of information which is usually printed by netstat arePrint network connections, routing tables, interface statistics, masquerade connections, and multicast.

    [fasil@smashtech ~]# netstatActive Internet connections (w/o servers)Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 .230.87:https ESTABLISHEDActive UNIX domain sockets (w/o servers)Proto RefCnt Flags Type State I-Node Pathunix 10 [ ] DGRAM 4970 /dev/logunix 2 [ ] DGRAM 6625 @/var/run/hal/hotplug_socketunix 2 [ ] DGRAM 2952 @udevdunix 2 [ ] DGRAM 100564unix 3 [ ] STREAM CONNECTED 62438 /tmp/.X11-unix/X0

    unix 3 [ ] STREAM CONNECTED 62437unix 3 [ ] STREAM CONNECTED 10271 @/tmp/fam-root-unix 3 [ ] STREAM CONNECTED 10270unix 3 [ ] STREAM CONNECTED 9276unix 3 [ ] STREAM CONNECTED 9275

    4.ping command is used to check the connectivity of a system to a network.Whenever there is problem in network connectivity we useping to ensure the system is connected to network.

    http://smashtech.blogspot.com/2008/08/linux-commands-hardware-informations.htmlhttp://smashtech.blogspot.com/2008/08/linux-commands-hardware-informations.htmlhttp://smashtech.blogspot.com/2008/08/linux-commands-hardware-informations.htmlhttp://4.bp.blogspot.com/_wozY1BGgOmM/SbPLoQ5F1ZI/AAAAAAAAAv4/O9nQZg1oiio/s1600-h/board.pnghttp://smashtech.blogspot.com/2008/08/linux-commands-hardware-informations.html
  • 7/29/2019 Linux Networking Basic Commands

    3/8

    [root@smashtech ~]# ping google.comPING google.com (74.125.45.100) 56(84) bytes of data.64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=0 ttl=241 time=295 ms64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=1 ttl=241 time=277 ms64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=2 ttl=241 time=277 ms

    --- google.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, t ime 6332msrtt min/avg/max/mdev = 277.041/283.387/295.903/8.860 ms, pipe 2

    5.Nslookup is a program to query Internet domain name servers. Nslookup has two modes:interactive and non-interactive. Interactive mode allows the user to query name servers for information aboutvarious hosts and domains or to print a list of hosts in a domain. Non-interactive mode is used to print justthe name and requested information for a host or domain.

    [fasil@smashtech ~]# nslookup google.comServer: server ipAddress: gateway ip 3

    Non-authoritative answer:Name: google.comAddress: 209.85.171.100Name: google.comAddress: 74.125.45.100Name: google.comAddress: 74.125.67.100

    6. dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performsDNS lookups and displays the answers that are returned from the name server(s) that were queried. MostDNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarityof output. Other lookup tools tend to have less functionality than dig.

    [fasil@smashtech ~]# dig google.com

    ; DiG 9.2.4 google.com

    ;; global options: printcmd;; Got answer:;; ->>HEADER

  • 7/29/2019 Linux Networking Basic Commands

    4/8

    ;; SERVER: 172.29.36.1#53(172.29.36.1);; WHEN: Thu Mar 5 14:38:45 2009;; MSG SIZE rcvd: 212

    7.Route/route print manipulates the IP routing tables. Its primary use is to set upstatic routes to specific hosts or networks via an interface after it has been configured with the ifconfigprogram.When the add or del options are used, route modifies the routing tables. Without these options,route displays the current contents of the routing tables.

    [fasil@smashtech ~]# routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface54.192.56.321 * 255.255.255.0 U 0 0 0 eth0

    * 255.255.0.0 U 0 0 0 eth0default 0.0.0.0 UG 0 0 0 eth0

    8.Traceroute:

    Internet is a large and complex aggregation of network hardware, connectedtogether by gateways. Tracking the route ones packets follow (or finding the miscreant gateway thatsdiscarding your packets) can be difficult.

    Traceroute utilizes the IP protocol time to live field and attempts to elicit an ICMP TIME_EXCEEDEDresponse from each gateway along the path to some host. The only mandatory parameter is the destinationhost name or IP number. The default probe datagram length is 40 bytes, but this may be increased byspecifying a packet length (in bytes) after the destination host name.

    [fasil@smashtech ~]# traceroute google.comtraceroute: Warning: google.com has multiple addresses; using 209.85.171.100traceroute to google.com (209.85.171.100), 30 hops max, 38 byte packets1 * * *

    9.W-displays information about the users currently on the machine, and their processes. The headershows, in this order, the current time, how long the system has been running, how many users arecurrently logged on, and the system load averages for the past 1, 5, and 15 minutes.

    [fasil@smashtechl ~]# w15:18:22 up 4:38, 3 users, load average: 0.89, 0.34, 0.19

    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATroot :0 - 10:41 ?xdm? 24:53 1.35s /usr/bin/gnome-sessionroot pts/1 :0.0 10:58 1.00s 0.34s 0.00s wroot pts/2 :0.0 12:10 23:32 0.03s 0.03s bash

    10. Nmap is designed to allow system administrators and curious individuals to scan largenetworks to determine which hosts are up and what services they are offering. nmap supports a large

    number of scanning techniques such as:UDP, TCP connect(), TCP SYN (half open), ftp proxy (bounceattack), ICMP (ping sweep), FIN, ACK sweep, Xmas Tree,SYN sweep, IP Protocol, and Null scan. See theScan Types section for more details. nmap also offers a number of advanced features such as remoteOS detection via TCP/IP fingerprinting, stealth scanning, dynamic delay and retransmission calculations,parallel scanning, detection of down hosts via parallel pings, decoy scanning, port filtering detection,direct (non-portmapper) RPC scanning, fragmentation scanning, and flexible target and port specification.

    Significant effort has been put into decent nmap performance for non-root users. Unfortunately, manycritical kernel interfaces (such as raw sockets) require root privileges. nmap should be run as rootwhenever possible (not setuid root, of course).

    The result of running nmap is usually a list of interesting ports on the machine(s) being scanned (ifany). Nmap always gives the ports "well known" service name (if any), number, state, and protocol.

  • 7/29/2019 Linux Networking Basic Commands

    5/8

    The state is either"open", "filtered", or "unfiltered". Open means that the target machine will accept()connections on that port.Filtered means that a firewall, filter, or other network obstacle is covering theport and preventing nmap from determining whether the port is open. Unfiltered means that the port isknown by nmap to be closed and no fire-wall/filter seems to be interfering with nmaps attempts todetermine this. Unfiltered ports are the common case and are only shown when most of the scanned portsare in the filtered state.

    Depending on options used, nmap may also report the following characteristics of the remote host: OS

    in use, TCP sequentiality, usernames running the programs which have bound to each port, the DNSname, whether the host is a smurf address, and a few other--Network exploration tool and securityscanners.

    ************************************************************************

    How to check the version of a Linux OS and Hardware name

    uname a is a linux command that will output useful information about your linuxdistribution, kernel version, cpu information and more

    Example Output

    Linux computerName 2.6.22.18-desktop-1mdv #1 SMP Mon Feb 11 13:53:50 EST 2008i686 Intel(R) Pentium(R) 4 CPU 3.40GHz GNU/Linux

    To check Just OS version

    $ cat /proc/version$ CYGWIN_NT-5.1 1.8.3(0.237/5/3) 2011-07-20 21:35Or$Uname r

    CYGWIN_NT-5.1 qasim-e37a201c8 1.8.3(0.237/5/3) 2011-07-20 21:35 i686 Cygwin

    $uname -aCYGWIN_NT-5.1 qasim-e37a201c8 1.8.3(0.237/5/3) 2011-07-20 21:35 i686 Cygwin

    For red hat OS

    cat /etc/redhat-release

    To check routing table in Linux

    $ netstat rn (route print command is also used)

    To check hard disk spaceUse df command to report file system disk space usage (parition wise):

    $ df H

    Arp (address resolution protocol):

  • 7/29/2019 Linux Networking Basic Commands

    6/8

    Show all lan ips plus mac addresses (only display that ipwhich u have used recently(ping))

    Nmap very important command

    The following command will display all IPs from 1 to 10 in localdomain.

    Other important nmap options

    $nmap sV [ip]$nmap sT [ip]$nmap PN [ip] (incase simple nmap not work)

  • 7/29/2019 Linux Networking Basic Commands

    7/8

  • 7/29/2019 Linux Networking Basic Commands

    8/8