UNIX Commands for TCPIP Networking


UNIX Commands for TCP/IP Networking

One of the major networking capabilities in UNIX comprises the basic commands for TCP/IP networking. These commands are used to establish TCP/IP connections and provide a set of user-level commands for networking tasks. Most versions of UNIX include two sets of commands used to supply networking services over the Internet, the Berkeley Remote Commands, which were developed at the University of California, Berkeley, and the DARPA Commands.

The DARPA Commands include facilities, independent of the operating system, for such tasks as terminal emulation, file transfer, mail, and obtaining information on users. You can use these commands for networking with computers running operating systems other than UNIX.

The Berkeley Remote Commands include UNIX computer-to-UNIX computer commands for remote copying of files, remote login, remote shell execution, and obtaining information on remote systems and users.

Different versions of UNIX also provide additional networking capabilities. In particular, distributed file systems, such as the Network File System (NFS), are an important networking capability of UNIX. Chapter 15 discusses the networking capabilities provided by distributed file systems.

The next section describes how to use the user-level UNIX TCP/IP commands: the Berkeley Remote Commands and the DARPA Commands.

In this chapter, it is assumed that TCP/IP commands have been installed and configured on your system and that your system is part of a TCP/IP network. (Also see Chapter 17 for information on operation, administration, and maintenance of your TCP/IP network.)

The Remote Commands

UNIX incorporates the Berkeley Remote Commands, which were originally developed as part of the BSD System. These are commonly known as the r* commands, because their names start with r, so that r* matches all their names when the * is considered to be a shell metacharacter.

You can use the Remote Commands to carry out many different tasks on remote machines linked to your machine via a TCP/IP network. The most commonly used of these commands are rcp (remote copy), used to transfer files; rsh (remote shell), used to execute a command on a remote host; and rlogin (remote login), used to log in to a remote host.

The Remote Commands let you use resources on other machines. This allows you to treat a network of computers as if it were a single machine.

Security Features and Issues for the Berkeley Remote Commands

When remote users are allowed to access a system, unauthorized users may gain access to restricted resources. Which remote users have access to a system can be controlled in several ways.

Security for the Remote Commands is managed on both the user level and the host level. On the user level, the system administrator of a remote machine can grant you access by adding an entry for you in the system’s password files. Also, the system administrator on the remote machine may create a home directory on that machine for you.

Unfortunately, the Berkeley Remote Commands are inherently insecure. We will point out some of their security vulnerabilities in our discussion. The numerous security problems with the Berkeley Remote Commands led to the development of a much more secure system called the Secure Shell, discussed later in this chapter. You probably will want to use the Secure Shell rather than the Berkeley Remote Commands if you have security concerns. However, even if you plan to use the Secure Shell, it is worthwhile understanding how the Berkeley Remote Commands work.

Host-Level Security   On the host level, each host on a TCP/IP network contains a file called /etc/host.equiv. This file includes a list of the machines that are trusted by that host. Users on remote machines listed in this file can remotely log in without supplying a password.

For instance, if your host, michigan, trusts the remote machines jersey, nevada, and massachusetts, the /etc/host.equiv file on michigan looks like this:

 $ cat /etc/host.equiv jersey nevada massachusetts

If the /etc/host.equiv file contains a line with just a plus sign (+), this machine trusts all remote hosts. Misuse of the /etc/host.equiv file may let any remote user log in without a password. Consequently, many system administrators prohibit its use anywhere within the network of an organization or company

User-Level Security   Another facility is used to enforce security on the user level. A user who has a home directory on a remote machine may have a file called .rhosts in his or her home directory on that machine. This file is used to allow or deny access to this user’s login, depending on which machine and which user is trying to gain access. The .rhosts file defines “equivalent” users, who are given the same access privileges.

An entry in .rhosts is either a host name, indicating that this user is trusted when accessing the system from the specified host, or a host name followed by a login name, indicating that the login name listed is trusted when accessing the system for the specified host. For instance, if khr has the following .rhosts file in /home/khr on the local system,

 $ cat .rhosts jersey nevada massachusetts rrr massachusetts jmf delaware delaware rrr

