LDP/LDP/guide/docbook/linux-ip/tools-sockets.xml

298 lines
9.6 KiB
XML

<!-- $Id$ -->
<appendix id="tools-sockets">
<title>Sockets; Servers and Clients</title>
<para>
There is little point to the huge study of routing and network
configuration if we can't move data from one host to another.
This appendix will cover many of the command line tools (and a few
daemons) which can be used to initiate TCP connections, receive TCP
connections and send and receive UDP datagrams. Many of these tools are
included with stock installations.
</para>
<para>
<link linkend="tools-telnet"><command>telnet</command></link> and
<link linkend="tools-nc"><command>nc</command></link> are the most
common tools used for quickly creating a TCP connection. The less
common utility
<link linkend="tools-tcpclient"><command>tcpclient</command></link>
provides a scriptable method for initiating TCP sessions, equally as
well as <command>nc</command>. Finally, the tool
<link linkend="tools-socat"><command>socat</command></link> includes
support for a large number of other types of sockets and files in
addition to TCP and UDP.
</para>
<para>
Some services expect to run under another utility which will handle the
socket operations. We'll tour the following utilities:
<link linkend="tools-xinetd"><command>xinetd</command></link>,
<link linkend="tools-tcpserver"><command>tcpserver</command></link> and
the very specifically designed port redirection utility
<link linkend="tools-redir"><command>redir</command></link>.
</para>
<para>
It's important to remember that tools like <command>socat</command> and
<command>nc</command> are suited equally well to initiate or receive TCP
connections, but may not have the flexibility of administrative control
afforded by tools such as <command>xinetd</command> and
<command>tcpserver</command> where this was inherent to the design of
the software.
</para>
<section id="tools-telnet">
<title><command>telnet</command></title>
<para>
</para>
</section>
<section id="tools-nc">
<title><command>nc</command></title>
<para>
Quick example of <command>nc</command> (pronounced net-cat) in action.
</para>
<example id="ex-tools-nc-basic">
<title>Simple use of <command>nc</command></title>
<programlisting>
<prompt>[root@tristan]# </prompt><userinput>nc 192.168.100.17 25</userinput>
<computeroutput>220 isolde ESMTP</computeroutput>
<userinput>quit</userinput>
<computeroutput>221 isolde</computeroutput>
</programlisting>
</example>
<para>
<command>nc</command> is one of a large number of tools for making a
simple TCP connection.
</para>
<para>
</para>
<example id="ex-tools-nc-timeout">
<title>Specifying timeout with <command>nc</command></title>
<programlisting>
<prompt>[root@tristan]# </prompt><userinput>nc -w 5 192.168.98.82 22</userinput>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-nc-source">
<title>Specifying source address with <command>nc</command></title>
<programlisting>
<prompt>[root@masq-gw]# </prompt><userinput>nc -s 192.168.99.254 192.168.47.3 25</userinput>
</programlisting>
</example>
<para>
</para>
<para>
</para>
<para>
</para>
<example id="ex-tools-nc-server">
<title>Using <command>nc</command> as a server</title>
<programlisting>
<prompt>[root@tristan]# </prompt><userinput>nc -l -p 2048</userinput>
</programlisting>
</example>
<para>
</para>
<para>
</para>
<para>
</para>
<example id="ex-tools-nc-delay">
<title>Delaying a stream with <command>nc</command></title>
<programlisting>
<prompt>[root@tristan]# </prompt><userinput>nc -l -p 2048</userinput>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-nc-udp">
<title>Using <command>nc</command> with UDP</title>
<programlisting>
<prompt>[root@tristan]# </prompt><userinput>nc -u 192.168.100.17 3000</userinput>
</programlisting>
</example>
<para>
</para>
</section>
<section id="tools-socat">
<title><command>socat</command></title>
<para>
</para>
<example id="ex-tools-socat-basic">
<title>Simple use of <command>socat</command></title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-socat-proxy">
<title>Using <command>socat</command> with proxy connect</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-socat-openssl">
<title>Using <command>socat</command> perform SSL</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-socat-file-descriptor">
<title>Connecting one end of <command>socat</command> to a file
descriptor</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-socat-serial">
<title>Connecting <command>socat</command> to a serial line</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-socat-pty">
<title>Using a PTY with <command>socat</command></title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-socat-exec">
<title>Executing a command with <command>socat</command></title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-socat-socat">
<title>Connecting one <command>socat</command> to another one</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
</section>
<section id="tools-tcpclient">
<title><command>tcpclient</command></title>
<para>
</para>
<example id="ex-tools-tcpclient-basic">
<title>Simple use of <command>tcpclient</command></title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-tcpclient-localport">
<title>Specifying the local port which <command>tcpclient</command>
should request</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-tcpclient-localip">
<title>Specifying the local IP to which <command>tcpclient</command>
should bind</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
</section>
<section id="tools-xinetd">
<title><command>xinetd</command></title>
<para>
</para>
<example id="ex-tools-xinetd-redir">
<title>IP redirection with <command>xinetd</command></title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<para>
</para>
<example id="ex-tools-xinetd-server">
<title>Publishing a service with <command>xinetd</command></title>
<programlisting>
</programlisting>
</example>
<para>
</para>
</section>
<section id="tools-tcpserver">
<title><command>tcpserver</command></title>
<para>
</para>
<example id="ex-tools-tcpserver-basic">
<title>Simple use of <command>tcpserver</command></title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-tcpserver-cdb">
<title>Specifying a CDB for <command>tcpserver</command></title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-tcpserver-concurrency">
<title>Limiting the number of concurrently accept TCP sessions
under <command>tcpserver</command></title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-tcpserver-uid">
<title>Specifying a UID for <command>tcpserver</command>'s
spawned processes</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
</section>
<section id="tools-redir">
<title><command>redir</command></title>
<para>
</para>
<example id="ex-tools-redir-basic">
<title>Redirecting a TCP port with <command>redir</command></title>
<programlisting>
</programlisting>
</example>
<para>
Here we are going to talk about port redirection, so point out
<xref linkend="nat-dnat"/> and <xref linkend="nat-pat-userspace"/>.
</para>
<example id="ex-tools-redir-transproxy">
<title>Running <command>redir</command> in transparent mode</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-redir-inetd">
<title>Running <command>redir</command> from another TCP server</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
<example id="ex-tools-redir-bindaddr">
<title>Specifying a source address for <command>redir</command>'s client
side</title>
<programlisting>
</programlisting>
</example>
<para>
</para>
</section>
</appendix>