linux networking commands

Post on 14-May-2015

4.143 Views

Category:

Technology

42 Downloads

Preview:

Click to see full reader

DESCRIPTION

Linux/Unix Networking Commands

TRANSCRIPT

Linux Networking Linux Networking CommandsCommands

Copyright, 2002 © NTM Consulting Inc.

TCP/IP Lecture Series

Professor Tom Mavroidis

Commands ReviewedCommands Reviewed

Ifconfigdmesgnetstatpingroutetraceroutenslookuparpdig

ifconfigifconfig

• 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.

ifconfig eth0 ifconfig eth0

• eth0 Link encap:Ethernet HWaddr 00:04:AC:16:54:4C eth0 Link encap:Ethernet HWaddr 00:04:AC:16:54:4C

• inet addr:192.168.2.1 Bcast:192.168.2.255 inet addr:192.168.2.1 Bcast:192.168.2.255 Mask:255.255.255.0Mask:255.255.255.0

• inet6 addr: fe80::204:acff:fe16:544c/10 Scope:Linkinet6 addr: fe80::204:acff:fe16:544c/10 Scope:Link

• UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

• RX packets:116242 errors:0 dropped:0 overruns:0 frame:0RX packets:116242 errors:0 dropped:0 overruns:0 frame:0

• TX packets:123380 errors:0 dropped:0 overruns:0 carrier:0TX packets:123380 errors:0 dropped:0 overruns:0 carrier:0

• collisions:9052 collisions:9052

• RX bytes:39103579 (37.2 Mb) TX bytes:106270739 (101.3 RX bytes:39103579 (37.2 Mb) TX bytes:106270739 (101.3 Mb)Mb)

When would you use When would you use ifconfig?ifconfig?

• To determine if an interface has To determine if an interface has been recognized and configured on been recognized and configured on a system a system

• To initially assign an IP address to To initially assign an IP address to an interfacean interface

• to bring an interface up or downto bring an interface up or down

What should you do if the What should you do if the interface isn’t found?interface isn’t found?

• This kind of problem usually This kind of problem usually appears on initial setup of a appears on initial setup of a machinemachine

• [root@localhost root]# ifconfig eth3 up[root@localhost root]# ifconfig eth3 up

• eth3: unknown interface: No such deviceeth3: unknown interface: No such device

See if the device has been See if the device has been found - use dmesgfound - use dmesg

• 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.

• Don’t forger to monitor the /var/log/messages file for any

strange activity.

TIP pipe the dmesg to the less command or the reply will scroll off the screen

dmesg | less

Before you have a useable Before you have a useable interface interface

• Determine if you can ping the Determine if you can ping the localhostlocalhost

• ping localhost orping localhost or

• ping 127.0.0.1ping 127.0.0.1

Does the localhost Does the localhost respond?respond?

• [root@localhost root]# ping localhost[root@localhost root]# ping localhost

• PING localhost.localdomain (127.0.0.1) from 127.0.0.1 : 56(84) bytes PING localhost.localdomain (127.0.0.1) from 127.0.0.1 : 56(84) bytes of data.of data.

• 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=0 ttl=255 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=0 ttl=255 time=1.968 msectime=1.968 msec

• 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=255 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=255 time=113 usectime=113 usec

• 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=2 ttl=255 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=2 ttl=255 time=178 usectime=178 usec

• 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=3 ttl=255 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=3 ttl=255 time=116 usectime=116 usec

Confirm you have set up Confirm you have set up the interface correctly.the interface correctly.

• ping the address returned by the ping the address returned by the ifconfig command “Ping ifconfig command “Ping 192.168.2.1”192.168.2.1”

eth0 Link encap:Ethernet HWaddr 00:04:AC:16:54:4C inet addr:192.168.2.1 Bcast:192.168.2.255 Mask:255.255.255.0 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)

pingping

• 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.

routeroute

• Gateways route data between Gateways route data between networksnetworks

• All devices make routing decisionsAll devices make routing decisions– local network? Deliver to destinationlocal network? Deliver to destination

– remote network? Forward to local remote network? Forward to local gatewaygateway

route -nroute -n

• -n prevents route from converting IP -n prevents route from converting IP addresses to hostnamesaddresses to hostnames

