Software Prerequisites: The Apache web server (httpd), FTP (requires xinetd or inetd) and Bind (named) software packages with their dependencies are all required. One can use the rpm command to verify installation:
rpm -q httpd bind bind-chroot bind-utils system-config-bind xinetd vsftpdRPMs added FC2+: system-config-httpd
rpm -q httpd bind xinetd vsftpdA Red Hat 8.0 wu-ftpd RPM may be installed (Newer version 2.6.2 or later with security fix wu-ftpd-2.6.2-11+) or install from source.
rpm -q httpd bind xinetd wu-ftpd
rpm -q apache bind inetd wu-ftpdUse wu-ftpd version 2.6.2 or later to avoid security problems.
rpm -ivh apache2 apache2-prefork bind bind-chrootenv bind-utils vsftpdNote: The apache2-MPM is a generic term for Apache installation options for "Multi-Processing Modules (MPM)s "prefork" or "worker". If you try and only install apache2 you will get the following error:
apache2-MPM is needed by apache2-2.0.53-9Also see Apache.org: MPMs
apt-get install apache2
apt-get install apache2-common
apt-get install apache2-mpm-prefork
apt-get install apache2-utils
apt-get install bind9
apt-get install vsftpd
One should also have a working knowledge of the Linux init process so that these services are initiated upon system boot. See the YoLinux init process tutorial for more info.
| Apache HTTP Web server configuration: |
This tutorial is for the Apache HTTP web server (Version 1.3 and 2.0). See the YoLinux list of Linux HTTP servers for a list of other web servers for the Hyper Text Transport Protocol.
The Apache configuration file is: /etc/httpd/conf/httpd.conf
Web pages are served from the directory as configured by the DocumentRoot directive. The default directory location is:
Apache may be configured to run as a host for one web site in this fashion or it may be configured to serve for multiple domains. Serving for multiple domains may be achieved in two ways:
[Potential Pitfall] The default umask for directory creation is correct by default but if not use: chmod 755 /home/user1/public_html
[Potential Pitfall] When creating new "Directory" configuration directives, I found that placing them by the existing "Directory" directives to be a bad idea. It would not use the .htaccess file. This was because the statement defining the use of the .htaccess file was after the "Directory" statement. Previously in RH 6.x the files were separated and the order was defined a little different. I now place new "Directory" statements near the end of the file just before the "VirtualHost" statements.
For users of Red Hat 7.1, the GUI configuration tool apacheconf was introduced for the crowd who like to use pretty point and click tools.
Files used by Apache:
Start/Stop/Restart scripts: The script is to be run with the qualifiers start, stop, restart or status.
i.e. /etc/rc.d/init.d/httpd restart. A restart allows the web server to start again and read the configuration files to pick up any changes. To have this script invoked upon system boot issue the command chkconfig --add httpd. See Linux Init Process Tutorial for a more complete discussion.
Also Apache control tool: /usr/sbin/apachectl start
Apache Control Command: apachectl:
| start | Start the Apache httpd daemon. Gives an error if it is already running. |
| stop | Stops the Apache httpd daemon. |
| graceful | Gracefully restarts the Apache httpd daemon. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. |
| restart | Restarts the Apache httpd daemon. If the daemon is not running, it is started. This command automatically checks the configuration files as in configtest before initiating the restart to make sure the daemon doesn't die. |
| status | Displays a brief status report. |
| fullstatus | Displays a full status report from mod_status. Requires mod_status enabled on your server and a text-based browser such as lynx available on your system. The URL used to access the status report can be set by editing the STATUSURL variable in the script. |
| configtest -t |
Run a configuration file syntax test. |
Apache Configuration Files:
Basic settings: Change the default value for ServerName www.<your-domain.com>
Giving Apache access to the file system: It is prudent to limit Apache's view of the file system to only those directories necessary. This is done with the directory statement. Start by denying access to everything, then grant access to the necessary directories.
Deny access completely to file system root ("/") as the default:
<Directory />
Options None
AllowOverride None
</Directory>
|
Set default location of system web pages and allow access: (Red Hat/Fedora/CentOS)
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
|
This will allow users to serve content from their home directories under the subdirectory "/home/userid/public_html/" by accessing the URLhttp://hostname/~userid/
LoadModule userdir_module modules/mod_userdir.so
...
...
<IfModule mod_userdir.c>
#UserDir disable - Add comment to this line
#
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disable" line above, and uncomment
# the following line instead:
UserDir public_html # Uncomment this line
</IfModule>
...
...
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
|
<Directory /home/user1/public_html> AllowOverride None order allow,deny allow from all Options Indexes Includes FollowSymLinks </Directory> |
File permissions: The Apache web server daemon must be able to read your web pages in order to feed thier contents to the network. Use an appropriate umask and file protection. This works: chmod ugo+r -R public_html
One may also use groups to control permisions. See the YoLinux tutorial on managing groups.
Ubuntu has broken out the Apache loadable module directives into the directory /etc/apache2/mods-available/. To enable an Apache module, generate soft links to the directory /etc/apache2/sites-enabled/ by using the commands a2enmod/a2dismod to enable/disable Apache modules.
Example:Note: This is the same as manually generating the following two soft links:
[Potential Pitfall]: If the Apache web server can not access the file you will get the error "403 Forbidden" "You don't have permission to accessfile-name on this server." Note the default permissions on a user directory when first created with "useradd" are:
The system enables/disables SELinux policies in the file /etc/selinux/config
SELinux can be turned off by setting the directive SELINUX. (Then reboot the system):
SELINUX=disabled
|
When using SELinux security features, the security context labels must be added so that Apache can read your files. The default security context label used is inherited from the directory for newly created files. Thus a copy (cp) must be used and not a move (mv) when placing files in the content directory. Move does not create a new file and thus the file does not recieve the directory security context label. The context labels used for the default Apache directories can be viewed with the command: ls -Z /var/www
The web directories of users (i.e. public_html) should be set with the appropriate context label (httpd_sys_content_t).
Assign a security context for web pages: chcon -R -h -t httpd_sys_content_t /home/user1/public_html
Options:
Use the following security contexts:
| httpd_sys_content_t | Used for static web content. i.e. HTML web pages. |
| httpd_sys_script_exec_t | Use for executable CGI scripts or binary executables. |
| httpd_sys_script_rw_t | CGI is allowed to alter/delete files of this context. |
| httpd_sys_script_ra_t | CGI is allowed to read or append files of this context. |
| httpd_sys_script_ro_t | CGI is allowed to read files and directories of this context. |
Set the following options: setsebool httpd-option true
(or set to false)
| httpd_enable_cgi | Allow httpd cgi support. |
| httpd_enable_homedirs | Allow httpd to read home directories. |
| httpd_ssi_exec | Allow httpd to run SSI executables in the same domain as system CGI scripts. |
The default SE boolean values are specified in the file: /etc/selinux/targeted/booleans
For more on SELinux see the YoLinux Systems Administration tutorial.
NameVirtualHost XXX.XXX.XXX.XXX <VirtualHost XXX.XXX.XXX.XXX> |
Notes:
NameVirtualHost XXX.XXX.XXX.XXX
NameVirtualHost 192.168.XXX.XXX
<VirtualHost XXX.XXX.XXX.XXX 192.168.XXX.XXX>
...
..
|
<Directory "/var/www/html"> ... This part remains the same .. </Directory> # Default for when no domain name is given (i.e. access by IP address) <VirtualHost *:80> ServerAdmin user1@your-domain.com DocumentRoot /var/www/html ErrorLog logs/error_log TransferLog logs/access_log </VirtualHost> # Add a VirtualHost definition for your domain which was once the system default. <VirtualHost XXX.XXX.XXX.XXX> |
<VirtualHost XXX.XXX.XXX.XXX>
ServerName www.your-domain.com - Note that no aliases are listed
...
...
</VirtualHost>
# Add a VirtualHost definition to forward to your primary URL
<VirtualHost XXX.XXX.XXX.XXX>
ServerName your-domain.com
ServerAlias other-domain.com
ServerAlias www.other-domain.com
Redirect permanent / http://www.your-domain.com.com/
</VirtualHost>
...
..
|
When specifying more domains, they may all use the same IP address or some/all may use their own unique IP address. Specify a "NameVirtualHost" for each IP address.
After the Apache configuration files have been edited, restart the httpd daemon: /etc/rc.d/init.d/httpd restart (Red Hat) or /etc/init.d/apache2 restart (Ubuntu / Debian)
<VirtualHost XXX.XXX.XXX.XXX>
ServerName supercorp.com
ServerAlias www.supercorp.com
ServerAdmin webmaster@localhost
DocumentRoot /home/supercorp/public_html/home
<Directory "/">
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/supercorp/public_html/home>
Options Indexes FollowSymLinks MultiViews
IndexOptions SuppressLastModified SuppressDescription
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /home/supercorp/cgi-bin/
<Directory "/home/supercorp/cgi-bin/">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/supercorp.com-error.log
# Possible values include: debug, info, notice, warn, error,
# crit, alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/supercorp.com-access.log combined
ServerSignature On
</VirtualHost>
|
Man pages:
NameVirtualHost * - Indicates all IP addresses <VirtualHost *> ServerAdmin user0@default-domain.com DocumentRoot /home/user0/public_html </VirtualHost> <VirtualHost XXX.XXX.XXX.101> ServerAdmin user1@domain-1.com DocumentRoot /home/user1/public_html </VirtualHost> <VirtualHost XXX.XXX.XXX.102> ServerAdmin user1@domain-2.com DocumentRoot /home/user2/public_html </VirtualHost> |
<Directory /var/www/cgi-bin> |
NameVirtualHost XXX.XXX.XXX.XXX <VirtualHost XXX.XXX.XXX.XXX> |
You can specify your own web pages instead of the default Apache error pages:
ErrorDocument 404 /Error404-missing.html |
If the appropriate php, perl and httpd RPM's are installed, the default Red Hat Apache configuration and modules will support PHP content. RPM Packages (RHEL4):
Apache configuration:
... |
[PHP]
engine = On
...
...
display_errors = Off
include_path = ".:/php/includes"
...
...
memory_limit = 32M ; Default is typically 8MB which is too low.
...
...
[MySQL]
...
...
mysql.default_host = superserver ; Hostname of the computer
mysql.default_user = dbuser
...
|
Test you PHP capabilities with this test file: /home/user1/public_html/test.php
<?php |
<?
phpinfo();
?>
|
For more info see YoLinux list of PHP information web sites.
The Apache web server daemon (httpd) can be started with the command line option "-f" to specify a unique configuration file for each instance. Configure a unique IP address for each instance of Apache. See the YoLinux Networking Tutorial to specify multiple IP addresses for one NIC (Network Interface Card). Use the Apache configuration file directive Listen XXX.XXX.XXX.XXX, where the IP address is unique for each instance of Apache.
Also see the local online Apache configuration manual: http://localhost/manual/.
GUI configuration tool:

