Linode is one of the best low-cost Virtual Private Server Hosts available, offering Xen VPS Hosting for a number of popular operating systems. With the release of Ubuntu 12.04 LTS, I felt that it was past time that I upgraded my webserver (the one that runs this website, actually!), and document the little tweaks that I discovered along the way.
What we’re setting up
- Ubuntu 12.04 LTS
- A standard LAMP Stack (Linux, Apache, MySQL, PHP)
- BIND DNS resolution—combined with Virtualmin below, you’ll be able to manage your own domains!
- Linode reverse-DNS resolution
- Virtualmin / Webmin backend server management
Step One: Nameserver Configuration
Log on to your domain registrar and set the nameservers for your domain to
ns1.linode.com ns2.linode.com ns3.linode.com ns4.linode.com ns5.linode.com
We’ll be using Linode’s nameservers as our primary DNS providers because they’ll stay up even when the server is down—taking advantage of redundancy where we can. Since it takes a while for this DNS setting to propagate, this should be done well before any of the other parts of this tutorial.
Step Two: Linode Configuration
Setting up the slave zone
Log into Linode’s dashboard, and add your domain (hereafter referred to as example.com) to the DNS manager. Configure it as “Slave Zone”, and set the master server IP to the IP of your server. This will allow Linode to mirror your server’s DNS settings.
Deploying Ubuntu 12.04 LTS
Deploy Ubuntu 12.04 LTS to your Linode, using the standard “Deploy a Linux Distribution” Option. This will take a short while, and you’ll be asked to supply an administrator password to the system.
Once that’s done, remember to set up the reverse-DNS setting, available in the “Remote Access” tab. This should be set to hostname.example.com, although it isn’t particularly important. Also, enable IPv6; it’s used internally for DNS resolution and will cause issues if disabled.
While you’re here, take note of the IP configuration settings listed. The important values are the public IPs / masks, the default gateway, and the DNS resolvers.
Step Three: Ubuntu Configuration
Alright, now it’s time to actually begin to set up the server. All commands following will be given with the assumption that you are running as the root user. DO NOT use the root account as your primary login; it should be reserved for system administration roles as much as is possible.
Setting up the hostname
Edit /etc/hostname with your favorite editor and set it to your hostname of choice. The file should look something like this:
Afterwards, run the command
$ hostname -F /etc/hostname
to set it across the system.
Then, edit /etc/hosts to enable localhost resolution. The first two lines should look something like this:
127.0.0.1 localhost your-ip-address hostname.example.com hostname
If you have trouble with this, take a look at Linode’s full guide here with regards to setting the hostname and hosts file.
To test, the command
should print the hostname of the server, and
$ hostname -f
should print hostname.example.com (or whatever you set as your Fully Qualified Domain Name).
Setting up a static IP
For some reason, Linode defaults its nodes to use DHCP; this will not work well with our BIND9 DNS server. So, using the settings you got from the Remote Access tab on the Dashboard, configure your /etc/network/interfaces file:
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 #iface eth0 inet dhcp iface eth0 inet static address your-ip-address-here netmask 255.255.255.0 gateway your-gateway-address-here
Edit May 1, 2012: Use Resolvconf directly instead of removing it.
View old version here: Expand
$ apt-get remove resolvconf
Configure the newly-static resolv.conf:
$ cat /etc/resolv.conf domain members.linode.com search members.linode.com nameserver dns-resolver-1-ip-here nameserver dns-resolver-2-ip-here nameserver 127.0.0.1 options rotate
Ubuntu now ships with a dynamic resolv.conf manager called resolvconf, which handles editing /etc/resolv.conf for us. Thus, instead of editing /etc/resolv.conf, we can edit /etc/resolvconf/resolv.conf.d/base
$ cat /etc/resolvconf/resolv.conf.d/base domain members.linode.com search members.linode.com nameserver dns-resolver-1-ip-here nameserver dns-resolver-2-ip-here nameserver 127.0.0.1 options rotate
Now, reload the resolvconf (or restart the server, since you’ve changed networking settings)
$ service resolvconf restart
Further details on resolv.conf and network interface configuration can be found in Linode’s documentation here.
Configuring the timezone
We can just use dpkg-reconfigure for this:
Since Ubuntu is debian-based, the installation of LAMP is remarkably simple:
$ apt-get update $ apt-get install lamp-server^
should do it—just follow the instructions that it gives you.
Installing Virtualmin and Webmin
Unfortunately, since Ubuntu 12.04 LTS just came out, Virtualmin doesn’t officially support it yet, but we can install it anyways!
Start by copying /etc/issue to a backup, so that we can trick Virtualmin into believing it’s installing on Ubuntu 10.04 LTS:
$ cp /etc/issue /etc/issue-bak
Edit /etc/issue, and replace “Ubuntu 12.04 LTS n l” with “Ubuntu 10.04.02 LTS”
Virtualmin depends on an scponly shell which Ubuntu has, for some reason, removed from the Precise Pangolin repositories. Nevertheless, we can just install the version from Oneiric, which works fine:
$ cd /tmp $ wget http://security.ubuntu.com/ubuntu/pool/universe/s/scponly/scponly_4.8-4.1_i386.deb $ dpkg -i scponly_4.8-4.1_i386.deb
Installing virtualmin itself: Virtualmin has kindly provided an install script for us, so we’ll just use that
$ cd /tmp $ wget http://software.virtualmin.com/gpl/scripts/install.sh $ chmod u+x install.sh $ /tmp/install.sh
Now that that’s all done, we can revert our /etc/issue file back to what it should be
$ mv /etc/issue-bak /etc/issue
Setting up the Virtualmin Configuration
Log on to your-ip-address:10000 to access the Virtualmin configuration panel. It should walk you through some initial setup options—you don’t need to change any of these.
After that’s done, go to Virtualmin→System Settings→Server Templates→BIND DNS Domains and find the Additional Manually Configured Nameservers box. Add these lines:
ns1.linode.com ns2.linode.com ns3.linode.com ns4.linode.com ns5.linode.com
Also, make sure that the option “Add sub-domain DNS records to parent’s domain” is set to “Yes”.
This will set up the Linode nameservers as slaves, and allow them to request zone transfers (AXFR and AXFR-style IXFR)
Now, go to Webmin→Servers→BIND DNS Server→Default Zone and set “Notify Slaves of Changes” to “Yes”.
To see if Linode is successfully duplicating your zone, view the syslog and watch for AXFR / IXFR transfers:
$ tail -f /var/log/syslog
BIND will automatically inform Linode when you’ve made a change to your DNS configuration.
Setting up your first Virtual Server
This part is pretty simple: just click “Create Virtual Server” on the Virtualmin dashboard, and give it the domain example.com. The rest should be handled for you.
After it’s been constructed, go to Virtualmin→Server Configuration→DNS Records and add a new A record for hostname.example.com, pointing at the IP Address of your hostname. This will serve as the primary forward-DNS for your server.
Yay! You’ve set up a Ubuntu/Virtualmin-powered Linode, and you’re ready to host a website. Since BIND and Virtualmin are configured to create a new zone for each virtual server, the DNS configuration should be largely automatic—no more needing to set all the A records yourself.
There is one caveat, however: Linode’s Slave DNS Zones are configured NOT to allow subdomains to be controlled by separate DNS zones.
This means that if you want to serve a different website for a domain and its subdomain (“example.com” and “test.example.com”, for example), you will need to configure “test.example.com” as a SUB-SERVER in Virtualmin. Otherwise, Linode will NOT request the DNS records, and you will not be able to access the subdomain.
To configure email virus and spam scanning, take a look at Ubuntu’s official Amavis tutorial here.