then the only trusted users are khr, when logging in from jersey, nevada, or delaware; rrr, when logging in from massachusetts or delaware; and jmf, when logging in from massachusetts.

When security is loose on a system, .rhosts files are owned by remote users, to facilitate access. However, when security is tight, root (on the local machine) will be the owner of all .rhosts files and will deny write permission by remote users. Misuse of .rhosts files may allow let unauthorized users access, so system administrators may prohibit their use.

Remote Login

At times you may need to log in to another UNIX computer on a TCP/IP network and carry out some tasks. This can be done using the rlogin command. You can use this command to log in to a remote machine and use it as if you were a local user. This is the general form of this command:

 $ rlogin machine

For instance, to log in to the remote machine jersey, use the following command:

 $ rlogin jersey Password: u2a33t   {not displayed} Sun Microsystems Inc.   SunOS 5.9       Generic May 2002 jersey Last login: Sun May 22 16:29:13 from 192.11.105.32 $

In this case, the remote host jersey prompted the user for a password. The remote user correctly entered the password and was logged in to jersey The remote host jersey also supplied the last login time for this user, and the place from which the user last logged in. (In this example, this is specified by the Internet address of a machine on the TCP/IP network, 192.11.105.32. See Chapter 17 for a discussion of this type of address.)

The rlogin command supplies the remote machine with your user ID. It also tells the remote machine what kind of terminal you are using by sending the value of your TERM variable. During an rlogin session, characters are passed back and forth between the two systems because during the session you remain connected to your original host.

You can also use rlogin to log in to a remote system using a different user ID. To do this, you use the -l option followed by the user ID. For instance, to log in to jersey with user ID ams, use this command:

 $ rlogin -l ams jersey

Unfortunately, when rlogin is used, all information sent over the connection, including passwords, is transmitted with no encryption, making it vulnerable to interception by unauthorized parties.

Later in this chapter, you’ll learn about another command, telnet, which you can use for logging in to a remote system on your TCP/IP network. Unlike using rlogin, you can use telnet to log in to machines running operating systems other than UNIX. However, when you use telnet to log in to a UNIX computer, telnet does not pass information about your environment to the remote machine, whereas rlogin does this.

rlogin Access   Under some circumstances, you can use rlogin to log in to a remote machine without even entering your password on that machine. At other times you will have to supply a password. Finally, under some circumstances you will not be able to log in at all. You are denied access when you attempt to log in to a remote machine if there is no entry for you in the password database on that machine.

If you do have an entry in the password database, and if the name of your machine is in the /etc/hosts.equiv file on the remote machine, you are logged in to the remote machine without entering a password. This happens because the remote machine trusts your machine.

You are also logged in without entering a password if the name of your local machine is not in the /etc/hosts.equiv database, but a line in .rhosts in the home directory of the login on the remote machine contains either your local machine’s name, if the login name is the same as yours, or your local machine’s name and your user name.

Otherwise, when you do have an entry in the password database of the remote machine, but the name of your machine is not in the /etc/hosts.equiv file on the remote host and there is no appropriate line in the .rhosts file in the home directory of the login on the remote machine, the remote machine prompts you for a password. If you enter the correct password for your account on the remote machine, you are logged in to this remote machine. However, even though you can log in, you will not be able to run remote processes such as rsh or rcp. This prevents you from using a multihop login to a secure machine.

When you use rlogin to attempt to log in to a machine not known by your machine, that is, whose host name cannot be resolved, your system will search without success through its host database and then return a message that the remote host is unknown. For instance, suppose you attempt to log in to the remote host nevada from your machine, but this machine is not in the host database of your machine. Your machine will return with the message

 $ rlogin nevada nevada: unknown host

Logging In to a Succession of Machines   You can successively log in to a series of different machines using rlogin commands. For instance, starting at your local machine you can log in to jersey using this command:

 $ rlogin jersey

Once you are successfully logged in to jersey, you can log in to nevada by issuing the command

 $ rlogin nevada

from your shell on jersey This would log you in to all three systems simultaneously