Adding web site login and password protection: See the YoLinux tutorial on web site password protection.
Log file analysis:
Scanning the Apache web log files will not provide meaningfull statistics unless they are graphed or presented in an easy to read fashion. The following packages to a good job of presenting site statistics.
Web site statistic services:
Load testing your server:
Apache Links:
| Log file analysis using Analog: |
Installation:
Configuration file: /etc/analog.cfg
LOGFILE /var/log/httpd/your-domain.com-access_log* http://www.your-domain.com UNCOMPRESS *.gz,*.Z "gzip -cd" SUBTYPE *.gz,*.Z # OUTFILE /home/user1/public_html/analog/Report.html # HOSTNAME "YourDomain.com" HOSTURL http://www.your-domain.com .... ... .. REQINCLUDE pages # Request page stats only ALL ON LANGUAGE US-ENGLISH |
Make Analog images available to the users report: ln -s /usr/share/analog/images/* /home/user1/public_html/analog
Log file location:
| MONTHLY ON | one line for each month |
| WEEKLY ON | one line for each week |
| DAILYREP ON | one line for each day |
| DAILYSUM ON | one line for each day of the week |
| HOURLYREP ON | one line for each hour of the day |
| GENERAL ON | the General Summary at the top |
| REQUEST ON | which files were requested |
| FAILURE ON | which files were not found |
| DIRECTORY ON | Directory Report |
| HOST ON | which computers requested files |
| ORGANISATION ON | which organisations they were from |
| DOMAIN ON | which countries they were in |
| REFERRER ON | where people followed links from |
| FAILREF ON | where people followed broken links from |
| SEARCHQUERY ON | the phrases and words they used... |
| SEARCHWORD ON | ...to find you from search engines |
| BROWSERSUM ON | which browser types people were using |
| OSREP ON | and which operating systems |
| FILETYPE ON | types of file requested |
| SIZE ON | sizes of files requested |
| STATUS ON | number of each type of success and failure |
#!/bin/sh cp /opt/etc/analog-domain1.com.cfg /etc/analog.cfg /usr/bin/analog cp /opt/etc/analog-domain2.com.cfg /etc/analog.cfg /usr/bin/analog ... |
| Measuring Web Server Performance: |
See the YoLinux.com web server benchmarking tutorial.
| FTPd and FTP user account configuration: |
Many FTP programs exist. This example covers the popular vsftpd (Red Hat default 9.0, Fedora Core, Suse) and wu-ftpd (Washington University) program which comes standard with RedHat (last shipped with RedHat 8.0 but can be installed on any Linux system). (RPM: wu-ftpd) There are other FTP programs including proFtpd (supports LDAP authentication, Apache like directives, full featured ftp server software), bftpd, pure-ftpd (free BSD and optional on Suse), etc ...
FTPd and SELinux: To allow FTPd daemon access to users home directories: setsebool -P ftp_home_dir 1
Follow with the command service vsftpd restart
FTPd configuration tutorials:
| vsFTPd and FTP user account configuration: |
The vsFTPd ftp server was first made available in Red Hat 9.0. It has been adopted by Suse and OpenBSD as well. This is currently the recomended FTP daemon for use on FTP servers.
Enable vsftpd:
For more on starting/stopping/configuring Linux services, see the YoLinux tutorial on the Linux init process and service activation.
anonymous_enable=YES - Anonymous FTP allowed by default if you comment this out. Default directory used: /var/ftp
local_enable=YES - Uncomment this to allow local users to log in with FTP.
Must also set SELinux boolean: setsebool -P ftp_home_dir 1
write_enable=YES - Uncomment this to enable any form of FTP write or upload command.
local_umask=022 - Default is 077. Umask 022 is used by most other ftpd's.
#anon_upload_enable=YES - Uncomment to allow the anonymous FTP user to upload files.
|
[Potential Pitfall]: vsftp does NOT support comments on the same line as a directive. i.e.:
user1 |
root |
#%PAM-1.0 |
PAM authentication configuration file: ftpusers
root bin daemon adm lp sync shutdown halt ... ... ... user6 - Users to deny user8 ... ... |
/var/log/xferlog {
# ftpd doesn't handle SIGHUP properly
nocompress
missingok
}
|
Sample vsFTPd configurations:
# Access rights |
# Access rights |
Specify list of local users chrooted to their home directories: /etc/vsftpd/vsftpd.chroot_list
Ubuntu typically: /etc/vsftpd.chroot_list
(Requires: chroot_list_enable=YES)
user1 |
[Potential Pitfall]: Mispelling a directive will cause vsftpd to fail with little warning.
File: .message
A NOTE TO USERS UPLOADING FILES:
File names may consist of letters (a-z, A-Z), numbers (0-9),
an under score ("_"), dash ("-") or period (".") only.
The file name may not begin with a period or dash.
|
Test if vsftp is listening: netstat -a | grep ftp
[root]# netstat -a | grep ftp |
Links:
| WU-FTPd and FTP user account configuration: |
The wu-ftpd FTP server can be downloaded (binary or source) from it's home page at http://wu-ftpd.org.
There are three kinds of FTP logins that wu-ftpd provides:
The file /etc/ftpaccess controls the configuration of ftp.
# Don't allow system accounts to log in over ftp |
Note:
allow-uid user-to-allow
allow-gid group-to-allow
[Potential Pitfall]: Flakey ftp behavior, timeouts, etc?? FTP works best with name resolution of the computer it is communicating with. This requires proper /etc/resolve.conf and name server (bind) configuration, /etc/hosts or NIS/NFS configuration.
File /home/user1/public_html/etc/pathmsg:
A NOTE TO USERS UPLOADING FILES: |
The whole point of the chroot directory is to make the user's home directory appear to be the root of the filesystem (/) so one could not wander around the filesystem. Configuration of /etc/ftpaccess will limit the user to their respective directories while still offering access to /bin/ls and other system commands used in FTP operation.
As root:
cd /home/user1
mkdir public_html
chown $1.$1 public_html
touch .rhosts - Security protection
chmod ugo-xrw .rhosts
|
#%PAM-1.0 |
service ftp |
/var/log/xferlog {
|
| FTP Pitfalls: |
If you get the following error:
ftp> ls
227 Entering Passive Mode (208,188,34,109,208,89)
ftp: connect: No route to host
ftp> passiveThis toggles passive mode on and off. When on, FTP will be limited to ports specified in the vsftpd configuration file: vsftpd.conf with the parameters pasv_min_port and pasv_max_port
Passive mode on.
# cat /etc/sysconfig/iptables-config | grep ip_nat_ftp
IPTABLES_MODULES="ip_conntrack_ftp"
# cat /etc/sysconfig/iptables-config | grep ip_nat_ftp
IPTABLES_MODULES="ip_nat_ftp"
FTP will change ports during use. The ip_conntrack_ftp module will consider each connection "RELATED". If iptables allows RELATED and ESTABLISHED connections then FTP will work. i.e. rule: /etc/sysconfig/iptables
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
[user1@nodex ~]$ ftp node.domain.com Connected to XXX.XXX.XXX.XXX. 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (XXX.XXX.XXX.XXX:user1): 331 Please specify the password. Password: 500 OOPS: cannot change directory:/home/user1 Login failed. ftp> bye |
This is often a result of SELinux preventing the vsftpd process from accesing the user's home directory. As root, grant access with the following command:
setsebool -P ftp_home_dir 1
Followed by: service vsftpd restart
Test your vsftpd SELinux settings: getsebool -a | grep ftp
allow_ftpd_anon_write --> off allow_ftpd_full_access --> off allow_ftpd_use_cifs --> off allow_ftpd_use_nfs --> off allow_tftp_anon_write --> off ftp_home_dir --> on ftpd_disable_trans --> off ftpd_is_daemon --> on httpd_enable_ftp_server --> off tftpd_disable_trans --> off |
| FTP Linux clients: |
| Basic user security: |
When hosting web sites, there is no need to grant a shell account which only allows the server to have more potential security holes. Current systems can specify the user to have only FTP access with no shell by granting them the "shell" /sbin/nologin provided with the system or the "ftponly" shell described below. The shell can be specified in the file /etc/passwd of when creting a user with the command adduser -s /sbin/nologinuser-id
[Potential Pitfall]: Red Hat 7.3 server with wu-ftp server 2.6.2-5 does not support this configuration to prevent shell access. It requires users to have a real user shell. i.e. /bin/bash It works great in older and current Red Hat versions. If it works for you, use it, as it is more secure to deny the user shell access. You can always deny telnet access. You should NOT be using this problem ridden version of ftpd. Use the latest wu-ftpd-2.6.2-11 which supports users with shell /opt/bin/ftponly
[Potential Pitfall]: Ubuntu Dapper/Hardy - Setting the shell to the preconfigured shell /bin/false will NOT allow vsftp access. One must create the shell "ftponly" as defined below to allow vsftp access with no shell.
Change the shell for the user in /etc/passwd from /bin/bash to be /opt/bin/ftponly.
...
user1:x:502:503::/home/user1:/opt/bin/ftponly
...
|
Create file: /opt/bin/ftponly.
Protection set to -rwxr-xr-x 1 root root
with the command: chmod ugo+x /opt/bin/ftponly
Contents of file:
#!/bin/sh
#
# ftponly shell
#
trap "/bin/echo Sorry; exit 0" 1 2 3 4 5 6 7 10 15
#
Admin=root@your-domain.com
#System=`/bin/hostname`@`/bin/domainname`
#
/bin/echo
/bin/echo "********************************************************************"
/bin/echo " You are NOT allowed interactive access."
/bin/echo
/bin/echo " User accounts are restricted to ftp and web access."
/bin/echo
/bin/echo " Direct questions concerning this policy to $Admin."
/bin/echo "********************************************************************"
/bin/echo
#
# C'ya
#
exit 0
|
The last step is to add this to the list of valid shells on the system.
Add the line /opt/bin/ftponly to /etc/shells.
Sample file contents: /etc/shells
/bin/bash
/bin/bash1
/bin/tcsh
/bin/csh
/opt/bin/ftponly
|
An alternative would be to assign the shell /bin/false or /sbin/nologin which became available in later releases of Red Hat, Debian and Ubuntu. In this case the shell /bin/false or /sbin/nologin would have to be added to /etc/shells to allow them to be used as a valid shell for FTP while disabling ssh or telnet access.
For more on Linux security see the: YoLinux.com Internet web site Linux server security tutorial
| Domain Name Server (DNS) configuration using Bind version 8 or 9: |
Two of the most popular ways to configure the program Bind (Berkeley Internet Domain software) to perform DNS services is in the role of (1) ISP or (2) Web Host.
When resolving IP addresses for a domain, Internic is expecting a "Primary" and a "Secondary" DNS name server. (Sometimes called Master and Slave) Each DNS name server requires the file /etc/named.conf and the files it points to. This is typically two separate computer systems hosted on two different IP addresses. It is not necesary that the Linux servers be dedicated to DNS as they may run a web server, mail server, etc.
Note on Bind versions: Red Hat versions 6.x used Bind version 8. Release 7.1 of Red Hat began using Bind version 9 and the GUI configuration tool bindconf was introduced for those of you that like a pretty point and click interface for configuration.
Installation Packages:
| named.conf | Primary/Secondary DNS server configuration. (See default file /usr/share/doc/bind-9.X.X/sample/etc/named.conf) |
/etc/ | /var/named/chroot/etc/ |
| named.root.hints | Configuration for recursive service. Required for all zones. (See default file /usr/share/doc/bind-9.X.X/sample/etc/named.root.hints) |
/etc/ | /var/named/chroot/etc/ |
| named | Red Hat system variables. | /etc/sysconfig/ | no change |
| rndc.key | Primary/Secondary DNS server configuration. | /etc/ | /var/named/chroot/etc/ |
| Zone files | Configuration files for each domain. Create this file to resolve host name internet queries i.e. define IP address of web (www) and mail servers in the domain. | /var/named/ | /var/named/chroot/var/named/ |
Debian / Ubuntu:
| named.conf named.conf.options named.conf.local |
Primary/Secondary DNS server configuration. | /etc/bind/ | /var/bind/chroot/etc/bind/ |
| rndc.key | Primary/Secondary DNS server configuration. | /etc/ | /var/bind/chroot/etc/ |
| Zone files | Configuration files for each domain. | /var/bind/data/ | /var/bind/chroot/var/bind/data/ |
Simple example: (no views)
options { - Ubuntu stores options in /etc/bind/named.conf.options
version "Bind"; - Don't disclose real version to hackers
directory "/var/named"; - Specified so relative path names can be used. Full path names still allowed.
allow-transfer { XXX.XXX.XXX.XXX; }; - IP address of secondary DNS
recursion no;
auth-nxdomain no; - conform to RFC1035. (default)
fetch-glue no; - Bind 8 only! Not used by version 9
};
zone "localhost" {
type master;
file "/etc/bind/db.local";
};
zone "0.0.127.in-addr.arpa" {
type master;
file "/etc/bind/db.127";
};
zone "your-domain.com"{ - Ubuntu separates the zone definitions into /etc/bind/named.conf.local
type master; - Specify master, slave, forward or hint
file "data/named.your-domain.com";
notify yes; - slave servers are notified when the zone is updated.
allow-update { none; }; - deny updates from other hosts (default: none)
allow-query { any; }; - allow clients to query this server (default: any)
};
zone "your-domain-2.com"{
type master;
file "data/named.your-domain-2.com";
notify yes;
};
|
BIND Views: The BIND naming service can support "views" which allow various sub-networks (i.e. private internal or public external networks) to have a different domain name resolution result.
Typical Red Hat Enterprise 5 example: (Bind 9.3.4 with three "views")
options
{
directory "/var/named"; // the default
dump-file "data/cache_dump.db";
statistics-file "data/named_stats.txt";
memstatistics-file "data/named_mem_stats.txt";
};
logging
{
// By default, SELinux policy does not allow named to modify the /var/named
// directory, so put the default debug log file in data/ :
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view "localhost_resolver"
{
// This view sets up named to be a localhost resolver ( caching only nameserver ).
// If all you want is a caching-only nameserver, then you need only define this view:
match-clients { localhost; };
...
};
view "internal"
{
// This view will contain zones you want to serve only to "internal" clients
// that connect via your directly attached LAN interfaces - "localnets" .
// For local private LAN. Not covered in this tutorial.
// Delete this view if web hosting with no local LAN.
match-clients { localnets; };
...
};
key ddns_key
{
algorithm hmac-md5;
secret "use /usr/sbin/dns-keygen to generate TSIG keys";
};
view "external"
{
// This view will contain zones you want to serve only to "external"
// public internet clients. This is covered below.
match-clients { any; };
...
..
};
|
Default configuration files: Red Hat may supply the default configuration in: /usr/share/doc/bind-9.X.X/sample/etc/named.conf
view "localhost_resolver": If supporting a caching DNS server (not required to support a web domain) you will also need the files:
view "external": (master) - details -
view "external"
{
/* This view will contain zones you want to serve only to "external" clients
* that have addresses that are not on your directly attached LAN interface subnets:
*/
match-clients { any; };
match-destinations { any; };
allow-transfer { XXX.XXX.XXX.XXX; }; - IP address of secondary DNS
recursion no;
// you'd probably want to deny recursion to external clients, so you don't
// end up providing free DNS service to all takers
// all views must contain the root hints zone:
include "/etc/named.root.hints";
// These are your "authoritative" external zones, and would probably
// contain entries for just your web and mail servers:
zone "your-domain.com" {
type master;
file "/var/named/data/external/named.your-domain.com";
notify yes;
allow-update { none; };
};
// You can also add the zones as a separate file like they do in Ubuntu by adding the following statement
include "/etc/named.conf.local";
};
|
DNS key:
Use the following command /usr/sbin/dns-keygen to create a key. Add this key to the "secret" statement as follows:
key ddns_key
{
algorithm hmac-md5;
secret "XlYKYLF5Y7YOYFFFY6YiYYXyFFFFBYYYYFfYYYJiYFYFYYLVrnrWrrrqrrrq";
};
|
Man Pages:
Forward Zone File: /var/named/named.your-domain.com
$TTL 604800 - Bind 9 (and some of the later versions of Bind 8) requires $TTL statement. Measured in seconds. This value is 7 days.
your-domain.com. IN SOA ns1.your-domain.com. hostmaster.your-domain.com. (
2000021600 ; serial - Many people use year+month+day+integer as a system. Never greater than 2147483647 for a 32 bit processor.
86400 ; refresh - How often secondary servers (in seconds) should check in for changes in serial number. (86400 sec = 24 hrs)
7200 ; retry - How long secondary server should wait for a retry if contact failed.
1209600 ; expire - Secondary server to purge info after this length of time.
86400 ) ; default_ttl - How long data is held in cache by remote servers.
IN A XXX.XXX.XXX.XXX - Note that this is the default IP address of the domain. I put the web server IP address here so that domain.com points to the same servers as www.domain.com
;
; Name servers for the domain
;
IN NS ns1.your-domain.com.
IN NS ns2.your-domain.com.
;
; Mail server for domain
;
IN MX 5 mail - Identify "mail" as the node handling mail for the domain. Do NOT specify an IP address!
;
; Nodes in domain
;
node1 IN A XXX.XXX.XXX.XXX - Note that this is the IP address of node1
ns1 IN A XXX.XXX.XXX.XXX - Optional: For hosting your own primary name server. Note that this is the IP address of ns1
ns2 IN A XXX.XXX.XXX.XXX - Optional: For hosting your own secondary name server. Note that this is the IP address of ns2
mail IN A XXX.XXX.XXX.XXX - Identify the IP address for node mail.
IN MX 5 XXX.XXX.XXX.XXX - Identify the IP address for mail server named "mail".
;
; Aliases to existing nodes in domain
;
www IN CNAME node1 - Define the webserver "www" to be node1.
ftp IN CNAME node1 - Define the ftp server to be node1.
|
MX records for 3rd party off-site mail servers:
your-domain.com. IN MX 10 mail1.offsitemail.com.
your-domain.com. IN MX 20 mail2.offsitemail.com.
|
Initial configuration: Note that Red Hat may supply the default zone configuration in: /usr/share/doc/bind-9.X.X/sample/var/named/
options { - Ubuntu stores options in /etc/bind/named.conf.options
version "Bind"; - Don't disclose real version to hackers
directory "/var/named";
allow-transfer { none; }; - Slave is not transfering updates to anyone else
recursion no;
auth-nxdomain no; - conform to RFC1035. (default)
fetch-glue no; - Bind 8 only! Not used by version 9
};
zone "localhost" {
type master;
file "/etc/bind/db.local"; - Ubutu: /etc/bind/db.local, Red Hat: /var/named/named.local
};
zone "0.0.127.in-addr.arpa" {
type master;
file "/etc/bind/db.127";
};
zone "your-domain.com"{
type slave;
file "named.your-domain.com"; - Specify slaves/named.your-domain.com for RHEL4/5 chrooted bind
masters { XXX.XXX.XXX.XXX; }; - IP address of primary DNS
};
zone "your-domain-2.com"{
type slave;
file "named.your-domain-2.com";
masters { XXX.XXX.XXX.XXX; };
};
|
view "external": (slave)
view "external"
{
match-clients { any; };
match-destinations { any; };
allow-transfer { none; }; - Slave does not transfer to anyone, slave receives
recursion no;
include "/etc/named.root.hints";
zone "your-domain.com" {
type slave;
file "/var/named/slaves/external/named.your-domain.com";
notify no; - Slave does not notify, slave is notified by master
masters { XXX.XXX.XXX.XXX; }; - State IP of master server
};
};
|
Slave Zone Files: These are transfered from master to slave and chached by slave. There is no need to generate a zone file on the slave.
Additional Information:
[Potential Pitfall]: Ubuntu dapper/hardy - Path names used can not violate Apparmor security rules as defined in /etc/apparmor.d/usr.sbin.named. Note that the slave files are typically named "/var/lib/bind/named.your-domain.com" as permitted by the security configuration.
[Potential Pitfall]: Ubuntu dapper/hardy - Create log file and set ownership and permission for file not created by installation:
[Potential Pitfall]: Error in /var/log/messages:
| transfer of 'yolinux.com/IN' from XXX.XXX.XXX.XXX#53: failed while receiving responses: permission denied |
| file "slaves/named.your-domain.com"; |
Bind Defaults:
query-source address * port 53;
query-source-v6 port 53;
|
After the configuration files have been edited, restart the name daemon.
Bind zone transfers work best if the clocks of the two systems are synchronised. See the YoLinux SysAdmin Tutorial: Time and ntpd
File: /var/named/named.your-domain.com This is created for you by Bind on the slave (secondary) server when it replicates from Primary server.
DNS GUI configuration:

