Exporting displays

As was previously mentioned, it is possible to run X programs on one computer and display them on another. This is incredibly bandwidth-intensive, so you probably won't want to do this over a modem connection or over very long distances. Additionally, there are security considerations: exporting a display is not a very secure thing to do, since you'll be letting the entire network look at what you're doing. Still, it can be very useful on a local network.

An important thing to note here is the use of the words “client” and “server”. When exporting the display, you may become confused as to what's a client and what's a server. We refer to the machine that actually runs the X programs and sends the display information as the “server”. The machine that you use to display the remote program is called the “client”. When discussing the design of X, this is reversed. The program that displays things is called the “server”, while the running program is called the “client”. It's not too terribly confusing, but worth pointing out.

For this example, we'll be making use of two computers: golf is a fairly powerful server sitting underneath a desk on one side of a crowded room. It has a lot of RAM and a nice processor in it. In addition, it has lots of X programs on it, but no monitor. On the other side of the room is couch, an old machine with little RAM and not much disk. It is way too weak to run resource-intensive programs like Netscape. couch has two major advantages, though: it has a monitor, and it is sitting right next to the couch so you don't even have to get up to use it. Ideally, you would be able to run Netscape without getting off the couch. Exporting is the answer.

First, log in to couch and start up X. Then open your favorite terminal program (xterm, rxvt, eterm, aterm, or a host of others). The first step to remotely displaying X programs is to set up the client machine so that other machines are allowed to display to the machine. This uses the xhost program to control access. If you are on a secure internal network, you probably don't care who can remotely display programs. In that case, you would just let anyone on the network display:

   couch$ xhost +
   access control disabled, clients can connect from any host

On the other hand, you might want to do this using machines that are on an insecure network (the Internet, a college network, or anything else that you don't have control over). You certainly don't want just anyone to connect. xhost allows you to be selective about who can display:

   couch$ xhost + golf.foc
   golf.foc being added to access control list

Now, only golf.foc (the server mentioned earlier) can display programs to couch. You can see who has access to display programs by running xhost with no arguments:

   couch$ xhost
   access control enabled, only authorized clients can connect
   INET:golf.foc
   INET:localhost
   INET:couch.foc
   LOCAL:

This is all you have to do to set up the client end of things. The next step is to set up the server so that it knows to display programs somewhere other than the monitor. Since the server doesn't have a monitor on it (and therefore doesn't have X running), it'll need to know where to display.

Setting up the server is not very difficult either. After connecting, you'll need to modify the $DISPLAY environment variable. By default, it will probably not be set to anything. You'll need to set $DISPLAY to the value of the remote host, plus a number that represents which X session to display to. You will almost always have only one X session running, so dealing with that variable shouldn't be an issue.

Here's how the $DISPLAY variable would be set on our example server using Bash as the shell. Other shells would use a different syntax, but the value should be the same.

   golf$ export DISPLAY=couch.foc:0.0

That's all there is to setting up the server side of things. Now you just stay logged into the server and run X programs from there. All the screen output from the program will get sent across the network to the client machine, even though it's running on a computer across the room.

   golf$ netscape &

This would run netscape off the server machine, but since the DISPLAY variable is set to couch, everything will get displayed there. You don't even have to get up to run those big X programs on your old terminal. One important note about this: the server machine will have to have all the X libraries and other support files needed to run the program. However, you won't need an X server or a /etc/XF86Config file, since nothing is getting displayed to the server.

Afterwards, you might want to disable display exporting by removing the server from your client's access control list:

   couch$ xhost - golf.foc
   golf.foc being removed from access control list
   couch$

You can see how this a great way to share computing resources. But be careful, you may be the host of many X programs for many remote computers and not even know it.