Aborting and Suspending rlogin Connections   To abort an rlogin connection, simply enter CTRL-D, exit, or ~. (tilde dot). You will return to your original machine. Note that when you have logged in to a succession of machines using rlogin, typing ~. returns you to your local machine, severing all intermediate connections. To abort only the last connection, type ~ ~. (tilde tilde dot).

If you are using a job control shell, such as jsh, you can suspend an rlogin connection, retaining the ability to return to it later. To do this, type ~ CTRL-Z (tilde CTRL-Z). When you suspend an rlogin connection, this connection becomes a stopped process on your local machine and you return to the original machine from which you issued the rlogin command. You can reactivate the connection by typing fg followed by a RETURN, or % followed by the job number of the stopped process.

When you are logged in to a succession of machines using rlogin, typing ~ CTRL-Z returns you to your local machine. Typing ~ ~ CTRL-Z (tilde tilde CTRL-Z) suspends only your last rlogin connection.

You can change the ~ to another character (here noted as c) by using the ~e option followed by the character you want to be the abort sequence, as shown in the following format:

 $ rlogin ~ec remote_host_name 

For instance, the command

 $ rlogin ~e+ jersey

begins the remote login process to jersey and sets the abort sequence to +. (plus dot).

Copying Files Using rcp

Suppose that you want to send a letter to everyone on a mailing list, but the file containing the names and addresses is located on a remote machine. You can use the rcp command to obtain a copy of this list. The rcp command is used to copy files to and from remote machines on a TCP/IP network.

This is the general form of an rcp command line:

 $ rcp source_machine:file destination_machine:file 

To use rcp to transfer files to or from a remote machine, you must have an entry in the password database on that machine, and the machine you are using must be in the remote machine’s list of trusted hosts (either in the /etc/host.equiv file or in your .rhosts file on the remote machine).

Copying from a Remote Host   To be able to copy a file from a remote machine, you must have read permission on this file. To use rcp to copy a file into a specified directory, giving the file the same name it has on the remote system, use a command line of the form

 $ rcp host:pathname directory 

For instance, to copy the file named /home/phonelist on the remote machine jersey into your directory /home/data on your local machine, naming the file /home/data/phonelist, use the command

 $ rcp jersey:/home/phonelist /home/data

You can also change the name of the file when you copy it by specifying a filename. This is the general form of this use of the rcp command:

 $ rcp host:pathname directory/file

For instance, the command

 $ rcp jersey:/home/phonelist /home/data/numbers

copies the file /home/phonelist on jersey into the file /home/data/numbers on your local machine.

When you copy files using rcp, you can use whatever abbreviations for directories are allowed by the shell you are using. For instance, with the standard shell, the command line

 $ rcp jersey:/home/phonelist $HOME/numbers

copies the file /home/phonelist on jersey to the file numbers in your home directory on your local machine.

Copying from Your Machine to a Remote Machine   You can also use rcp to copy a file from your machine to a remote machine. You must have write permission on the directory on the remote machine that you want to copy the file to.

This is the general form of the rcp command used to copy a file from your machine to a remote machine:

 $ rcp file host:directory 

For instance, to copy the file /home/numbers on your machine into the directory /home/ data on the remote host jersey, naming it /home/data/numbers, use this command:

 $ rcp /home/numbers jersey:/home/data

To rename the file on the remote machine, use a command line of the following form:

 $ rcp file host:directory/file 

For instance, the command

 $ rcp /home/numbers jersey:/home/data/lists

renames the copied file /home/data/lists.

Using rcp to Copy Directories   You can copy entire directory subtrees using the rcp command with the -r option. This is the general form of the command line used to copy a remote directory into a specified directory on your machine:

 $ rcp -r machine:directory directory 

For instance, you can copy the directory /home/data on the remote machine jersey into the directory /home/info on the local machine using this command:

 $ rcp -r jersey:/home/data /home/info

To copy a local directory into a specified directory on a remote host, you use a command line of the form

 $ rcp -r directory machine:directory