• the 0.0.0.0 entry is the default the 0.0.0.0 entry is the default gateway gateway [root@localhost root]# route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth1

route -Cn (display cache route -Cn (display cache table)table)

• [root@localhost root]# route -Cn[root@localhost root]# route -Cn

• Kernel IP routing cacheKernel IP routing cache

• Source Destination Gateway Flags Metric Ref Use Source Destination Gateway Flags Metric Ref Use IfaceIface

• 192.168.1.101 192.168.1.55 192.168.1.55 il 0 0 65 lo192.168.1.101 192.168.1.55 192.168.1.55 il 0 0 65 lo

• 192.168.2.1 192.168.2.75 192.168.2.75 0 1 0 eth0192.168.2.1 192.168.2.75 192.168.2.75 0 1 0 eth0

• 192.168.1.55 192.175.48.42 192.168.1.1 0 0 0 eth1192.168.1.55 192.175.48.42 192.168.1.1 0 0 0 eth1

• 192.168.1.55 192.168.1.101 192.168.1.101 0 0 1 eth1192.168.1.55 192.168.1.101 192.168.1.101 0 0 1 eth1

• 192.168.1.55 192.168.1.101 192.168.1.101 0 1 0 eth1192.168.1.55 192.168.1.101 192.168.1.101 0 1 0 eth1

• 127.0.0.1 127.0.0.1 127.0.0.1 l 0 0 3 lo127.0.0.1 127.0.0.1 127.0.0.1 l 0 0 3 lo

• 192.168.1.101 192.168.1.255 192.168.1.255 ibl 0 0 4 lo192.168.1.101 192.168.1.255 192.168.1.255 ibl 0 0 4 lo

• 127.0.0.1 127.0.0.1 127.0.0.1 l 0 0 1 lo127.0.0.1 127.0.0.1 127.0.0.1 l 0 0 1 lo

traceroutetraceroute

• 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 "time exceeded" 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.

Note Traceroute has lost some of its effectiveness since most

ISP’s disallow it from running on their networks

nslookupnslookup

• 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.

arparp

• Physical networks have their own Physical networks have their own addressing schemeaddressing scheme

• IP addresses are used to direct a IP addresses are used to direct a datagram to a specific physical datagram to a specific physical networknetwork

arp tablearp table

• arp maintains a table of translations arp maintains a table of translations between IP addresses and ethernet between IP addresses and ethernet addressesaddresses

• [root@localhost root]# arp[root@localhost root]# arp

• Address HWtype HWaddress Flags Mask IfaceAddress HWtype HWaddress Flags Mask Iface

• 192.168.1.1 ether 00:04:5A:DB:A1:C5 C eth1192.168.1.1 ether 00:04:5A:DB:A1:C5 C eth1

• 192.168.2.75 ether 00:10:E0:04:61:84 C eth0192.168.2.75 ether 00:10:E0:04:61:84 C eth0

• 192.168.1.101 ether 00:09:B7:13:AA:13 C eth1192.168.1.101 ether 00:09:B7:13:AA:13 C eth1

/etc/hosts/etc/hosts

• Setting the hosts file will resolve Setting the hosts file will resolve names to addressesnames to addresses

[root@localhost root]# less /etc/hosts# Do not remove the following line, or various programs# that require network functionality will fail.127.0.0.1 localhost.localdomain localhost192.168.1.1 gatewayout.tcp-ip.ca192.168.2.75 basement.tcp-ip.ca192.168.1.101 just_a_node.tcp-ip.ca

arp -a will then resolvearp -a will then resolve

• Instead of just names, you also get IP addressesInstead of just names, you also get IP addresses

• [root@localhost root]# arp -a[root@localhost root]# arp -a

• gatewayout.tcp-ip.ca (192.168.1.1) at 00:04:5A:DB:A1:C5 [ether] on eth1gatewayout.tcp-ip.ca (192.168.1.1) at 00:04:5A:DB:A1:C5 [ether] on eth1

• basement.tcp-ip.ca (192.168.2.75) at 00:10:E0:04:61:84 [ether] on eth0basement.tcp-ip.ca (192.168.2.75) at 00:10:E0:04:61:84 [ether] on eth0

• just_a_node.tcp-ip.ca (192.168.1.101) at 00:09:B7:13:AA:13 [ether] on eth1just_a_node.tcp-ip.ca (192.168.1.101) at 00:09:B7:13:AA:13 [ether] on eth1

