Collaboration

News with Leafnode

Are you in a small business environment where setting up a simple news server would drastically cut down on Internet traffic? If so, Leafnode is for you! Vincent Danen is here to get you up and running with a fast and reliable news server.


In this Daily Drill Down, we’re going to look at a news server called Leafnode. Leafnode is a unique news server that is designed for small companies or families that have several people who read the same newsgroups. It is meant for a small number of users; I would say that the best performance would be found with fewer than 100 users. For small companies, Leafnode performs admirably. It does not scale very well, though, so I would recommend that larger companies looking to install their own news server find another solution, such as INN.

One of the oldest aspects of the Internet is Usenet, more informally known as newsgroups. Usenet is a means of communicating with people in a fashion similar to e-mail mailing lists but without using e-mail. Usenet relies on servers that communicate with each other and distribute news articles, or messages. End users use news clients to connect to these servers to download articles and read them or to post messages to these groups for others to read.

Usenet relies on the Network News Transfer Protocol (NNTP) to distribute news articles. You may see news clients or servers referred to as NNTP clients or servers. This is because each speaks the language of Usenet: NNTP.

While most individuals use a simple news client to retrieve and read Usenet postings, there are situations where setting up a news server can be beneficial. For instance, let’s assume that you’re in a small company setting where you have a number of employees who observe some of the same newsgroups. Having a news server installed on your local network means that you have to download news articles from the Internet only once, not multiple times for each employee. In a situation with 10 employees, you can save your company a decent amount of bandwidth. For companies with hundreds of employees, having a local news server can save a large amount of Internet traffic. Of course, you must find the appropriate server. If you decide to use a full-scale news server, you may find that it downloads groups and articles that are never read, which creates higher bandwidth usage for no good reason, resulting in additional cost.

Installing Leafnode
To install Leafnode, visit the Leafnode Web site. Download the latest version, which at the time of this writing is 1.9.18 and is available as a gzipped tar archive called leafnode-1.9.18.tar.gz. Save this file into your /usr/local/src directory and unarchive it using the following commands:
tar xvzf leafnode-1.9.18.tar.gz

The next step is to compile and install Leafnode. For those familiar with compiling and installing programs under Linux, this is a simple step. For those unfamiliar, don't worry—it isn't difficult. After you have unarchived the file, issue the following commands:
cd leafnode-1.9.18
./configure —prefix=/usr
make
make install


There is one caveat to this. You must have a user called news installed on the system prior to doing the install. Most Linux systems come with a news user preinstalled for you. If this is not the case, you will have to add one. To see if your Linux system has a news user on the system, execute the following command:
grep news /etc/passwd

If an entry like
news:x:9:13:news:/var/spool/news

is printed to your screen, then you have the news account configured. If no such entry is displayed, you will need to add the news user. You can do this easily by executing
useradd -d /var/spool/news -M -r -s /bin/true news

This command will add the news user to the system with a home directory of /var/spool/news. It will also tell Linux to create a system account with a shell of /bin/true. The shell is there to prevent anyone from logging in to the system, since the shell /bin/true is not a real shell. Once the news user is added onto the system, you can execute the installation commands for Leafnode.

When all these steps are complete, your Leafnode server will be installed in the /usr directory tree. The configuration files will be found in the /etc/leafnode directory, and the news spool will be located in /var/spool/news. This directory is where Leafnode will store all of the retrieved articles.

Configuring Leafnode
Leafnode uses /etc/leafnode/config as its primary configuration file. You’ll see a /etc/leafnode/config.example file in that directory initially. It's a good idea to preserve that file intact so that you can refer to it later if necessary, so make a copy of that file and call it config. Use your favorite text editor to edit the file. When you edit this file, however, you must ensure that the news user always has permission to at least read the file; otherwise, Leafnode will not function properly. The best way to ensure this is to make the file owned by the user and group news. Let's take a look at some of the options you may want to configure. For the most part, Leafnode's defaults work very well, but there are a few things that must be changed.