Thus, to copy the directory /home/info on the local machine into the directory /home/data on the remote machine jersey, use the command line

 $ rcp -r /home/info jersey:/home/data

Using Shell Metacharacters with rcp   Be careful when you use shell metacharacters with rcp commands. Shell metacharacters are interpreted on the local machine instead of on the remote machine unless you use escape characters or quotation marks. For example, suppose you want to copy the files /etc/f1 and /etc/f2 on the remote machine jersey, and that in your current directory on the local machine you have files named friends and fiends. To attempt to copy the files /etc/f1 and /etc/f2 on jersey into your current directory, you type this:

 $ rcp jersey:/etc/f*

Your local shell expands f* to match the filenames friends and fiends. Then it attempts to copy the files /etc/friends and /etc/fiends on jersey, which was not what you intended.

You can avoid this problem using an escape character like this:

 $ rcp jersey:/etc/f\*

You can also use this:

 $ rcp \'jersey:/etc/f*\'

Creating a Remote Shell with rsh

Sometimes you may want to execute a command on a remote machine without logging in to that machine. You can do this using the rsh (for remote shell) command (HP-UX users should note that this command is called remsh in HP-UX systems). An rsh command executes a single command on a remote UNIX system host on a TCP/IP network. (Do not confuse the remote shell rsh with the restricted shell, discussed in Chapter 12. Although the restricted shell also has the name rsh, it is not a user-level command. Chapter 12 describes how the restricted shell is run.)

To use rsh, you must have an entry in the password database on the remote machine, and the machine you are using must be a trusted machine on this remote host, either by being listed in the /etc/hosts.equiv file or by having an appropriate entry in your .rhosts file in your home directory on the remote machine.

This is the general form of an rsh command:

 $ rsh host command

For instance, to produce a complete listing of the files in the directory /home/khr on jersey, use this command:

 $ rsh jersey ls -l /home/khr

The output of the ls -l command on jersey is your standard output on your local machine.

The command rsh does not actually log in to the remote machine. Rather, a daemon on the remote machine generates a shell for you and then executes the command that you specify The type of shell generated is determined by your entry in the password database on the remote host. Also, the appropriate startup file for your shell (i.e., your .profile on the remote host if you use the standard shell) is invoked.

Shell Metacharacters and Redirection with rsh

Shell metacharacters and redirection symbols in an rsh command that are not quoted or escaped are expanded at the local level, not on the remote machine. For instance, the command

 $ rsh jersey ls /usr/bin > /home/khr/list

lists files in the directory /usr/bin on the machine jersey, redirecting the output to the file /home/khr/list on the local machine. This is the outcome because the redirection symbol > is interpreted at the local level.

To perform the redirection on the remote machine and place the list of files in /usr/bin on jersey into the file /home/khr/list on jersey, use single quotes around the redirection sign >:

 $ rsh jersey ls /usr/bin '>' /home/khr/list

Using a Symbolic Link for rsh Commands

When you find that you often issue rsh commands on a particular machine, you can set up a symbolic link that lets you issue an rsh command on that host simply by using the name of that host. For instance, suppose you run the command

 $ ln -s /usr/sbin/rsh /usr/hosts/jersey

and put the directory /usr/hosts in your search path. Instead of using the command line

 $ rsh jersey ls /usr/bin

you can use the simpler command line

 $ jersey ls /usr/bin

When you make this symbolic link, you can also remotely log in to jersey by simply issuing the command

 $ jersey

which is shorthand for this:

 $ rlogin jersey

Using rwall

Another r* command that you might find useful is rwall (from remote write all), available on many versions of UNIX. This command is used to send a message to all users on a remote host (as long as this host is running the rwall daemon, rwalld). (Note that this capability is often restricted to just root by system administrators.) For instance, you can send a message to all users on the remote machine saginaw using the following command:

 $ rwall saginaw Please send your monthly activity report to Yvonne at california!ygm by Friday.   Thanks! CTRL+D

You end your message by typing CTRL-D to signify end-of-file. This message will be delivered to all users on saginaw, beginning with the line that looks like this:

 Broadcast message from ygm on california ...




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net