Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Linux Networking Commands


Published on

Linux/Unix Networking Commands

Published in: Technology
  • Great commentary , Coincidentally , if your business requires a NJ CN 10483 , my family saw a template document here
    Are you sure you want to  Yes  No
    Your message goes here

Linux Networking Commands

  1. 1. Linux Networking Commands Copyright, 2002 © NTM Consulting Inc. TCP/IP Lecture Series Professor Tom Mavroidis
  2. 2. Commands Reviewed Ifconfig dmesg netstat ping route traceroute nslookup arp dig
  3. 3. ifconfig <ul><li>ifconfig is used to assign an address to a network interface and/or configure network interface parameters. ifconfig must be used at boot time to define the network address of each interface present on a machine; it may also be used at a later time to redefine an interface's address or other operating parameters. </li></ul>
  4. 4. ifconfig eth0 <ul><li>eth0 Link encap:Ethernet HWaddr 00:04:AC:16:54:4C </li></ul><ul><li>inet addr: Bcast: Mask: </li></ul><ul><li>inet6 addr: fe80::204:acff:fe16:544c/10 Scope:Link </li></ul><ul><li>UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 </li></ul><ul><li>RX packets:116242 errors:0 dropped:0 overruns:0 frame:0 </li></ul><ul><li>TX packets:123380 errors:0 dropped:0 overruns:0 carrier:0 </li></ul><ul><li>collisions:9052 </li></ul><ul><li>RX bytes:39103579 (37.2 Mb) TX bytes:106270739 (101.3 Mb) </li></ul>
  5. 5. When would you use ifconfig? <ul><li>To determine if an interface has been recognized and configured on a system </li></ul><ul><li>To initially assign an IP address to an interface </li></ul><ul><li>to bring an interface up or down </li></ul>
  6. 6. What should you do if the interface isn’t found? <ul><li>This kind of problem usually appears on initial setup of a machine </li></ul><ul><li>[root@localhost root]# ifconfig eth3 up </li></ul><ul><li>eth3: unknown interface: No such device </li></ul>
  7. 7. See if the device has been found - use dmesg <ul><li>The command 'dmesg', which is used to print kernel messages, is very useful in determining if a piece of hardware has been found, and if so, what the system is referring to it as. </li></ul><ul><li>Don’t forger to monitor the /var/log/messages file for any strange activity. </li></ul>TIP pipe the dmesg to the less command or the reply will scroll off the screen dmesg | less
  8. 8. Before you have a useable interface <ul><li>Determine if you can ping the localhost </li></ul><ul><li>ping localhost or </li></ul><ul><li>ping </li></ul>
  9. 9. Does the localhost respond? <ul><li>[root@localhost root]# ping localhost </li></ul><ul><li>PING localhost.localdomain ( from : 56(84) bytes of data. </li></ul><ul><li>64 bytes from localhost.localdomain ( icmp_seq=0 ttl=255 time=1.968 msec </li></ul><ul><li>64 bytes from localhost.localdomain ( icmp_seq=1 ttl=255 time=113 usec </li></ul><ul><li>64 bytes from localhost.localdomain ( icmp_seq=2 ttl=255 time=178 usec </li></ul><ul><li>64 bytes from localhost.localdomain ( icmp_seq=3 ttl=255 time=116 usec </li></ul>
  10. 10. Confirm you have set up the interface correctly. <ul><li>ping the address returned by the ifconfig command “Ping” </li></ul>eth0 Link encap:Ethernet HWaddr 00:04:AC:16:54:4C inet addr: Bcast: Mask: inet6 addr: fe80::204:acff:fe16:544c/10 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:116242 errors:0 dropped:0 overruns:0 frame:0 TX packets:123380 errors:0 dropped:0 overruns:0 carrier:0 collisions:9052 RX bytes:39103579 (37.2 Mb) TX bytes:106270739 (101.3 Mb)
  11. 11. ping <ul><li>System administration command. Confirm that a remote host is online and responding. ping is intended for use in network testing, measurement, and management. Because of the load it can impose on the network, it is unwise to use ping during normal operations or from automated scripts. </li></ul>
  12. 12. route <ul><li>Gateways route data between networks </li></ul><ul><li>All devices make routing decisions </li></ul><ul><ul><li>local network? Deliver to destination </li></ul></ul><ul><ul><li>remote network? Forward to local gateway </li></ul></ul>
  13. 13. route -n <ul><li>-n prevents route from converting IP addresses to hostnames </li></ul><ul><li>the entry is the default gateway </li></ul>[root@localhost root]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface U 0 0 0 eth0 U 0 0 0 eth1 U 0 0 0 lo UG 0 0 0 eth1
  14. 14. route -Cn (display cache table) <ul><li>[root@localhost root]# route -Cn </li></ul><ul><li>Kernel IP routing cache </li></ul><ul><li>Source Destination Gateway Flags Metric Ref Use Iface </li></ul><ul><li> il 0 0 65 lo </li></ul><ul><li> 0 1 0 eth0 </li></ul><ul><li> 0 0 0 eth1 </li></ul><ul><li> 0 0 1 eth1 </li></ul><ul><li> 0 1 0 eth1 </li></ul><ul><li> l 0 0 3 lo </li></ul><ul><li> ibl 0 0 4 lo </li></ul><ul><li> l 0 0 1 lo </li></ul>
  15. 15. traceroute <ul><li>Trace route taken by packets to reach network host. traceroute attempts tracing by launching UDP probe packets with a small TTL (time to live), then listening for an ICMP &quot;time exceeded&quot; reply from a gateway. host is the destination hostname or the IP number of host to reach. packetsize is the packet size in bytes of the probe datagram. Default is 38 bytes. </li></ul>Note Traceroute has lost some of its effectiveness since most ISP’s disallow it from running on their networks
  16. 16. nslookup <ul><li>Query Internet domain name servers. nslookup has two modes: interactive and noninteractive. Interactive mode allows the user to query name servers for information about various hosts and domains or to print a list of hosts in a domain. It is entered either when no arguments are given (default name server will be used) or when the first argument is a hyphen and the second argument is the hostname or Internet address of a name server. Noninteractive mode is used to print just the name and requested information for a host or domain. It is used when the name of the host to be looked up is given as the first argument. Any of the keyword = value pairs listed under the interactive set command can be used as an option on the command line by prefacing the keyword with a -. The optional second argument specifies a name server. </li></ul>
  17. 17. arp <ul><li>Physical networks have their own addressing scheme </li></ul><ul><li>IP addresses are used to direct a datagram to a specific physical network </li></ul>
  18. 18. arp table <ul><li>arp maintains a table of translations between IP addresses and ethernet addresses </li></ul><ul><li>[root@localhost root]# arp </li></ul><ul><li>Address HWtype HWaddress Flags Mask Iface </li></ul><ul><li> ether 00:04:5A:DB:A1:C5 C eth1 </li></ul><ul><li> ether 00:10:E0:04:61:84 C eth0 </li></ul><ul><li> ether 00:09:B7:13:AA:13 C eth1 </li></ul>
  19. 19. /etc/hosts <ul><li>Setting the hosts file will resolve names to addresses </li></ul>[root@localhost root]# less /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail. localhost.localdomain localhost
  20. 20. arp -a will then resolve <ul><li>Instead of just names, you also get IP addresses </li></ul><ul><li>[root@localhost root]# arp -a </li></ul><ul><li> ( at 00:04:5A:DB:A1:C5 [ether] on eth1 </li></ul><ul><li> ( at 00:10:E0:04:61:84 [ether] on eth0 </li></ul><ul><li> ( at 00:09:B7:13:AA:13 [ether] on eth1 </li></ul>
  21. 21. netstat <ul><li>The netstat command symbolically displays the contents of various net- work-related data structures. There are a number of output formats, de- pending on the options for the information presented. The first form of the command displays a list of active sockets for each protocol. The second form presents the contents of one of the other network data struc- tures according to the option selected. Using the third form, with a wait interval specified, netstat will continuously display the informa- tion regarding packet traffic on the configured network interfaces. The fourth form displays statistics about the named protocol. </li></ul>
  22. 22. netstat -nr <ul><li>[root@localhost root]# netstat -nr </li></ul><ul><li>Kernel IP routing table </li></ul><ul><li>Destination Gateway Genmask Flags MSS Window irtt Iface </li></ul><ul><li> U 40 0 0 eth0 </li></ul><ul><li> U 40 0 0 eth1 </li></ul><ul><li> U 40 0 0 lo </li></ul><ul><li> UG 40 0 0 eth1 </li></ul>
  23. 23. dig - supercharged nslookup <ul><li>oroot@localhost root]# dig </li></ul><ul><li>; <<>> DiG 9.1.3 <<>> </li></ul><ul><li>;; global options: printcmd </li></ul><ul><li>;; Got answer: </li></ul><ul><li>;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10483 </li></ul><ul><li>;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 6, ADDITIONAL: 4 </li></ul><ul><li>;; QUESTION SECTION: </li></ul><ul><li>; IN A </li></ul><ul><li>;; ANSWER SECTION: </li></ul><ul><li> 86400 IN A </li></ul>
  24. 24. dig - better than nslookup <ul><li>;; AUTHORITY SECTION: </li></ul><ul><li> 86400 IN NS </li></ul><ul><li> 86400 IN NS </li></ul><ul><li> 86400 IN NS </li></ul><ul><li> 86400 IN NS </li></ul><ul><li> 86400 IN NS </li></ul><ul><li> 86400 IN NS </li></ul><ul><li>;; ADDITIONAL SECTION: </li></ul><ul><li> 86400 IN A </li></ul><ul><li> 86400 IN A </li></ul><ul><li> 86400 IN A </li></ul><ul><li> 86400 IN A </li></ul><ul><li>;; Query time: 2202 msec </li></ul><ul><li>;; SERVER: </li></ul><ul><li>;; WHEN: Sun Sep 29 16:38:20 2002 </li></ul><ul><li>;; MSG SIZE rcvd: 238 </li></ul>
  25. 25. References <ul><li>For detailed syntax on these and other linux commands look at </li></ul><ul><li>http://www. oreillynet .com/ linux / cmd / </li></ul>