The first thing to change, obviously, is the news servers you connect to. Typically, you will be connecting to your ISP's NNTP server, so you will need to know how to access it. Some news servers also require you to log in with a username and password. If this is the case, you will need to know that information as well.

The command
Server = news.myisp.com

tells Leafnode to use news.myisp.com as the first NNTP server to connect to. You can specify as many news servers as you like so that you can have Leafnode monitor more than one server. For example, if you also pay for your news service, you can have Leafnode monitor the pay news server, as well as your ISP's news server. If you need to enter a username or password, use the following commands:
username = joe
password = secret


This will tell Leafnode to log in to the previously specified news server with the username joe and the password secret.

In this file, you can also configure the maximum number of bytes allowed in an article to download or the minimum number of lines required to download an article. You can also define the expiry length of articles by defining a number of days with the expire keyword. The expire keyword is mandatory and should be defined on a per-server basis.

For instance, if you were to connect to two news servers, one with passwords and one without, and set an expiry of 20 days, you would use
Server = news.forpay.com
username = joe
password = secret
expiry = 20
Server = news.public.com
expiry = 20


Everything else in the config file is pretty straightforward and self-explanatory. By leaving all other settings at the defaults and specifying your servers, you should be able to begin using Leafnode right away.

Fetching news automatically
Because Leafnode is a news server and client all in one, you will need to fetch news with it on a semiregular basis in order to have current articles available to your news clients. Leafnode connects to the defined server(s) and downloads the articles, which your clients then download to read. To have new articles for them to read, Leafnode needs to be told to download the news.

To do this, Leafnode comes with a program called fetchnews. You should run fetchnews as often as you need to download new articles. The best way to do this is to set up a cron job to download the news, so everything is automatic and transparent.

Also, you will need to run the texpire program to expire old news articles so that your hard drive does not become saturated with news that has been read already or that no one is interested in reading. Leafnode monitors reading habits, so it will only download news that clients are downloading from it. This prevents Leafnode from wasting bandwidth on articles that are of no interest to anyone. You should run texpire on a regular basis—but with less frequency than fetchnews—perhaps only once a day or even once a week.

To get cron to do this work for you, simply su to news as root. Then edit the crontab file for the news user so that it will run these two programs at convenient times for you. To accomplish this, use these commands
su – news
crontab -e


to become the news user. This will fire up the default editor on your system and allow you to edit the crontab for the news user. Insert the following into the crontab:
0 4 * * 1 /usr/sbin/texpire
01 * * * * /usr/sbin/fetchnews


The first command tells cron to run texpire every Monday morning at 4:00 A.M. The second command tells cron to runfetchnews every hour. Now save the file, and cron will begin to automatically execute these commands for you.

You must now run the fetchnews program as root, so exit your su session. The first time you run fetchnews, you must tell it to download the list of newsgroups from your news servers. To do this, execute the following command as root:
/usr/sbin/fetchnews -v -n

Now Leafnode will know all of the newsgroups available and will present them as available newsgroups to your news clients.

Connecting to Leafnode
The final step is to make Leafnode ready to receive connections. You must run Leafnode from inetd or xinetd, whichever one your system is using. If you are using inetd with TCP wrappers, edit your /etc/inetd.conf file and insert this line:
nntp stream tcp nowait news /usr/sbin/tcpd /usr/sbin/leafnode

If you do not use TCP wrappers, you will want to use this line instead:
nntp stream tcp nowait news /usr/sbin/leafnode

Now restart inetd by executing this command:
kill -HUP `cat /var/run/inetd.pid`

If you want to protect your Leafnode server by using TCP wrappers, you can do so easily. If the news server is available only for intranet use, you may want to seriously consider doing this so that your news server can’t be abused by the outside world. Let's assume that your internal network is using the IP network address of 192.168.1.0. You would write the following in your /etc/hosts.deny file to allow only machines with IP addresses located in your local network to access Leafnode:
leafnode: ALL EXCEPT 192.168.1. 127.0.0.1