Must install packages:
host node.domain-to-test.com your-nameserver-to-test.domain.com
or
Test the name server with the nslookup command in interactive mode:
nslookup
> server your-nameserver-to-test.domain.com > node.domain-to-test.com > exit
Test the MX record if appropriate:
nslookup -querytype=mx domain-to-test.com
OR
host -t mx domain-to-test.com
Test using the dig command:
dig @name-server domain-to-query
OR
dig @IP-address-of-name-server domain-to-query
Test your DNS with the following DNS diagnostics web site: DnsStuff.com
logging {
channel bindlog {
file "/var/log/bindlog" versions 5 size 1m; - Keep five old versions of the log-file (rotates logs)
print-time yes;
print-category yes;
print-severity yes;
};
/* If you want to enable debugging, eg. using the 'rndc trace' command,
* named will try to write the 'named.run' file in the $directory (/var/named).
* By default, SELinux policy does not allow named to modify the /var/named directory,
* so put the default debug log file in data/ :
*/
channel default_debug {
file "data/named.run";
severity dynamic;
};
category xfer-out { bindlog; }; - Zone transfers
category xfer-in { bindlog; }; - Zone transfers
category security { bindlog; }; - Approved/unapproved requests
// The following logging statements, panic, insist and response-checks are valid for Bind 8 only. Do not user for version 9.
category panic { bindlog; }; - System shutdowns
category insist { bindlog; }; - Internal consistency check failures
category response-checks { bindlog; }; - Messages
};
|
The following example uses the Red Hat RPM bind-8.2.3-0.6.x.i386.rpm. Applies to Bind version 9 as well.
The latest RedHat bind updates run the named as user "named" to avoid a lot of earlier hacker exploits. To chroot the process is to create an even more secure environment by limiting the view of the system that the process can access. The process is limited to the chrooted directory assigned.
The chroot of the named process to a directory under a given user will prevent the possibility of an exploit which at one time would result in root access. The original default RedHat configuration (6.2) ran the named process as root, thus if an exploit was found, the named process will allow the hacker to use the privileges of the root user. (no longer true)
Named Command Sytax:
named -u user -g group -t directory-to-chroot-to
Example:
named -u named -g named -t /opt/named
When chrooted, the process does not have access to system libraries thus a local lib directory is required with the appropriate library files - theoretically. This does not seem to be the case here and as noted above in chrooted FTP. It's a mystery to me but it works???? Another method to handle libraries is to re-compile the named binary with everything statically linked. Add -static to the compile options. The chrooted process should also require a local /etc/named.conf etc... but doesn't seem to???
Script to create a chrooted bind environment:
#!/bin/sh cd /opt mkdir named cd named mkdir etc mkdir bin mkdir var cd var mkdir named mkdir run cd .. chown -R named.named bin etc var
|
cp -p /etc/named.conf etc cp -p /etc/localtime etc cp -p /bin/false bin echo "named:x:25:25:Named:/var/named:/bin/false" > etc/passwd echo "named:x:25:" > etc/group touch var/run/named.pid if [ -f /etc/namedb ] then cp -p /etc/namedb etc/namedb fi mkdir dev cd dev # Create a character unbuffered file. mknod -m ugo+rw null c 1 3 cd .. chown -R named.named bin etc var
|
Add changes to the init script: /etc/rc.d/init.d/named
#!/bin/bash
#
# named This shell script takes care of starting and stopping
# named (BIND DNS server).
#
# chkconfig: - 55 45
# description: named (BIND) is a Domain Name Server (DNS) \
# that is used to resolve host names to IP addresses.
# probe: true
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /etc/sysconfig/named ] && . /etc/sysconfig/named - Added in Red Hat version 7.1
[ -f /usr/sbin/named ] || exit 0
[ -f /etc/named.conf ] || exit 0
RETVAL=0
start() {
# Start daemons.
echo -n "Starting named: "
daemon named -u named -g named -t /opt/named - Change made here
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/named
echo
return $RETVAL
}
stop() {
# Stop daemons.
echo -n "Shutting down named: "
killproc named
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named
echo
return $RETVAL
}
rhstatus() {
/usr/sbin/ndc status
return $?
}
restart() {
stop
start
}
reload() {
/usr/sbin/ndc reload
return $?
}
probe() {
# named knows how to reload intelligently; we don't want linuxconf
# to offer to restart every time
/usr/sbin/ndc reload >/dev/null 2>&1 || echo start
return $?
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rhstatus
;;
restart)
restart
;;
condrestart)
[ -f /var/lock/subsys/named ] && restart || :
;;
reload)
reload
;;
probe)
probe
;;
*)
echo "Usage: named {start|stop|status|restart|condrestart|reload|probe}"
exit 1
esac
exit $?
|
Note: The current version of bind from the RedHat errata updates and security fixes (http://www.redhat.com/support/errata/) runs the named process as user "named" in the home (not chrooted) directory /var/named with no shell available. (named -u named) This should be secure enough. Proceed with a chrooted installation if your are paranoid.
See:
Chrooted DNS configuration:
Modern releases of Linux (i.e. Fedore Core 3, Red Hat Enterprise Linux 4) come preconfigured to use "chrooted" bind. This security feature forces even an exploited version of bind to only operate within the "chrooted" jail /var/named/chroot which contains the familiar directories:
If building from source you will have to generate this configuration manually:
www0 IN A XXX.XXX.XXX.1
www1 IN A XXX.XXX.XXX.2
www2 IN A XXX.XXX.XXX.3
www3 IN A XXX.XXX.XXX.4
www4 IN A XXX.XXX.XXX.5
www5 IN A XXX.XXX.XXX.6
www IN CNAME www0.your-domain.com.
|
Also see lbnamed: lbnamed load balancing named
Note that the Name registrations policies for the registrars are stated at ICANN.org.
| Web Server Load Balancing: |
Load balancing becomes important if your traffic volume becomes too great for either your server or network connection or both. Multiple options are available for load balancing.
| Using a Linux Virtual Server to Create a Load Balance Cluster: |
You can use a single Linux server to forward requests to a cluster of servers using iptables for IP masquerading and IPVsadm to scale your load. The load balancing server receiving and routing the requests is called the "Linux Virtual Server" (LVS). The LVS receives the requests which are passed to the real servers which process and reply to the request. This reply is forwarded to the client by the LVS.
This feature is available with the Linux 2.4/2.6 kernel. (If compiling kernel: Networking Options + IP: Virtual Server Configuration)
Configuration: This example will load balance http traffic to three web servers and ftp traffic to a fourth server.
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -P POSTROUTING DROPFor more on IP Masquerading, iptables and subnet addresses, see the YoLinux network gateway tutorial.
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
ipvsadm -A -t 66.218.88.103:80 -s wlcCommand directives:
ipvsadm -A -t 66.218.88.103:21 -s wrr
ipvsadm -a -t 66.218.88.103:80 -r 176.168.1.1:80 -mCommand directives:
ipvsadm -a -t 66.218.88.103:80 -r 176.168.1.2:80 -m -w 2
ipvsadm -a -t 66.218.88.103:80 -r 176.168.1.3:80 -m
ipvsadm -a -t 66.218.88.103:21 -r 176.168.1.4:21 -m
Links:
| Managing Web Server Daemons: |
To view if these services are running, type ps -aux and look for the httpd, inetd and named services (daemons). These are background processes necessary to perform the server tasks.
root 681 0.0 0.5 2304 744 ? S Sep09 0:01 named |
| Sys Admin Script: |
Script to prepare an account: (Red Hat/Fedora)
#!/bin/sh
# Author Greg Ippolito
# Requires: /opt/etc/AccountDefaults/pathmsg favicon.ico mwh-mini_tr.gif etc.
# /opt/bin/ftponly
# You must be root to run this script.
#
if [ $# -eq 0 ]
then
echo "Enter user id as a command argument"
else if [ -r /home/$1 ]
then
echo "User's home directory already exists"
else
echo "1) Create user."
adduser -m $1
echo "2) Set user Password."
passwd $1
echo "3) Add read access to user directory so apache can read it."
cd /home
chmod ugo+rx $1
cd $1
echo "4) Create web directories."
mkdir public_html
chown $1.$1 public_html
chcon -R -h -u system_u -r object_r -t httpd_sys_content_t public_html
cd public_html
mkdir images
chown $1.$1 images
chcon -R -h -u system_u -r object_r -t httpd_sys_content_t images
# Block potential for unauthenticated logins
cd ../
touch .rhosts
chmod ugo-xrw .rhosts
echo "5) Create default web page"
sed "/HEADING/s!HEADING!$1!" /opt/etc/AccountDefaults/default-index.html > index.html
cp -p /opt/etc/AccountDefaults/favicon.ico .
cp -p /opt/etc/AccountDefaults/default-logo.gif ./images
cp -p /opt/etc/AccountDefaults/robots.txt .
chown $1.$1 index.html favicon.ico robots.txt
chcon -R -h -t httpd_sys_content_t index.html favicon.ico robots.txt
chcon -R -h -t httpd_sys_content_t images/default-logo.gif
echo "6) Edit /etc/passwd file - change user shell to /opt/bin/ftponly"
cp -p /etc/passwd /etc/passwd-`date +%m%d%y`
sed "/^$1/s!/bin/bash!/opt/bin/ftponly!" /etc/passwd-`date +%m%d%y` > /etc/passwd
#wu-ftp# Requires: /etc/ftpaccess guestuser restrict-uid
#wu-ftp# echo "7) Add user to /etc/ftpaccess file"
#wu-ftp# cp -p /etc/ftpaccess /etc/ftpaccess-`date +%m%d%y`
#wu-ftp# sed "/^guestuser/s!guestuser !guestuser $1 !" /etc/ftpaccess-`date +%m%d%y` > /etc/ftpaccess
#wu-ftp# sed "/^restricted-uid/s!restricted-uid !restricted-uid $1 !" /etc/ftpaccess-`date +%m%d%y` > /etc/ftpaccess
#wu-ftp# echo "guest-root /home/$1/public_html $1" >> /etc/ftpaccess
echo "7) Add user to vsftpd chroot list
cat `echo $1` >> /etc/vsftpd/vsftpd.chroot_list
echo "8) Setting Disk Quotas to default 50Mb limit:"
# Use user johndoe as a prototype.
edquota -p johndoe $1
echo "9) Admin Follow-up:"
echo " Modify quota.user if different than default"
echo " Make changes to Bind names services on dns1 and dns2 if necessary"
echo " Change /etc/http/conf/httpd.conf or
echo " add config to /etc/http/conf.d/ if using a new domain name"
echo " Add e-mail aliases to mail server if necessary"
fi
fi
|
FYI: Sample robots.txt files: