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.
telnetnc
Quick example of nc (pronounced net-cat) in action.
Simple use of nc[root@tristan]# nc 192.168.100.17 25220 isolde ESMTPquit221 isoldenc is one of a large number of tools for making a
simple TCP connection.
Specifying timeout with nc[root@tristan]# nc -w 5 192.168.98.82 22Specifying source address with nc[root@masq-gw]# nc -s 192.168.99.254 192.168.47.3 25Using nc as a server[root@tristan]# nc -l -p 2048Delaying a stream with nc[root@tristan]# nc -l -p 2048Using nc with UDP[root@tristan]# nc -u 192.168.100.17 3000socatSimple use of socatUsing socat with proxy connectUsing socat perform SSLConnecting one end of socat to a file
descriptorConnecting socat to a serial lineUsing a PTY with socatExecuting a command with socatConnecting one socat to another onetcpclientSimple use of tcpclientSpecifying the local port which tcpclient
should requestSpecifying the local IP to which tcpclient
should bindxinetdIP redirection with xinetdPublishing a service with xinetdtcpserverSimple use of tcpserverSpecifying a CDB for tcpserverLimiting the number of concurrently accept TCP sessions
under tcpserverSpecifying a UID for tcpserver's
spawned processesredirRedirecting a TCP port with redir
Here we are going to talk about port redirection, so point out
and .
Running redir in transparent modeRunning redir from another TCP serverSpecifying a source address for redir's client
side