Sockets; Servers and Clients 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. telnet and nc are the most common tools used for quickly creating a TCP connection. The less common utility tcpclient provides a scriptable method for initiating TCP sessions, equally as well as nc. Finally, the tool socat includes support for a large number of other types of sockets and files in addition to TCP and UDP. Some services expect to run under another utility which will handle the socket operations. We'll tour the following utilities: xinetd, tcpserver and the very specifically designed port redirection utility redir. It's important to remember that tools like socat and nc are suited equally well to initiate or receive TCP connections, but may not have the flexibility of administrative control afforded by tools such as xinetd and tcpserver where this was inherent to the design of the software.
<command>telnet</command>
<command>nc</command> Quick example of nc (pronounced net-cat) in action. Simple use of <command>nc</command> [root@tristan]# nc 192.168.100.17 25 220 isolde ESMTP quit 221 isolde nc is one of a large number of tools for making a simple TCP connection. Specifying timeout with <command>nc</command> [root@tristan]# nc -w 5 192.168.98.82 22 Specifying source address with <command>nc</command> [root@masq-gw]# nc -s 192.168.99.254 192.168.47.3 25 Using <command>nc</command> as a server [root@tristan]# nc -l -p 2048 Delaying a stream with <command>nc</command> [root@tristan]# nc -l -p 2048 Using <command>nc</command> with UDP [root@tristan]# nc -u 192.168.100.17 3000
<command>socat</command> Simple use of <command>socat</command> Using <command>socat</command> with proxy connect Using <command>socat</command> perform SSL Connecting one end of <command>socat</command> to a file descriptor Connecting <command>socat</command> to a serial line Using a PTY with <command>socat</command> Executing a command with <command>socat</command> Connecting one <command>socat</command> to another one
<command>tcpclient</command> Simple use of <command>tcpclient</command> Specifying the local port which <command>tcpclient</command> should request Specifying the local IP to which <command>tcpclient</command> should bind
<command>xinetd</command> IP redirection with <command>xinetd</command> Publishing a service with <command>xinetd</command>
<command>tcpserver</command> Simple use of <command>tcpserver</command> Specifying a CDB for <command>tcpserver</command> Limiting the number of concurrently accept TCP sessions under <command>tcpserver</command> Specifying a UID for <command>tcpserver</command>'s spawned processes
<command>redir</command> Redirecting a TCP port with <command>redir</command> Here we are going to talk about port redirection, so point out and . Running <command>redir</command> in transparent mode Running <command>redir</command> from another TCP server Specifying a source address for <command>redir</command>'s client side