netstatnetstat

• 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.

netstat -nrnetstat -nr

• [root@localhost root]# netstat -nr[root@localhost root]# netstat -nr

• Kernel IP routing tableKernel IP routing table

• Destination Gateway Genmask Flags MSS Window Destination Gateway Genmask Flags MSS Window irtt Ifaceirtt Iface

• 192.168.2.0 0.0.0.0 255.255.255.0 U 40 0 0 192.168.2.0 0.0.0.0 255.255.255.0 U 40 0 0 eth0eth0

• 192.168.1.0 0.0.0.0 255.255.255.0 U 40 0 0 192.168.1.0 0.0.0.0 255.255.255.0 U 40 0 0 eth1eth1

• 127.0.0.0 0.0.0.0 255.0.0.0 U 40 0 0 lo127.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 eth10.0.0.0 192.168.1.1 0.0.0.0 UG 40 0 0 eth1

dig - supercharged dig - supercharged nslookupnslookup

• oroot@localhost root]# dig cs.senecac.on.caoroot@localhost root]# dig cs.senecac.on.ca

• ; <<>> DiG 9.1.3 <<>> cs.senecac.on.ca; <<>> DiG 9.1.3 <<>> cs.senecac.on.ca

• ;; global options: printcmd;; global options: printcmd

• ;; Got answer:;; Got answer:

• ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10483;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10483

• ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 6, ADDITIONAL: 4;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 6, ADDITIONAL: 4

• ;; QUESTION SECTION:;; QUESTION SECTION:

• ;cs.senecac.on.ca. IN A;cs.senecac.on.ca. IN A

• ;; ANSWER SECTION:;; ANSWER SECTION:

• cs.senecac.on.ca. 86400 IN A 142.204.57.48cs.senecac.on.ca. 86400 IN A 142.204.57.48

dig - better than nslookupdig - better than nslookup

• ;; AUTHORITY SECTION:;; AUTHORITY SECTION:

• senecac.on.ca. 86400 IN NS ns.onet.on.ca.senecac.on.ca. 86400 IN NS ns.onet.on.ca.

• senecac.on.ca. 86400 IN NS ns2.senecac.on.ca.senecac.on.ca. 86400 IN NS ns2.senecac.on.ca.

• senecac.on.ca. 86400 IN NS hades.senecac.on.ca.senecac.on.ca. 86400 IN NS hades.senecac.on.ca.

• senecac.on.ca. 86400 IN NS ittads.senecac.on.ca.senecac.on.ca. 86400 IN NS ittads.senecac.on.ca.

• senecac.on.ca. 86400 IN NS pulsar.senecac.on.ca.senecac.on.ca. 86400 IN NS pulsar.senecac.on.ca.

• senecac.on.ca. 86400 IN NS nsprime.senecac.on.ca.senecac.on.ca. 86400 IN NS nsprime.senecac.on.ca.

• ;; ADDITIONAL SECTION:;; ADDITIONAL SECTION:

• ns2.senecac.on.ca. 86400 IN A 142.204.10.100ns2.senecac.on.ca. 86400 IN A 142.204.10.100

• hades.senecac.on.ca. 86400 IN A 142.204.57.15hades.senecac.on.ca. 86400 IN A 142.204.57.15

• ittads.senecac.on.ca. 86400 IN A 142.204.6.57ittads.senecac.on.ca. 86400 IN A 142.204.6.57

• pulsar.senecac.on.ca. 86400 IN A 142.204.119.97pulsar.senecac.on.ca. 86400 IN A 142.204.119.97

• ;; Query time: 2202 msec;; Query time: 2202 msec

• ;; SERVER: 127.0.0.1#53(127.0.0.1);; SERVER: 127.0.0.1#53(127.0.0.1)

• ;; WHEN: Sun Sep 29 16:38:20 2002;; WHEN: Sun Sep 29 16:38:20 2002

• ;; MSG SIZE rcvd: 238;; MSG SIZE rcvd: 238

ReferencesReferences

• For detailed syntax on these and For detailed syntax on these and other linux commands look at other linux commands look at

• http://www.http://www.oreillynetoreillynet.com/.com/linuxlinux//cmdcmd//

top related