!HOW DO YOU SET UP A GOPHER SERVER?

A guide written on February 7th 2021 by Dio9sys
________________________________________________



When I tried to set up my gopherhole, I ran into a lot of pitfalls with
getting the server to work.  Unfortunately, a lot of the guides I found
pretty much said "install pygopherd on an LTS ubuntu server and then it
will automagically work," which isn't useful for cases where it does
not work out that easy, or for cases where you're using something other
than Ubuntu or pygopherd.

My gopherhole is hosted on a Fedora 33 server, and is served by a
security-centered gopher server called Gophernicus. I chose this
server, both for its security features and because it was one of
the first ones I found that had a package for rpm-based distros.

I'll talk about the package later.  First, let's talk about how I set
this server up in terms of infrastructure.



HOW DID YOU SET UP THE BACK END FOR THIS THING?!
________________________________________________



My server is hosted on linode, running the $10/month plan.  If I get
so much traffic that I need to upgrade then I will but, with how small
the packets are when working with gopher protocol, I think $10 will be
more than enough. I chose Fedora 33 because this linode is my
experimental machine.  I use it to study linux filesystems and
admin tasks, and figured it would be fun to use something where I didn't
mind if I broke something so I could just roll it back.  Don't worry;
I make backups before I do anything drastic!

In order to get a custom domain for my gopherhole, I bought a domain on
namecheap.  They give a cheap base rate for the first couple of years,
so I figured I'd buy 2 years of my domain for $10 total and, when the
time comes for renewal, I'll be know how often I actually use the domain
and will get an idea for how much I like namecheap or if I want to use a
different service.

After setting up a machine and buying a domain, I confirmed my info with
ICANN and then went into namecheap and told them to use a custom DNS
server.  I then wrote in the 5 urls that linode uses for DNS servers.
I then went into linode and added a new domain, entered dio9sys.fun and
pointed it at my machine.  Waited about 15 minutes and found that I could
ping dio9sys.fun and it would return the IP address for my machine.  Nice!




INSTALLING GOPHERNICUS - FAILED FIRST ATTEMPT
_____________________________________________

Okay, so now that my node was set up and ready to go, it was just time to
install a gopher server.

I did a search for "gopher server fedora 33" to see if there were any guides
to help out.  There were not any specific to fedora, and pygopherd didn't
have a dnf package to choose from.  However, I did find the gregw/gopher copr
that had, among other things, gophernicus as a gopher server.  I decided that
that would be the server I would use and installed it.

It installed, it had a test page in /var/gopher and.........nothing.

Any time I would try to connect I got "connection refused."

I know for a fact that the connection refused error can mean multiple things:
1. It may mean that the server isn't listening on the right port
2. It may mean that the server is being blocked from listening by the firewall

I figured that, being as how I did the easy thing and installed from a package,
surely it was listening on the right port and set everything up for me!

That was a mistake, but first let's talk about the firewall rules I added.

Firewall rules are pretty easy if you know what to look for.  In Fedora, they
are handled using a service called firewalld.  In order to change firewall
settings, you simply run firewall-cmd with some parameters.

Gopher runs on TCP port 70.  Just to be safe, I tried allowing traffic on both
TCP and UDP port 70 just because a lot of modern services run on both.

In order to do this, I ran the following commands:
sudo firewall-cmd --add-port=70/TCP
sudo firewall-cmd --add-port=70/UDP
sudo firewall-cmd --runtime-to-permanent

The first two commands tell the firewall to open up port 70 to both TCP and UDP
traffic.  The third command tells the firewall to take the settings currently
applied to the firewall and make them permanent.

Of course, before being able to run sudo at all you'll need your user to be in
wheel group, but this is a gopher guide, not a fedora guide, and I trust you
in your ability to learn how to use sudo :)

Okay, firewall changed and....still nothing.  What's going on?

I did some looking and found old support threads from people talking about
having to change settings in their inet.d file to get their gopher server of
choice to listen on port 70.  Only problem is that modern versions of Fedora
run on systemd, not inetd or xinetd.





SUCCESSFUL SECOND TRY - COMPILING GOPHERNICUS FROM SOURCE
_________________________________________________________

Okay, so now that you have seen all the things I did that DIDN'T work, let's
talk about what I did that DID work.

After getting frustrated that I couldn't find modern documentation anywhere
for preinstalled gopher packages, I remembered that the gophernicus github
page has specific instructions for compiling the server from source.

"What the heck," I said to myself.  "This will give me the latest version
anyway and, right now, I'm just spinning my wheels trying to make something
work with no documentation.  What's the worst that could happen?"

WORD TO THE WISE - ALWAYS INSTALL GOPHERNICUS FROM SOURCE

Installing from source was quick.  Installing from source was easy.

Most of all, installing from source gave me the right commands to get
the server listening on port 70.

You see, when you compile you set a flag for what listening service your
computer uses.  In this case I selected systemd.  The make script is
smart and, based on the flags you set, will tell you what commands to run
to get the service started.

In the case of systemd, run the following commands:

sudo systemctl enable gophernicus.socket
sudo systemctl start gophernicus.socket

These two commands will first ENABLE gophernicus to start on startup,
and then will START the service during this session.

After compiling, installing and starting the Gophernicus service, I tried
once more to connect.

Into the web proxy I was using for testing I entered gopher://dio9sys.fun

and.....

"Welcome to Gophernicus!"

IT WORKED!

BUT WHY DOES IT WORK???
---------------------------------------------

This works because systemd communicates with firewalld and, even if
you have a port open, you need a socket to handle the connection.

If you go to /usr/lib/systemd/system/ you'll see a number of socket
files.  gophernicus.socket is a socket file that shows the
description of the service and which ports to listen to.

Fun fact: this is useful for every service.  I copied this socket
file, renamed it and edited it to work for gemini protocol and
that's how I got my gemini capsule up and running!

When you enable the socket file, it creates a system link in
/etc/systemd/system/sockets.target.wants/ and then running the
start command invokes the file so it can actually listen on the port.

If you run into firewall problems, check to make sure you have a socket
file!



So, to recap....





WHAT TO TRY IF YOUR GOPHER SERVER ISN'T WORKING
_______________________________________________

1. Uninstall the package you installed and compile from source
2. Make sure your system is listening on port 70 for gopher traffic
3. Check your firewall; make sure it's not blocking port 70 traffic
4. Check your sockets files; make a socket file and enable if if you
  don't have one.
5. Make sure you have some kind of file in /var/gopher/ so you can see if
  the server is working.
6. If you find that you can't view the files you're hosting, make sure the
  permissions are set right.  I find that running chmod 644 on anything
  that doesn't load works, as it gives you universal read without giving
  universal write.
7. Keep trying.  You'll get there!

Okay, now that it's working...




WHERE TO GO FROM HERE? - HOW TO MAKE A COOL GOPHERHOLE
______________________________________________________

Honestly, this is something I'm still working on.  An easy first step
is to look up the standards for the gophermap file.  That can turn your
text files into full pages with interactive links and formatting.

I found a basic guide on wikipedia to gophermap formatting and then,
for a more in-depth guide, there's a great file on baud.baby that goes
over it. You can find that here:

gopher://baud.baby:70/0/phlog/fs20181102.txt


So, what are you waiting for?  Go out there, spend $20 on a server and a domain
and go show the world what you're made of!