This allows the localhost and any IP address from 192.168.1.0 to 192.168.1.255, but no others, to access your Leafnode server.

If you use xinetd, the configuration is a little different. You’ll need to create a new file called leafnode in your /etc/xinetd.d directory and insert the following contents:
service nntp
{
flags                = REUSE
socket_type          = stream
wait                 = no
user                 = news
server               = /usr/sbin/leafnode
log_on_failure       += USERID
}


You will need to restart xinetd in a similar fashion as you restarted inetd, by executing
kill -HUP `cat /var/run/xinetd.pid`

Now you should be able to fire up your news client and connect to the news server on the machine where you just installed Leafnode. For instance, if you installed it on a computer with the IP address of 192.168.5.10, you would tell your news clients to connect to the news server at 192.168.5.10 (or whatever domain name you have associated with that machine).

If you’re using Leafnode on a local Linux machine, you’ll need to edit the file /etc/nntpserver to include your local IP address. If you plan to read news on Linux machines that are in your network but are not local, you will want to do the same. Newsreaders such as tin or slrn use that file or the $NNTPSERVER environment variable to find out which news server to connect to. If you’ll be using a Windows client or a GUI Linux client, simply point the client to your news server in its configuration screen.

At this point, you can use any client to connect to your Leafnode server. Subscribe to newsgroups in the usual fashion. At first, there will be only one message in each newsgroup you subscribe to, which is a marker message for Leafnode. When you read this message, it tells Leafnode that you are interested in the newsgroup, and future articles in that particular newsgroup will be downloaded for you automatically. Because this message is not a standard news article, some news clients have difficulty reading it. Using the Pan newsreader under Linux, I was absolutely unable to read this message, but both tin and slrn had no problem reading the message. If you want to use Pan, you may also have to temporarily use either of these text-mode newsreaders to initialize Leafnode in this way. When I used Outlook Express on a Windows 98 machine, it would not read roughly 30 percent of the marker messages in the groups I subscribed to, but it read the others. I don't know why this is, but you may need to use one of the text-mode Linux news clients to read the marker message that tells Leafnode to start downloading the articles in that group.

Once you’ve subscribed to the groups you want to read, simply run fetchnews again. This will make Leafnode download articles in the groups you've subscribed to so that you can read real articles in your news client.

Conclusion
While some may argue that Usenet is dated and practically obsolete, I have to disagree. While Usenet may not be as convenient as mailing lists or as flashy as Web-based discussion forums, it certainly has its place for high-volume discussion forums. Usenet is relatively fast and easy to deal with from the end user's perspective and doesn't require an active connection to the Internet. This is a real benefit for those who still use dial-up accounts and who may be charged a fee based on the amount of time spent online.

As I’ve shown in this Daily Drill Down, a news server such as Leafnode is ideal for small businesses and also for single users or families. With it, you can conserve bandwidth, automate the downloading of new articles, and provide some excellent server-based filtering, which can be extremely handy for preventing people from reading newsgroups that are inappropriate for the workplace or your home.

Setting up Leafnode takes about 10 to 15 minutes. It's not very difficult, and the benefits it provides are many. One benefit is the convenience of having news downloaded at regular times and available at your fingertips almost instantaneously. Another benefit is that if you’re looking for a good news client that you enjoy, you don't have to redownload news articles that you’ve downloaded already using another client. Since everything is retained on your Leafnode server, the only interaction with any other news server is done by Leafnode itself, which prevents you from downloading multiple copies of the same articles simply to find a program you like. Take it from me—someone who still hasn't found the perfect news client—that this can be a real asset.
The authors and editors have taken care in preparation of the content contained herein but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.

About Vincent Danen

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks

Free Newsletters, In your Inbox