Sunday, September 25, 2011

Falling from the cloud

So, for a few reasons, I've decided to try to take more of my identity back inhouse.  I'd outsourced some of my world to Blogger, Github, Facebook and domains hosted by GoDaddy, but, I figured I'd try to pull everything back home.

First up, I need to host my never-updated page back on my own server.  The most logical thing would be to run the Apache that have been integrated into Fedora 15, but, I want to run serveez, which is a GNU webserver that I've worked on a bit.

My network is very simple.  It looks like this:

I didn't have to do anything special to get the DSL Modem to allow traffic to my webserver.

The Router was more complicated.  I want anything trying to connect on port 80 to be forwarded on to the server.  So I used a browser to log into the control panel of the Linksys router.  Under a tab called "applications and gaming" and a section called "single port forwarding" I set the HTTP port 80 to be sent to the internal IP 192.168.1.99.

So why that IP xxx.xxx.xxx.99?  Well that router has its own DHCP server that the laptop and my server have been using when they connect to the router.  And that DHCP starts assigning numbers beginning with 192.168.1.100.  So usually my various computers are assigned IPs between 100 and 103 depending on which one is booted first.  But I need the HTTP traffic to be always forwarded to the server, so I'm going to have to give the server a static IP.

The server is running Fedora 15, so everything is hidden from the user and it is impossible to change anything without intensive google-fu.  But to change the network, run the command nm-connection-editor.  There I edited my wired IPv4 connection to "manual" mode instead of DHCP mode, entered the static IP, netmask, etc.  I found the address for the nameserver from the router's control panel.

Then, I had to figure out how to disable the firewall on port 80.  The magic command there was system-config-firewall-tui.  That brought up a firewall wizard.  Under the 'customize' section, I was allowed to disable the firewall for www port 80.

I used dyn.com's free service to make a temporary domain for my server.  Basically, you just create an account, choose a temporary hostname (something like blahblahblah.dyndns-home.com), have dyn's website tell you what your public IP is, and then connect that IP to your temporary hostname.

Then I kicked off the webserver, and was able to see my hello world web page.  Sweet.

But we're still not done.  Two more things have to happen.  The webserver needs to come up automatically when the computer boots, and a script needs to be in place to poll your public IP and inform Dyn whenever it changes.  When you have a DSL connection, you public IP probably changes every day as well as each time you reboot.

To get the webserver to boot on startup, you need to add it to the startup scripts.  Unfortunately Fedora has moved to the overly complicated and opaque systemd.  So to do that, I'd first have to get systemd to kick off serveez.

I created a file named serveez.service and saved it into /usr/local/share/systemd/system

[Unit]
Description=Serveez HTTP Daemon

[Service]
Type=forking
ExecStart=/usr/local/bin/serveez --daemon --cfg-file=/usr/local/etc/serveez-mg/serveez.cfg
PIDFile=/usr/local/var/serveez-mg/serveez.pid

[Install]
WantedBy=multi-user.target
From here, I ran the commands


systemctl enable serveez.service
systemctl start serveez.service

That should be enough to get it kicked off.  I verified that it was working using systemctl status serveez.service


The next chore was to get ddclient to run.  ddclient is a program that checks the IP address of the computer, and if it has changed, it notifies dyn.com, the provider of my dynamic IP hostname.  It wasn't included by default in my distro, so I installed it with yum.  The installed package included a script that gets put into /etc/rc.d, but, it didn't work for me.

I made a simple configuration file and put in into /etc/ddclient.conf


syslog=yes
mail=root
cache=/tmp/ddclient.cache
pid=/var/run/ddclient.pid
use=web, web=checkip.dyndns.com/, web-skip='IP Address'
protocol=dyndns2
login=XXXXXXX
password=XXXXXXX
XXXXXX.dyndns-home.com

Obviously your DynDNS login, password, and the hostname at the bottom line would change for your setup.

And to have this kick off automatically, I had to make yet another systemd service file: ddclient.service

[Unit]
Description=ddclient dyndns.com dynamic ip updater

[Service]
Type=forking
ExecStart=/usr/sbin/ddclient -daemon 900
PIDFile=/usr/local/var/ddclient.pid

[Install]
WantedBy=multi-user.target

Pfft. And that basically got Serveez up and running on my box. But, enough stupidity for one Sunday.