old-www/LDP/GNU-Linux-Tools-Summary/html/c8319.htm

943 lines
12 KiB
HTML

<HTML
><HEAD
><TITLE
>Network Commands</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="GNU/Linux Command-Line Tools Summary"
HREF="book1.htm"><LINK
REL="PREVIOUS"
TITLE="Mathematical tools"
HREF="c8113.htm"><LINK
REL="NEXT"
TITLE="Internet Specific Commands"
HREF="x8751.htm"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>GNU/Linux Command-Line Tools Summary</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="c8113.htm"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x8751.htm"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="NETWORK-COMMANDS"
></A
>Chapter 13. Network Commands</H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
><A
HREF="c8319.htm#NETWORK-CONFIGURATION"
>Network Configuration</A
></DT
><DT
><A
HREF="x8751.htm"
>Internet Specific Commands</A
></DT
><DT
><A
HREF="x9094.htm"
>Remote Administration Related</A
></DT
></DL
></DIV
><P
>The network <A
NAME="AEN8322"
></A
>commands chapter explains <A
NAME="AEN8324"
></A
>various tools which can be useful when networking <A
NAME="AEN8326"
></A
>with other computers <A
NAME="AEN8328"
></A
>both within the network <A
NAME="AEN8330"
></A
>and accross the internet,<A
NAME="AEN8332"
></A
> obtaining more <A
NAME="AEN8334"
></A
>information <A
NAME="AEN8336"
></A
>about other computers. This chapter also includes <A
NAME="AEN8338"
></A
>information on tools for network <A
NAME="AEN8340"
></A
>configuration, file transfer <A
NAME="AEN8342"
></A
>and working with remote machines.<A
NAME="AEN8344"
></A
></P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>netstat</DT
><DD
><P
><A
NAME="AEN8351"
></A
>Displays contents <A
NAME="AEN8353"
></A
>of /proc/net files.<A
NAME="AEN8355"
></A
> It works with the <SPAN
CLASS="PRODUCTNAME"
>Linux</SPAN
> Network Subsystem,<A
NAME="AEN8358"
></A
> it will tell <A
NAME="AEN8360"
></A
>you what the status<A
NAME="AEN8362"
></A
> of ports <A
NAME="AEN8364"
></A
>are ie. open,<A
NAME="AEN8366"
></A
> closed,<A
NAME="AEN8368"
></A
> waiting,<A
NAME="AEN8370"
></A
> masquerade <A
NAME="AEN8372"
></A
>connections. It will also display various other things. It has many different options.<A
NAME="AEN8374"
></A
></P
></DD
><DT
>tcpdump</DT
><DD
><P
><A
NAME="AEN8380"
></A
>This is a sniffer,<A
NAME="AEN8382"
></A
> a program that captures <A
NAME="AEN8384"
></A
>packets off <A
NAME="AEN8386"
></A
>a network<A
NAME="AEN8388"
></A
> interface <A
NAME="AEN8390"
></A
>and interprets <A
NAME="AEN8392"
></A
>them for you. It understands all basic <A
NAME="AEN8394"
></A
>internet <A
NAME="AEN8396"
></A
>protocols,<A
NAME="AEN8398"
></A
> and can be used to save <A
NAME="AEN8400"
></A
>entire packets <A
NAME="AEN8402"
></A
>for later inspection.<A
NAME="AEN8404"
></A
></P
></DD
><DT
>ping</DT
><DD
><P
>The ping <A
NAME="AEN8410"
></A
>command (named after the sound <A
NAME="AEN8412"
></A
>of an active sonar system) sends <A
NAME="AEN8414"
></A
>echo requests <A
NAME="AEN8416"
></A
>to the host <A
NAME="AEN8418"
></A
>you specify <A
NAME="AEN8420"
></A
>on the command line, and lists<A
NAME="AEN8422"
></A
> the responses <A
NAME="AEN8424"
></A
>received their round <A
NAME="AEN8426"
></A
>trip time.</P
><P
>You simply use ping as:</P
><PRE
CLASS="SCREEN"
>ping ip_or_host_name</PRE
><P
>Note to stop <A
NAME="AEN8431"
></A
>ping (otherwise it goes forever) use
<B
CLASS="KEYCAP"
>CTRL</B
>-<B
CLASS="KEYCAP"
>C</B
>
<A
NAME="AEN8436"
></A
>
(break).</P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Please note: </B
>Using ping/smbmount/ssh or other <SPAN
CLASS="PRODUCTNAME"
>UNIX</SPAN
> system programs with a computer name rather than IP address will only work if you have the computer listed <A
NAME="AEN8442"
></A
>in your /etc/hosts<A
NAME="AEN8444"
></A
> file. Here is an example:</P
><P
><PRE
CLASS="SCREEN"
>192.168.1.100 new </PRE
> This line says that their is a computer called &ldquo;new&rdquo;<A
NAME="AEN8448"
></A
> with IP address 192.168.1.100<A
NAME="AEN8450"
></A
>. Now that it exists in the /etc/hosts file I don't have to type the IP address anymore, just the name &ldquo;new&rdquo;.</P
></BLOCKQUOTE
></DIV
></DD
><DT
>hostname</DT
><DD
><P
><A
NAME="AEN8456"
></A
>Tells the user the host <A
NAME="AEN8458"
></A
>name of the computer they are logged <A
NAME="AEN8460"
></A
>into. Note: may be called <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>host.<A
NAME="AEN8463"
></A
></I
></SPAN
></P
></DD
><DT
>traceroute</DT
><DD
><P
><A
NAME="AEN8469"
></A
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>traceroute</I
></SPAN
> will show <A
NAME="AEN8472"
></A
>the route <A
NAME="AEN8474"
></A
>of a packet.<A
NAME="AEN8476"
></A
> It attempts <A
NAME="AEN8478"
></A
>to list <A
NAME="AEN8480"
></A
>the series <A
NAME="AEN8482"
></A
>of hosts <A
NAME="AEN8484"
></A
>through which <A
NAME="AEN8486"
></A
>your packets <A
NAME="AEN8488"
></A
>travel<A
NAME="AEN8490"
></A
> on their way to a given destination.<A
NAME="AEN8492"
></A
> Also have a look at <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>xtraceroute</I
></SPAN
> (one of several <A
NAME="AEN8495"
></A
>graphical <A
NAME="AEN8497"
></A
>equivalents of this program). </P
><P
>Command syntax:</P
><PRE
CLASS="SCREEN"
>traceroute machine_name_or_ip</PRE
></DD
><DT
>tracepath</DT
><DD
><P
><A
NAME="AEN8505"
></A
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>tracepath</I
></SPAN
> performs <A
NAME="AEN8508"
></A
>a very simlar function <A
NAME="AEN8510"
></A
>to <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>traceroute</I
></SPAN
> the main difference <A
NAME="AEN8513"
></A
>is that <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>tracepath</I
></SPAN
> doesn't take complicated <A
NAME="AEN8516"
></A
>options.</P
><P
>Command syntax:</P
><PRE
CLASS="SCREEN"
>tracepath machine_name_or_ip</PRE
></DD
><DT
>findsmb</DT
><DD
><P
><A
NAME="AEN8524"
></A
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>findsmb</I
></SPAN
> is used to list info <A
NAME="AEN8527"
></A
>about machines <A
NAME="AEN8529"
></A
>that respond <A
NAME="AEN8531"
></A
>to SMB <A
NAME="AEN8533"
></A
>name queries <A
NAME="AEN8535"
></A
>(for example windows <A
NAME="AEN8537"
></A
>based machines <A
NAME="AEN8539"
></A
>sharing <A
NAME="AEN8541"
></A
>their hard disk's). </P
><P
>Command syntax:</P
><PRE
CLASS="SCREEN"
>findsmb</PRE
><P
>This would find all machines <A
NAME="AEN8546"
></A
>possible,<A
NAME="AEN8548"
></A
> you may need to specify a particular<A
NAME="AEN8550"
></A
> subnet to query those machines only...</P
></DD
><DT
>nmap</DT
><DD
><P
><A
NAME="AEN8556"
></A
>&ldquo; network <A
NAME="AEN8558"
></A
>exploration tool and security <A
NAME="AEN8560"
></A
>scanner<A
NAME="AEN8562"
></A
>&rdquo;. <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>nmap</I
></SPAN
> is a very advanced <A
NAME="AEN8565"
></A
>network tool used to query <A
NAME="AEN8567"
></A
>machines (local or remote) as to whether they are up and what ports <A
NAME="AEN8569"
></A
>are open <A
NAME="AEN8571"
></A
>on these machines.<A
NAME="AEN8573"
></A
> </P
><P
>A simple usage example:</P
><PRE
CLASS="SCREEN"
>nmap machine_name</PRE
><P
>This would query your own machine <A
NAME="AEN8578"
></A
>as to what ports <A
NAME="AEN8580"
></A
>it keeps open.<A
NAME="AEN8582"
></A
> <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>nmap</I
></SPAN
> is a very powerful <A
NAME="AEN8585"
></A
>tool, documentation <A
NAME="AEN8587"
></A
>is available <A
NAME="AEN8589"
></A
>on the <A
HREF="http://www.insecure.org/nmap/"
TARGET="_top"
>nmap site</A
><A
NAME="AEN8592"
></A
> as well as the information in the manual <A
NAME="AEN8594"
></A
>page.<A
NAME="AEN8596"
></A
></P
></DD
></DL
></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="NETWORK-CONFIGURATION"
></A
>Network Configuration</H1
><P
></P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>ifconfig</DT
><DD
><P
><A
NAME="AEN8606"
></A
>This command is used to configure <A
NAME="AEN8608"
></A
>network <A
NAME="AEN8610"
></A
>interfaces<A
NAME="AEN8612"
></A
>, or to display their current configuration.<A
NAME="AEN8614"
></A
> In addition <A
NAME="AEN8616"
></A
>to activating and deactivating <A
NAME="AEN8618"
></A
>interfaces <A
NAME="AEN8620"
></A
>with the &ldquo;up&rdquo; and &ldquo;down&rdquo; settings,<A
NAME="AEN8622"
></A
> this command is necessary for setting <A
NAME="AEN8624"
></A
>an interface's address<A
NAME="AEN8626"
></A
> information <A
NAME="AEN8628"
></A
>if you don't have the <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>ifcfg</I
></SPAN
> script.<A
NAME="AEN8631"
></A
></P
><P
>Use <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>ifconfig</I
></SPAN
> as either:</P
><PRE
CLASS="SCREEN"
>ifconfig</PRE
><P
>This will simply list all information on all network <A
NAME="AEN8637"
></A
>devices currently up.</P
><PRE
CLASS="SCREEN"
>ifconfig eth0 down</PRE
><P
>This will take eth0 (assuming the device <A
NAME="AEN8641"
></A
>exists) down, it won't be able<A
NAME="AEN8643"
></A
> to receive <A
NAME="AEN8645"
></A
>or send <A
NAME="AEN8647"
></A
>anything until you put the device back &ldquo;up&rdquo; again.</P
><P
>Clearly there are a lot more options for this tool, you will need to read the manual/info page to learn <A
NAME="AEN8650"
></A
>more <A
NAME="AEN8652"
></A
>about them. </P
><P
></P
></DD
><DT
>ifup</DT
><DD
><P
><A
NAME="AEN8659"
></A
>Use <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> ifup device-name </I
></SPAN
>to bring an interface <A
NAME="AEN8662"
></A
>up by following a script (which will contain your default networking <A
NAME="AEN8664"
></A
>settings). Simply type<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> ifup <A
NAME="AEN8667"
></A
></I
></SPAN
>and you will get help on using the script.</P
><P
>For example typing:</P
><PRE
CLASS="SCREEN"
>ifup eth0</PRE
><P
>Will bring eth0 <A
NAME="AEN8672"
></A
>up if it is currently down.</P
></DD
><DT
>ifdown</DT
><DD
><P
><A
NAME="AEN8678"
></A
>Use<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> ifdown device-name </I
></SPAN
>to bring an interface <A
NAME="AEN8681"
></A
>down using a script (which will contain your default network settings). Simply type<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> ifdown <A
NAME="AEN8684"
></A
></I
></SPAN
>and you will get help <A
NAME="AEN8686"
></A
>on using the script.</P
><P
>For example typing:</P
><PRE
CLASS="SCREEN"
>ifdown eth0</PRE
><P
>Will bring eth0 <A
NAME="AEN8691"
></A
>down if it is currently up.</P
></DD
><DT
>ifcfg</DT
><DD
><P
><A
NAME="AEN8697"
></A
>Use <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>ifcfg</I
></SPAN
> to configure <A
NAME="AEN8700"
></A
>a particular interface.<A
NAME="AEN8702"
></A
> Simply type ifcfg <A
NAME="AEN8704"
></A
>to get help <A
NAME="AEN8706"
></A
>on using this script.</P
><P
>For example, to change <A
NAME="AEN8709"
></A
>eth0 <A
NAME="AEN8711"
></A
>from 192.168.0.1 <A
NAME="AEN8713"
></A
>to 192.168.0.2 <A
NAME="AEN8715"
></A
>you could do:</P
><PRE
CLASS="SCREEN"
>ifcfg eth0 del 192.168.0.1
ifcfg eth0 add 192.168.0.2</PRE
><P
>The first command takes eth0 <A
NAME="AEN8719"
></A
>down and removes <A
NAME="AEN8721"
></A
>that stored <A
NAME="AEN8723"
></A
>IP address<A
NAME="AEN8725"
></A
> and the second one brings it back up with the new <A
NAME="AEN8727"
></A
>address.</P
></DD
><DT
>route</DT
><DD
><P
><A
NAME="AEN8733"
></A
>The <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>route</I
></SPAN
> command is the tool used to display <A
NAME="AEN8736"
></A
>or modify <A
NAME="AEN8738"
></A
>the routing <A
NAME="AEN8740"
></A
>table.<A
NAME="AEN8742"
></A
> To add <A
NAME="AEN8744"
></A
>a gateway <A
NAME="AEN8746"
></A
>as the default <A
NAME="AEN8748"
></A
>you would type:</P
><PRE
CLASS="SCREEN"
>route add default gw some_computer</PRE
></DD
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="c8113.htm"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.htm"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x8751.htm"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Mathematical tools</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Internet Specific Commands</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>