Finally, a Reason to Use Your Modem

—by Bryan Pribanic, bryan@pribanic.net

13 April 2003

Your Server probably has one, but you sure as heck don’t have any plans to use it to connect to the Internet. So, what are you going to do with your modem?

Turn it into a dial-in remote access solution, of course.

In this first installment we are going to set up the modem for use as a dial-in terminal server. This will allow you to make a command line connection to your server over the phone line—a handy little trick for when your Internet connection goes down.

(1) Answer the phone

Before we can make a connection, we need to set up our modem to auto-answer when we call up. We’ll do this by installing UUCP on the machine. In addition to a small utility that will allow us to talk to the modem, we get the whole UUCP package—which is an old-old-school method of transferring files between two UNIX systems.

First, we’ll create the UUCP user that the software will run as. We’ll do this by creating a small text file with the info for the user and then loading it into NetInfo. Drop down to the command line and execute the following:

echo “uucp:*:10:66::0:0:UUCP User:/usr/spool/uucppublic:/usr/lib/uucp/uucico” > uucpuser

Now we’ll load this into NetInfo:

sudo niload passwd . < uucpuser

Next we’ll get and decompress the UUCP source code:

curl -O ftp://ftp.gnu.org/pub/gnu/uucp/uucp-1.06.2.tar.gz 
gnutar -xzvf uucp-1.06.2.tar.gz 
cd uucp-1.06.1

You can check to see if this worked by typing

id uucp

Which should return some info about the uucp user.

We now need to tweak the uucp config file before installation to put the man pages in the right place:

open -e Makefile.in

This will open the makefile in TextEdit, allowing you to go to the man page section. You need to comment out the current entries for where to stash the man pages and uncomment the alternative place underneath.

When you are done the section of the file will look like this:

#man1dir = $(prefix)/man/man1
man1dir = $(prefix)/share/man/man1
man1ext = .1
#man8dir = $(prefix)/man/man8
man8dir = $(prefix)/share/man/man8

Save this file and go back to the Terminal and compile UUCP:

./configure
make
sudo make install

Now that we have it compiled we can create a few directories that UUCP will be looking for:

sudo mkdir -p /usr/spool/uucp
sudo chmod 755 /usr/spool
sudo chmod 1777 /usr/spool/uucp

Finally we can actually make a connection to the modem and tell it to auto-answer:

rehash
sudo cu -l /dev/tty.modem

After a few moments you should get a message on the screen that says you are connected. You will now need to type in a few commands. Note that you can’t use the backspace when doing this, so if you make a mistake just return and type the command again. After each command you should get an “OK” for a response letting you know that the change worked. So, here’s what you need to enter.

ats0=1 
at&w 
~.

The first command contains a zero, not an “O,” and it tells the modem to answer the line when it rings. The next command saves that setting into the nvram of the modem so you won’t have to do this every time you reboot. Finally, the last command will disconnect you from the modem.

(2) Get mgetty

Now that the modem is listening, we need to connect it to mgetty—which will get us our login prompt when dialing in.

Go back to the command line to download the source and decompress it:

curl -O ftp://alpha.greenie.net/pub/mgetty/source/1.1/mgetty1.1.30-Dec16.tar.gz
gnutar -xzvf mgetty1.1.30-Dec16.tar.gz
cd mgetty-1.1.30

Now we can do some minor edits to the config files.

open -e Makefile

This will open up the Makefile in TextEdit. We need to change the C compiler from gcc to cc. I know that Mac OS X actually uses gcc, but the configure script for mgetty can’t figure that out. So find the line very near the top that says “CC=gcc” and comment that out by putting a pound sign in front of it. Then remove the pound sign from in front of the next line.

Now do a search for “INSTALL=install -c -o bin -g bin". This line tells the software to use the “bin” user when running. We don’t have a “bin” user so comment out this line and uncomment the line below that references NeXT/BSD.

Finally, we need to change the fax user. Mgetty has some fax capabilities but again we don’t have a fax user so we need to edit that a bit. Search for “FAX_OUT_USER=fax” and change it to “FAX_OUT_USER=nobody"

Save the file in TextEdit and then move back to the command line. The next file we need to edit is policy.h-dist. This file sets up some basic parameters of your modem connection. The problem is that your modem may not understand the default init string that mgetty uses. For example, the internal modem in my TiBook 667 didn't. To get around this open the file in TextEdit.

open -e policy.h-dist

and search for this line:

#define MODEM_INIT_STRING “ATS0=0Q0&D3&C1"

and make it look like this

#define MODEM_INIT_STRING “ATS0=0Q0"

Now save the file. Then you’ll need to copy that default file into a working file that mgetty will use during compilation.

cp policy.h-dist policy.h

Now we can get to the actual build of mgetty.

make sudo makeinstall

We need to add one line to /etc/ttys that will hook mgetty up to the modem. You’ll need to do this as the root user, so either do this with emacs or vi from the command line, or log into your machine as root and edit the file in TextEdit. Either way, add this line to the end /etc/ttys:

tty.modem “/usr/local/sbin/mgetty -D -x 3” vt100 on

The -D tells mgetty not to use your modem for faxes; this was a necessary step on my machine, but may not be on yours. The -x 3 sets the debugging level to 3.

And lastly you’ll need to reboot, or for the daring

sudo kill -HUP 1

You should now be able to dial into your machine and get a login prompt.

You can do this either from another machine that you have installed UUCP on; you would use the cu command to initiate the connection or you can use ZTerm if you would like a more graphical application.

Using either method establish the connection with “atdt” and then your server’s phone number

For example:

atdt 2025551212