Email This List Email This List Print This List Print This List

Set­ting up the basics — web serv­er

Set­ting the Host­name

You’ll need to set your system’s host­name and fully qual­i­fied domain name (FQDN). Your host­name should be some­thing unique. Some people name their serv­ers after plan­ets, philo­soph­ers, or anim­als. Note that the system’s host­name has no rela­tion­ship to web­sites or email ser­vices hos­ted on it, aside from provid­ing a name for the sys­tem itself. Your host­name should not be “www” or any­thing too gen­er­ic.

If you’re unfa­mil­i­ar with Linux, one of the first things you’ll need to learn is how to use nano, a text edit­or included with most dis­tri­bu­tions. To open a file for edit­ing, type nano file.txt where “file.txt” is the name of the file you want to cre­ate or edit. When you’re fin­ished edit­ing, press Control-X and then Y to save the changes.

 

Ubuntu /​ Debi­an

Enter fol­low­ing com­mands to set the host­name, repla­cing hostname with the host­name of your choice:

1
2
echo "hostname" > /etc/hostname
hostname -F /etc/hostname

If it exists, edit the file /etc/default/dhcpcd to com­ment out the SET_HOSTNAME dir­ect­ive:

/​etc/​default/​dhcpcd
1
#SET_HOSTNAME='yes'

Cen­tOS 7 /​ Fedora ver­sion 18 and above

Enter the fol­low­ing com­mand to set the host­name, repla­cing hostname with the host­name of your choice:

1
hostnamectl set-hostname hostname

Cen­tOS 6 /​ Fedora ver­sion 17 and below

Enter the fol­low­ing com­mands to set the host­name, repla­cing hostname with the host­name of your choice:

1
2
echo "HOSTNAME=hostname" >> /etc/sysconfig/network
hostname "hostname"

Slack­ware

Enter the fol­low­ing com­mands to set the host­name, repla­cing hostname with the host­name of your choice:

1
2
echo "hostname" > /etc/HOSTNAME
hostname -F /etc/HOSTNAME

Gentoo

Enter the fol­low­ing com­mands to set the host­name, repla­cing hostname with the host­name of your choice:

1
2
echo "HOSTNAME=\"hostname\"" > /etc/conf.d/hostname
/etc/init.d/hostname restart

Arch Linux

Enter the fol­low­ing com­mand to set the host­name, repla­cing hostname with the host­name of your choice:

1
hostnamectl set-hostname hostname

Update /​etc/​hosts

Next, edit your /etc/hosts file to resemble the fol­low­ing example, repla­cing hostname with your chosen host­name, example.com with your system’s domain name, and 12.34.56.78 with your system’s IP address. As with the host­name, the domain name part of your FQDN does not neces­sar­ily need to have any rela­tion­ship to web­sites or oth­er ser­vices hos­ted on the serv­er (although it may if you wish). As an example, you might host “www​.some​thing​.com” on your serv­er, but the system’s FQDN might be “mars​.somethin​gelse​.com.”

/​etc/​hosts
1
2
127.0.0.1 localhost.localdomain localhost 
12.34.56.78 hostname.example.com hostname

If you have IPv6 enabled on your serv­er, you will also want to add an entry for your IPv6 address, as shown in this example:

/​etc/​hosts
1
2
3
127.0.0.1 localhost.localdomain localhost 
12.34.56.78 hostname.example.com hostname 
2600:3c01::a123:b456:c789:d012 hostname.example.com hostname

The value you assign as your system’s FQDN should have an “A” record in DNS point­ing to your serv­ers IPv4 address. For serv­ers with IPv6 enabled, you should also set up a “AAAA” record in DNS point­ing to your serv­ers IPv6 address. For more inform­a­tion on con­fig­ur­ing DNS, seeAdding DNS Records.

Set­ting the Timezone

You can change your serv­ers timezone to whatever you want it to be. It may be best to set it to the same timezone of most of your users. If you’re unsure which timezone would be best, con­sider using uni­ver­sal coördin­ated time or UTC (also known as Green­wich Mean Time).

Ubuntu /​ Debi­an

Enter the fol­low­ing com­mand to access the timezone util­ity:

1
dpkg-reconfigure tzdata

Arch Linux and Cen­tOS 7

Enter the fol­low­ing com­mand to view a list of avail­able time zones:

1
timedatectl list-timezones

Use the up and down arrows to view all the avail­able time zones. Then, press CTRL‑C to exit the list of time zones.

Enter the fol­low­ing com­mand to set the time zone:

1
timedatectl set-timezone America/New_York

All Oth­er Dis­tri­bu­tions

Manu­ally cre­ate a link from a zone file in /usr/share/zoneinfo to /etc/localtime. You must find the zone file for your timezone. See the examples below for com­mon pos­sib­il­it­ies.

Use only one com­mand (e.g. ln -sf /usr/share/zoneinfo/UTC /etc/localtime) to set the timezone. Do not paste the com­ment (e.g. ## for Universal Coordinated Time) in to your ter­min­al win­dow.

1
2
3
4
5
6
7
ln -sf /usr/share/zoneinfo/UTC /etc/localtime ## for Universal Coordinated Time

ln -sf /usr/share/zoneinfo/EST /etc/localtime ## for Eastern Standard Time

ln -sf /usr/share/zoneinfo/US/Central /etc/localtime ## for American Central

ln -sf /usr/share/zoneinfo/US/Eastern /etc/localtime ## for American Eastern

Check­ing the Time

Now try enter­ing the fol­low­ing com­mand to view the cur­rent date and time accord­ing to your serv­er:

1
date

The out­put should look sim­il­ar to this: Thu Feb 16 12:17:52 EST 2012.

Installing Soft­ware Updates

Now you need to install the avail­able soft­ware updates for your serv­ers Linux dis­tri­bu­tion. Doing so patches secur­ity holes in pack­ages and helps pro­tect your serv­er against unau­thor­ized access.

Installing soft­ware updates on your serv­er is a task that you will need to per­form reg­u­larly in future. If you need help remem­ber­ing, try cre­at­ing a monthly alert with the cal­en­dar applic­a­tion on your desktop com­puter.

Ubuntu /​ Debi­an

Enter the fol­low­ing com­mands to check for and install soft­ware updates:

1
2
apt-get update
apt-get upgrade --show-upgraded

Cen­tOS /​ Fedora

Enter the fol­low­ing com­mands to check for and install soft­ware updates:

1
yum update

Arch Linux

Before you can update the sys­tem, you need to cre­ate entropy, ini­ti­ate pac­man-key and pop­u­late the keyring.

1
2
3
4
haveged -w 1024
pacman-key --init
pkill haveged
pacman-key --populate archlinux

You should now be set to update the sys­tem

1
pacman -Syu

Related Post

admin has written 133 articles