Ubuntu Server configuration

Submitted by admindm on Thu, 10/11/2012 - 18:27

Now we have an expensive and time consuming brick in the corner of the room sucking up power its time to make it do something useful. Before we do anything else it would be a good idea to do an update. We do this first in case the update would require us to set something up again or may change how somethings set up. No point doing the same work twice. We also need to set up our network configuration so we can access the server remotely. Once we can get access remotely we can ditch the keyboard.

Log into your server and you should be met by a terminal (for Windows users thats what we call a command prompt). You should also be greeted by some basic resource information, your servers IP as well as a notification of available updates. Ubuntu supplies a database of packages, before runing an update we need to update this list. To do this type

sudo apt-get update

The sudo part tells the server you want to run the command as a root user. You'll be asked for your password and then the server will update its package list. Now you need to actually tell it to update the packages.

sudo apt-get upgrade

You will be asked to confirm the new packages and told how much space they will take up. Most packages take up hardly any space so this shouldn't be much. It also tells you how much will be downloaded, which can be much more than you expect for how little space is used, bear in mind most files are being replaced. I'd imagine you have a fairly good internet package if your contemplating this anyway and you don't need to worry about download limits.

ubuntu server login infoubuntu server update

Now we need a static IP address. Later we are going to forward ports to our server and without a static IP address it may change when we reboot our server or router and break all our port forwarding work. There are two ways to set a static IP address. Most routers allow you to set a static IP address in their LAN configuration pages. You can also set a static IP address on the server itself. I usually do both. That way if I change my router and forget to set the address it will be set by the server. If I reinstall the server and forget to define an IP address then the router will automatically assign the correct one. You can find out how to set static IP addresses for your router at portforward.com but its easier to do this when you forward ports so you only have to log into your router once. To continue we are going to need a text editor. My personal favourite, at least for server side editing, is nano. Nano is very, very basic and that is entirely the point. For anything complex I edit via ftp and use notepad++ but we'll go over that later. The file we need to edit is /etc/network/interfaces. Notice that unlike in a Windows system there is no file extension. You do see file extensions in Linux but typically the file type is identified by the files properties, not its extension. We also need to edit this file as a root user so the command we use is

sudo nano /etc/network/interfaces

ubuntu network configuration

This means edit /etc/network/interfaces with nano as a root user. When you open the file you will notice certain lines start with #. Most file types in Ubuntu use this as a comment. Anything that follows on this line is ignored, its just to help you read the file. You should also notice you have two interfaces. We need to edit eth0. eth0 is basically your LAN port. If you have multiple lan ports you will probably have eth1 and maybe some others depending on your system. We only need to change our primary network interface so we'll concentrate on eth0.

Replace this 

auto eth0
iface eth0 inet dhcp

with this

auto eth0
iface eth0 inet static
address 192.168.0.200
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 192.168.0.1

Then press Ctrl-X to quit. You will be asked if you want to save, press Y for yes then accept the file name by pressing enter. The address can be any address you like on your network. You could just use the address you were assigned automatically. Make sure you set it to an address you know is free. The gateway will most likely be the address of your router. If your not sure what this is then use the command "route". This will show you your routing table most specificaly the IP address of your gateway. Most home routers have a default IP address of 192.168.0.1 or 192.168.1.1. Network needs to match the first 3 numbers of your router followed by a 0. Broadcast needs to match the first 3 numbers of your router followed by 255. For dns-nameservers you can list multiple addresses, but its easier to simply specify your routers address and it will use the same DNS servers as your router.

ubuntu server network configurationubuntu server network configuration

You now need to reboot your server or reset the network interface to apply the changes. 

To reboot the server use

sudo reboot

To only restart the network interface use

sudo ifdown eth0
sudo ifup eth0

ifdown disables your network interface and ifup reenables it. 

Now to test you can access the server via a web browser. Open your favourite web browser and type the IP address you set into the address bar. You should see apache's default landing page. You won't yet be able to access your server from the internet but you should be able to access this page from any device on your local network. Even a mobile phone if your connected by wifi. This is obviously no use at all. We need a web page thats accessible from anywhere in the world. You should also be able to access your server via SSH, more on this later.

Apache landing page

To access your server you need to forward ports in your router to the IP address of your server. What ports you need to forward depends on what you want to access on your server. As an example to access a basic web page over http you need to forward port 80. Once you forward port 80 You will be able to access your landing page from your internet IP address. To find your internet IP address simply type my IP address into Google. It will like your internet IP at the top of the search. There are 1000s of routers out there. If I get requests I wil post an example of my router but as this is likely to only help a few people I suggest you check out portforward.com. On portforward.com you pick out your router model and it shows you how to setup a static IP address and forward ports. It will also tell you the default IP address, username and password of your router. Below is a list of ports I've forwarded and their use. I'll add to the list as I expand the guide. Remember you only need to forward ports to access these services from outside your local network. You should be able to access all these services when in your local network regardless of port forwarding. Also bear in mind some services require a port range or multiple ports. portforward.com will show you how to assign these.

  • 80 - Http, needed to access basic web pages
  • 443 - https, needed to access secure web pages
  • 20,21 - ftp, needed to access your server fia ftp and for ftp download
  • 22 - ssh/sftp, needed to access shh anf for secure ftp
  • 23 - telnet, insecure version of ssh
  • 9987/UDP - teamspeak voice chat
  • 10011/TCP - teamspeak serverquery port
  • 30033/TCP - teamspeak ftp port
  • 2008/TCP - liscence check port