Ernest G. Wilson II's FreeBSD
8.0 "UNIX" Installation Pages
"Many people want to learn UNIX. Here is a
complete guide using
some of the most popular software packages in the world!"
The instructions on these
pages contain nearly everything you need to:
Setup a full blown
FreeBSD server that includes
Apache
(the UNIX web server platform),
MySQL
(the open source SQL database and web based management),
Perl with
many useful modules,
FreeTDS
(allows Perl / UNIX to talk to Microsoft and Sybase SQL
Servers),
Net-SNMP (SNMP trap receiver logging service and SNMP
tool set), PHP
(scripting language preferred by many web based
applications),
phpMyAdmin (web based MySQL administration),
Samba (allows UNIX machines to talk with "Windows" based
machines),
SFTP, SSH and many more popular UNIX tools! These
instructions are the result of years of tinkering, enjoy!
FreeBSD is at the heart of
many popular things you already know!
pfSense - FreeBSD-based firewall tailored for use as
a firewall and router
You will want an SSH / X11 client to perform
steps in Section II and beyond from your Windows PC, I like
free
Xming / Putty!
If you need to copy files to a functional FreeBSD
server that does not have networking, here are some
basic CD commands: # Mount the CDRom to make it usable by the
operating system mount_cd9660 /dev/acd0c /cdrom # Take a look at the files on your CD cd /cdrom
ls # Copy files of your choice,
here are some basic examples:
cp /cdrom/*.tar.gz /usr/src/
cp /cdrom/MyFile.tar.gz /tmp/MyFile.tar.gz # Unmount the CDRom (optional) umount /cdrom
Users operating from behind a company firewall can
use a proxy # Set the environment variable:
http_proxy=http://MyCorporateProxyServer:8080 # Export the variable into your shell to
make it usable from the "Bash" shell: export http_proxy # Download files via the Internet from
command line using "fetch": fetch
http://www.SomeServer.com/SomeFile.tar.gz # Other Shells: Other than my favorite
(Bash) make need to set the environment variable in another manner: setenvhttp://MyCorporateProxyServer:8080 # Note: You could set it more permanently
by editing a file:
vi /etc/make.conf:
HTTP_PROXY= http://proxy.example.net:8080/
FTP_PROXY= http://proxy.example.net:8080/ # The space after the equal sign is required
Note: These instructions are designed to be
followed in order!
Each new instruction set
and section builds on previous carefully planned out steps.
I. The Basics (Get a basic system online laying
the foundation for applications)
A. Getting FreeBSD
Start by downloading the installation software
of your choice:
High Speed (broadband) Internet connection and CD Recorder (and
blank CDRom media) required: a.) Recommended: Network Install (for the brave and the lazy people like
me, this may be the only ISO you will ever need if you have high
speed Internet!):
FreeBSD 8.0 Boot Only -
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/8.0/8.0-RELEASE-i386-bootonly.iso
Save these ISO files some place you will remember later!
Using your favorite CD burning software, write
(burn) each of these files to a blank CD. WARNING: Make sure that you don't
just copy these files to a CD!
There files are special "ISO" disk images, meaning you need to
"write the image" back to CD, not just copy it to a CD.
For example:
Using a free software package like CD Burner XP Pro
- From the "File" menu, choose "Write ISO
to CD"
- Select each ISO (one at a time per blank
CD) that you downloaded earlier
and click "Write Disc"
You can of course use your favorite CD writing software.
(This was just a quick example using free CD Recording software)
For anyone having trouble downloading the ISO
files or burning them to CD:
Head over to the FreeBSD Mall and purchase an official copy! http://www.freebsdmall.com
B. Installing FreeBSD
Section 1 - Physical connection to local keyboard and
monitor required
(Plug in the CPU, monitor, keyboard and network
cable and we can get started)
#
Run Portsnap
/usr/sbin/portsnap fetch
/usr/sbin/portsnap extract
/usr/sbin/portsnap update # Get updated ports by running this
combination command periodically (updates the source
code in the /usr/ports directory, not any actually
installed ports themselves)
/usr/sbin/portsnap fetch &&
/usr/sbin/portsnap update
# Install
Bash Shell
cd /usr/ports/shells/bash
make install clean distclean # Edit the password file with "vipw"
(which uses "vi"
commands to edit) and set root's shell
to use bash (vipw
is a special "vi"
for the password
file "pw"):
vipw
# Manually change / edit the "shell" for root from:
/usr/bin/sh
to: /usr/local/bin/bash
# Install SSH Server - Secure Shell Protocol Suite
(secure remote administration)
cd /usr/ports/security/openssl
make install clean distclean # Compile & Install
- Making sure to "overwrite" the base on the command
line and GUI cd /usr/ports/security/openssh-portable make install -DOPENSSH_OVERWRITE_BASE clean
distclean # Also make sure you select
overwrite base in the GUI # Edit /etc/rc.conf so OpenSSH will start at boot
time vi /etc/rc.conf
# Backup the example original sshd_config
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup # Edit sshd_config (You can do more if you like,
this is just a nice start)
vi
/etc/ssh/sshd_config
# Edit /etc/rc.conf - Here is an nice starting
configuration that you can edit for your needs!
vi /etc/rc.conf
# Reboot and start working remotely via SSH
shutdown -r now
Section 2 - Network connection to the server is required
(Unless this build is a workstation you can
leave the server room and perform these steps remotely from
your office)
To work remotely use your favorite SSH client -
Need a free SSH and X Windows
client?
Example: ssh YourServerIP
-l YourUsername (enter your password to
log in) Then type:
su (and enter the root password to become
root)
Setting up a comfortable user friendly shell
environment
# Log in as root to make these changes
#
Setting up an "/opt" directory
# ATTENTION: I install major
applications into /opt (Just like Windows has "C:\Program Files" I
use "/opt" in FreeBSD) # Note: No need
to do a separate dedicated partition for /opt since we can "symlink"
it to /usr/opt # You should only need to do this once and only if you don't
already have a /opt directory
ln -sv /usr/local/opt /opt
cd /usr/local
mkdir opt
chmod -R 755 /opt
chmod -R 755 /usr/local/opt # Test it out, these commands should now
take you to the same place since /opt is symbolically linked to
/usr/opt now
cd /opt
cd /usr/local/opt
#
Setting up a "/opt/scripts" directory as a central locations for
shared scripts
cd /opt
mkdir scripts
chmod a+r /opt/scripts
chmod a+x /opt/scripts
cd /opt/scripts
pwd
# An
"auto export DISPLAY" script to make remote X11 apps via SSH easy! # Change to the scripts directory cd /opt/scripts # Edit / create a new script
vi setdisplay.sh
# Set the script executable
chmod a+x
/opt/scripts/setdisplay.sh # Check the output
/opt/scripts/setdisplay.sh
# You should see something like IPAddress:0.0 or Hostname:0.0
# This script is designed to work inside the .profile in the next
section
# The sole purpose is to automate the environment variable of:
# export DISPLAY=ipaddress:0.0
#
Setting up your ".profile" to customize your bash shell environment # Change to root's home directory
cd /root # Edit your .profile (you can replace the
generic default with this new stuff)
vi .profile
# Note: Each user account should fix up their
unique .profile in their home directory
# vi /usr/share/skel/dot.profile
#
Setting up "/etc/motd" for a
custom "message of the day"
vi /etc/motd
# Make sure everyone can motd
chmod a+r /etc/motd
touch /etc/COPYRIGHT
#
Setting up "/etc/ssh/banner" for
a custom "message of the day" # Add a line to the bottom of your sshd_config
vi /etc/ssh/sshd_config
# Edit / create the banner
vi /etc/ssh/banner
# Make sure everyone can read the banner
chmod a+r /etc/ssh/banner
# You will need to restart sshd or simply reboot
for these changes to take effect
# Reduce boot menu from 10 seconds to 3 seconds
vi /boot/defaults/loader.conf
autoboot_delay="3"
# Install Xterm - So you
can "pop" (open) multiple windows after you SSH cd /usr/ports/x11/xterm
make install clean distclean
# Enable Linux in
FreeBSD - Enable compatibility with Linux based
programs
more /usr/ports/UPDATING
cd /usr/ports/emulators/linux_base-f10
make install clean distclean
# Add Linux startup variables to your system startup
vi /etc/rc.conf
# Add procfs to your fstab - simply copy and paste this line to the
very bottom of the file (fstab is your File System Table) # Note:
Some Linux emulated software needs linprocfs part to
work!
vi /etc/fstab
#Install FreeBSD
Compatibility - Enable compatibility with
previous versions of FreeBSD
# FreeBSD 4x Binary Compatibility
cd /usr/ports/misc/compat4x
make install clean distclean
# FreeBSD 5x Binary Compatibility
cd /usr/ports/misc/compat5x
make install clean distclean
# FreeBSD 6x Binary Compatibility
cd /usr/ports/misc/compat6x
make install clean distclean
# FreeBSD 7x Binary Compatibility
cd /usr/ports/misc/compat7x
make install clean distclean
Section 3 - Tune the operating system and
environment
FreeBSD under VMware (Optional - Only needed if you are running
FreeBSD inside VMware)
Compile FreeBSD Kernel
(Optional - Re-compile a custom kernel tuned for your hardware
+ adds Kernel firewall options!)
vi /etc/make.conf
cd /usr/src/sys/i386/conf
# If you don't have that directory with code, go get it using
sysinstall tool:
# sysinstall --> configure --> Distributions --> src --> sys
# Make a copy of the GENERIC kernel file
and edit the copy
(Typically copy it to your computer's name)
cd /usr/src/sys/i386/conf
cp GENERIC VMwareFreeBSD8
# Learn about the hardware found on the
machine you are about to compile (see what was detected etc.)
dmesg | more
# Edit your new configuration file (adds,
removes, comment stuff out etc.) # Comment (#) out all unwanted options
(refer to kernel config as your guide) example (then save and exit):
# Here are
some options you will need (and want) built-in to your kernel -
Add these: vi
/usr/src/sys/i386/conf/VMwareFreeBSD
# Also:
You may now see messages in /var/log/messages like this:
# Aug 15 19:54:44 nms kernel: Connection attempt to TCP
127.0.0.1:111 from 127.0.0.1:864 flags:0x02
# Since you probably don't have RPC running for NFS use on TCP port
111 you can ignore these.
# If you had RPC running, you wouldn't see these "log in vain"
messages.
# "Log in vain" messages show connection attempts on ports where you
do not currently have services running # Note:
Webmin's rule editor breaks the rule file - it
forgets to put "add" starting each line
Software RAID1 Mirror
(Optional - Only needed if you have dual hard drives and want RAID1 using gmirror)
# Boot up and log in as root
# Set security to allow these changes sysctl kern.geom.debugflags=16
# Create the new mirror gmirror label -v -b round-robin gm0 /dev/ad4
# Edit the /etc/fstab adding mirror and replacing all ad with gm vi /etc/fstab
# Edit /boot/loader.conf
vi /boot/loader.conf
# Reboot
shutdown -r now
# Add the second disk to the mirror
gmirror insert gm0 /dev/ad6
# Check the status
gmirror status
gmirror list
# Reboot and verify operation
shutdown -r now
gmirror status
gmirror list
# Note: If you lock yourself out because of a typo
in the fstab, do this to get read/write edit control: mount -u
mount -a -t ufs
swapon -a
vi /etc/fstab
FreeBSD Update
- (Optional) Not desired
if you compiled your own kernel above - Tracks the FreeBSD security branches
# FreeBSD Update is a system for automatically building,
distributing, fetching, and applying binary security updates for
FreeBSD
/usr/sbin/freebsd-update fetch
/usr/sbin/freebsd-update install
# Quick updates run this periodically
freebsd-update fetch && freebsd-update install
Section 4 - Update and secure the operating system
# Kick off a portsnap
update again! /usr/sbin/portsnap fetch &&
/usr/sbin/portsnap update
# Update installed Ports
automatically
# Portmanager utility for upgrading all installed ports (use this after you
run portsnap)
cd /usr/ports/ports-mgmt/portmanager
make install clean distclean
# Upgrade all installed ports! Run this
periodically!
/usr/local/bin/portmanager -u
# Sample config file if you need to make exceptions or exclusions
during automatic updates
# /usr/local/etc/portmanager/pm-020.conf.SAMPLE
# Enable the
FreeBSD Vulnerability Database using "portaudit"
cd /usr/ports/ports-mgmt/portaudit
make install clean distclean
# Run portaudit for the first time
/usr/local/sbin/portaudit -Fda
/usr/local/etc/periodic/security/*portaudit
# NOTE: portaudit will automatically run each day scheduled via cron
now
# Process
Accounting - a security method in which an
administrator may keep track of system resources used
# Create the accounting file and activate it
touch /var/account/acct
accton /var/account/acct
# Enable accounting startup at boot time by adding a line to the
rc.conf
vi /etc/rc.conf
# Test out accounting and useful commands
sa
lastcomm
lastcomm ls
Hardening
FreeBSD - Increase system security prior to
going into production
# We only need one (1) "temp"
directory on our system and that should be /tmp
rm -R /var/tmp/
ln -s /tmp /var/tmp
# Make
the console more secure by prompting for the root password going
into single user mode
vi /etc/ttys
console none unknown off
insecure
# Increase SSH security by adding or uncommenting a
few lines in the sshd_config
vi /etc/ssh/sshd_config
Protocol 2
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 2m
PermitRootLogin no
# WARNING:
PermitRootLogin no requires that you have a normal user account and
use "su"
StrictModes yes
MaxAuthTries 3
PermitEmptyPasswords no
PrintLastLog yes
UsePrivilegeSeparation yes
UseDNS yes
# WARNING: UseDNS yes means all of your hosts must
be in DNS with forward / reverse correct!
# Switch new
passwords to use blowfish instead of md5 and increase password
security in general
echo "crypt_default=blf" >> /etc/auth.conf
# Edit login.conf and edit and add a few lines to the default
section
vi /etc/login.conf
:passwd_format=blf:\
:minpasswordlen=9:\
:mixpasswordcase=true:\
:passwordtime=90d:\
:idletime=30:\
:accounted=true:\
:autodelete=90d:\
:warnpassword=14d:\
# Put the changes to login.conf into effect
/usr/bin/cap_mkdb /etc/login.conf
# MCrypt
cd /usr/ports/security/mcrypt
make install clean
distclean
#
Portupgrade (not used by Ernie, but
nice to have just in case)
cd /usr/ports/ports-mgmt/portupgrade
make install clean
distclean
#
Portmaster (not used by Ernie, but
nice to have just in case)
cd /usr/ports/ports-mgmt/portmaster
make install clean
distclean
# Useful Network Utilities
- Nmap and various other tools every admin should have # nmap
is a powerful network scanning tool that should be a standard item
in your tool box cd /usr/ports/security/nmap
make install clean distclean
# Example:
#
nmap v sV -O -p 21,135,139,445,5800,5900 www.netjunkies.net
#
nmapfe is a frontend GUI for nmap to make life simpler
#
cd /usr/ports/security/nmapfe
#
make install clean
# Example:
#
nmapfe &
#
dnstracer determines where a given Domain Name Server (DNS) gets
its information cd /usr/ports/dns/dnstracer
make install clean distclean
# Example:
#
dnstracer www.netjunkies.net
#
dhcping sends a DHCP request to DHCP server to see if it's up
and running cd /usr/ports/net/dhcping
make install clean distclean
# Example:
#
dhcping -v 172.28.0.10
#
echoping tests performances of a remote host by sending it TCP
"echo" (or other protocol) packets cd /usr/ports/net/echoping
make install clean distclean
# Example:
#
echoping -h / www.netjunkies.net:80
# fping is
meant to be used in scripts and its output is easy to parse cd /usr/ports/net/fping
make install clean distclean
# Examples:
#
fping -g 172.28.0.0/24
#
fping -a -g 172.28.0.0/24
# hping is a
command-line oriented TCP/IP packet assembler/analyzer cd /usr/ports/net/hping
make install clean distclean
# Example:
#
hping --scan 1-1024 -S 172.28.0.10
# ngrep
can be used to debug various plain text protocols like HTTP and FTP
etc. cd /usr/ports/net/ngrep
make install clean distclean
# Example:
#
ngrep port 80
#
netcat is the tcp/ip "Swiss Army knife" cd /usr/ports/net/netcat
make install clean distclean
# Examples:
#
nc -v www.netjunkies.net 80 (and type: GET / HTTP/1.0)
#
nc -v www.netjunkies.net 80 < get.txt
#
ipmitools for a simple command-line interface to Baseboard
Management Controller (BMC) cd /usr/ports/sysutils/ipmitool
make install clean distclean
# Example:
# ipmitool -I lan -H 172.28.0.12 -f passfile chassis power status
#
tcpview a tcpdump front end GUI cd /usr/ports/net/tcpview
make install clean distclean
# Example:
# tcpview &
#
trafshow cd /usr/ports/net/trafshow
make install clean distclean
# Example:
# trafshow
#
Putty cd /usr/ports/security/putty
make install clean distclean
#
Pancho cd /usr/ports/net-mgmt/pancho/
make install clean distclean
#
Rancid
- Cisco "diff" tool cd /usr/ports/net-mgmt/rancid/
make install clean distclean
# Notes:
http://www.joe-ma.co.za/page.php?9
# For further configuration information please look at
# /usr/local/share/rancid/README.
# If you are upgrading from the previous version of rancid look at
# /usr/local/share/rancid/UPGRADING.
# If you would like to set up Rancid to be browseable from Web,
# you need to install devel/cvsweb or devel/viewvc.
# For rancid looking-glass copy the actual CGIs (located at
# /usr/local/libexec/rancid/{lg.cgi lgform.cgi}) to your cgi-bin.
#
WireShark cd /usr/ports/net/wireshark
make install clean distclean
# Lynx cd /usr/ports/www/lynx
make install clean distclean
cd #
wgetpro is also for retrieving files, but has advanced
capabilities like pulling a file out of a stream
# v1.3 has vulnerabilities and should not be on a production server
#
cd /usr/ports/ftp/wgetpro/
#
make install clean
# Example:
# wpro mms://win30ny.audiovideoweb.com/avwebdsnywin3147/bush.wmv
# Kick off a portsnap one
last time! /usr/sbin/portsnap fetch &&
/usr/sbin/portsnap update
# Kick off a portmanager
upgrade one last time!
/usr/local/bin/portmanager -u
II. Setting the Stage (Prerequisites for a useable application
server):
# Perl CPAN Shell - A very nice
way to add Perl modules to your system # The CPAN shell is a very effective and methodic
way to add perl modules to your system.
# This is the advised and best method to use if your machine can
connect to the Internet.
# Configure the CPAN Shell
/usr/bin/perl -MCPAN -e shell
yes
install Bundle::CPAN
yes
yes
yes
exit <PRESS ENTER when asked>
exit
# Exit and relaunch the CPAN shell
once or twice to verify basic operation (Choose "no" if it asks you
for detailed config) /usr/bin/perl -MCPAN -e shell
exit
# CPAN shell commands to know
? <--
Display Help Menu
reload cpan <-- Reloads CPAN interface
i /DBD/ <-- Searches for any module with
"DBD" in the name
install DBI <-- Installs module "DBI"
# Add a few modules the hard way via source!
# mime-construct cd /usr/src
fetch http://search.cpan.org/CPAN/authors/id/R/RO/ROSCH/mime-construct-1.9.tar.gz
tar xvf mime-construct-1.9.tar.gz
cd mime-construct-1.9
perl Makefile.PL
make
make install
# Also get the "Timezone Update":
http://java.sun.com/javase/downloads/index.jsp
# Download: "JDK US DST Timezone Update Tool - 1_3_25" to obtain the
time zone update file:
# tzupdater-1_3_25-2009u.zip (old was:
tzupdater-1_3_15-2009g.zip)
# Put this file into your:
/usr/ports/distfiles
# Also get the "Java Cryptography Extension (JCE) Unlimited
Strength Jurisdiction Policy Files 6":
http://java.sun.com/javase/downloads/
# Obtain the JCE policy file
# jce_policy-6.zip
# Put this file into your:
/usr/ports/distfiles
# Java 1.5
cd /usr/ports/java/diablo-jdk15
make install clean distclean
# Java 1.6
cd /usr/ports/java/diablo-jdk16
make install clean distclean
# Eclipse
# cd /usr/ports/java/eclipse/
#
make install clean distclean
# Webmin - A web based interface for UNIX Admins to control the
server # SSL Perl module /usr/bin/perl -MCPAN -e shell
install Net::SSLeay
install Authen::PAM
exit
# Webmin
cd /usr/ports/sysutils/webmin
make install clean distclean
# Run the setup script and set a
password
/usr/local/lib/webmin/setup.sh
# Edit /etc/rc.conf and add
webmin_enable="YES"
vi /etc/rc.conf
# Usermin cd /usr/ports/sysutils/usermin
make install clean distclean
# Run the setup script and set a
password
/usr/local/lib/usermin/setup.sh
# Edit /etc/rc.conf and add
usermin_enable="YES"
vi /etc/rc.conf
# Test Webmin
https://YourServerIP:10000 # Test Usermin
https://YourServerIP:20000
# GNUPG cd /usr/ports/security/gnupg
make install clean distclean
III. Server Applications (The reason for existing!):
# Edit
two (2) files to mimic FreeBSD "Ports" installation vi
/usr/src/httpd-?.?.??/include/httpd.h
# findDEFAULT_ERRORLOG
and change logs/error_log to
/var/log/httpd-error.log
vi /usr/src/httpd-?.?.??/include/scoreboard.h
# findDEFAULT_SCOREBOARD
and change logs/apache_runtime_status
to /var/run/apache_runtime_status
# Create “rc” scripts to start at boot time
(Although this example is a source install, these scripts are from
the FreeBSD Ports and work as designed): vi
/usr/local/etc/rc.d/apache22
vi
/usr/local/etc/rc.d/htcacheclean
#
Make the startup scripts executable:
chmod +x /usr/local/etc/rc.d/apache22
chmod +x /usr/local/etc/rc.d/htcacheclean
# Edit the "httpd.conf" and add at the very bottom of the conf file vi
/usr/local/etc/apache22/httpd.conf
# Edit the "httpd.conf" to suit your needs, at least
change the variables: vi
/usr/local/etc/apache22/httpd.conf User www
Group www ServerAdmin
you@example.com
cd /usr/ports/www/mod_perl2
make install clean distclean
# Edit the "httpd.conf" and add the new perl
module to load, at the very bottom of the conf file vi
/usr/local/etc/apache22/httpd.conf
or
# Change to the /tmp
directory not your normal source dir! cd /tmp
# Adding a "Real" HTTPS / SSL ability to
your Apache Web Server:
http://slacksite.com/apache/certificate.php
$12.99/yr =
http://www.godaddy.com/Compare/gdcompare_ssl.aspx?isc=sslqgo001c cd
/usr/local/etc/apache22/ # Generate a key and do not forget the
password openssl genrsa -des3
-out
joomla.netjunkies.net-server.key
2048 password password # Remove the password from the
file so Apache can start at boot time without needing a human to
be present to type in the password openssl rsa -in
joomla.netjunkies.net-server.key
-out joomla.netjunkies.net-server.pem # Generate a CSR (Certificate Signing
Request) that will be used a
Godaddy or
Thawte or
Verisign
# Note: When you are prompted for
CN (Common Name), make sure you put
the server's FQDN like:
joomla.netjunkies.net
(DO NOT PUT YOUR ACTUAL NAME!) openssl req
-new -key
joomla.netjunkies.net-server.key
-out joomla.netjunkies.net-server.csr # Use the newly created CSR file (and
some ca$h) to buy a SSL certificate!
# You will send them a "csr" file and the will send you a "crt'
file:
joomla.netjunkies.net-server.crt
# Add to httpd.conf vi
/usr/local/etc/apache22/httpd.conf
Listen 209.195.211.6:80
Listen 209.195.211.6:443
Listen 209.195.211.7:80
Listen 209.195.211.7:443
#Listen 80
#Listen 443 SSLMutex sem
SSLRandomSeed startup builtin
SSLSessionCache none
SSLCipherSuite HIGH:MEDIUM
SSLProtocol all -SSLv2
#
UseCanonicalName off
NameVirtualHost 209.195.211.6
NameVirtualHost 209.195.211.7
#
<VirtualHost 209.195.211.6:443>
ServerAdmin YourEmail@gmail.com
DocumentRoot /usr/local/www/data
ServerName joomla.netjunkies.net
ScriptAlias /cgi-bin/ /usr/local/www/cgi-bin/
SSLEngine on
SSLCertificateFile
/usr/local/etc/apache22/joomla.netjunkies.net-server.crt
SSLCertificateKeyFile
/usr/local/etc/apache22/joomla.netjunkies.net-server.pem
SSLCACertificateFile /usr/local/etc/apache22/gd_bundle.crt
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
<Directory "/usr/local/www/data">
allow from all
Options +Indexes
</Directory>
</VirtualHost> # Make the SSL logs directory mkdir
/usr/local/www/data/logs/
chown -R www:www
/usr/local/www/data/logs/ # Restart Apache
/usr/local/etc/rc.d/apache22 restart
sockstat -4
# Adding a "Self
Signed" HTTPS / SSL ability to
your Apache Web Server # Create a certificate authority
cd /root
cp /usr/local/openssl/openssl.cnf.sample /usr/local/openssl/openssl.cnf
openssl genrsa -des3 -out my-ca.key 2048
openssl req -new -x509 -days 3650 -key my-ca.key -out my-ca.crt
# Create a server certificate
# Note: When asked for "CN" do NOT put your name, you must put the
FQDN of the web server!
openssl genrsa -des3 -out nms1-server.key 1024
openssl req -new -key nms1-server.key -out nms1-server.csr
openssl x509 -req -in nms1-server.csr -out nms1-server.crt -sha1 -CA
my-ca.crt -CAkey my-ca.key -CAcreateserial -days 3650
openssl x509 -in nms1-server.crt -text -noout
chmod 0400 *.key
cp nms1-server.crt /usr/local/etc/apache22/nms1.crt
cp nms1-server.key /usr/local/etc/apache22/nms1.key
cp my-ca.crt /usr/local/etc/apache22/cassl.crt
# HTTPS
vi /usr/local/etc/apache22/httpd.conf # Edit:
Listen 192.168.0.161:80
Listen 192.168.0.161:443 # Add to the very bottom of your httpd.conf:
SSLMutex sem
SSLRandomSeed startup builtin
SSLSessionCache none
SSLCipherSuite HIGH:MEDIUM
SSLProtocol all -SSLv2
<VirtualHost 192.168.0.161:443>
DocumentRoot /opt/apache/htdocs
ServerName nms1.yourcompany.com
ServerAdmin YourEmail@yourcompany.com
SSLEngine on
SSLCertificateFile /usr/local/etc/apache22/nms1.crt
SSLCertificateKeyFile /usr/local/etc/apache22/nms1.key
SSLCACertificateFile /usr/local/etc/apache22/cassl.crt
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
SSLCipherSuite HIGH:MEDIUM
SSLProtocol all -SSLv2
<Directory "/opt/apache/htdocs">
SSLOptions +StdEnvVars
Options Indexes
AllowOverride None
Allow from from all
Order allow,deny
</Directory>
</VirtualHost>
# Remove the need to type a passphrase every time
Apache starts:
cp /usr/local/etc/apache22/nms1.key
/usr/local/etc/apache22/nms1.key.withpassphrase
openssl rsa -in /usr/local/etc/apache22/nms1.key.withpassphrase -out
/usr/local/etc/apache22/nms1.key
MySQL - An open source SQL database and web based
management
#
Add
a “mysql” user to your system: (MySQL
should not need to run as root!) pw groupadd mysql pw useradd mysql -n mysql -G
mysql -s /usr/sbin/nologin
# GUI Tools
cd /usr/ports/databases/mysql-gui-tools/
make install clean distclean
# Install the base database
/usr/local/bin/mysql_install_db
# Set permissions to correct owner
chown -R mysql:mysql /var/db/mysql
# Start the server
cd /usr/local ; /usr/local/bin/mysqld_safe &
# Perform basic checks
/usr/local/bin/mysqladmin version
/usr/local/bin/mysqladmin variables
# Set a Password!
/usr/local/bin/mysqladmin -u root password
mysqlpassword
# Secure a
production server
/usr/local/bin/mysql_secure_installation
# Add a "mysql" user with password
and grant that user permission to connect
/usr/local/bin/mysql --user=root --password=mysqlpassword
mysql
GRANT ALL PRIVILEGES ON *.* TO
mysql@localhost
IDENTIFIED BY 'mysqlpassword' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO
mysql@"%" IDENTIFIED BY
'mysqlpassword' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO
root@localhost
IDENTIFIED BY 'mysqlpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
# Add a "mysqltop" user with
no password
and no ability to make changes and only usable via localhost for the
"mtop" CLI tool
/usr/local/bin/mysql --user=root --password=mysqlpassword
mysql
grant super, reload, process on *.* to
mysqltop;
grant super, reload, process on *.* to
mysqltop@localhost;
flush privileges;
exit
#
(Optional) Add
some compatibility for Linux applications by creating a symbolic
links ln -sv
/usr/local/bin/mysqladmin /usr/bin/mysqladmin
ln -sv /usr/local/bin/mysqldump /usr/bin/mysqldump
# (Optional) Run some tests before going into production
(optional)
#
/usr/local/mysql-test/mysql-test-run --force
# cd /usr/local/mysql-test ; perl mysql-test-run.pl
# Report any problems with the /usr/local/bin/mysqlbug script
# Create the "rc" startup script vi /usr/local/etc/rc.d/mysql-server
chmod +x /usr/local/etc/rc.d/mysql-server
vi /etc.rc.conf
mysql_enable="YES"
# Test the "rc" script /usr/local/etc/rc.d/mysql-server restart
/usr/local/etc/rc.d/mysql-server stop
/usr/local/etc/rc.d/mysql-server start
/usr/local/etc/rc.d/mysql-server reload
# Clean up
cd /usr/src/mysql-?.?.*
make clean
# Perform basic checks using the password
/usr/local/bin/mysqladmin --user=root --password=mysqlpassword
ping
/usr/local/bin/mysqladmin --user=root --password=mysqlpassword version
/usr/local/bin/mysqladmin --user=root --password=mysqlpassword variables
/usr/local/bin/mysqladmin --user=mysql
--password=mysqlpassword var
ext stat ver
# Get the free
MySQL
Administrator to optimize and test your settings!
UNTESTED AT THIS POINT DO NOT USE # cd /usr/ports/devel/libglade2
# make install clean
# cd /usr/ports/x11-toolkits/gtkmm24
# make install clean
# cd /usr/ports/databases/mysql-administrator
# make install clean
# cd /usr/src
# fetch http://mysql.he.net/Downloads/MySQLGUITools/mysql-gui-tools-5.0r12.tar.gz
# Performance tuning # Edit /etc/my.cnf vi /etc/my.cnf
# Restart MySQL
/usr/local/etc/rc.d/mysql.sh restart
# Check out your MySQL settings and tune /etc/my.cnf do more as
desired /usr/local/bin/mysqladmin --user=mysql
--password=mysqlpassword var
ext stat ver
Perl with Modules - Scripting language with add-ons to get actual work
done
force install Proc::ProcessTable # CTRL-C if it locks up
install IO::Scalar
install Spreadsheet::ParseExcel
# After installation, exit CPAN shell
exit
# CPAN shell commands to know - just
FYI
? <--
Display Help Menu
reload cpan <-- Reloads CPAN interface
i /DBD/ <-- Searches for any module with
"DBD" in the name
install DBI <-- Installs module "DBI"
# Unzip and Untar
tar xvf SNMP_Session-?.??.tar.gz
# Configure cd SNMP_Session-?.??
perl Makefile.PL
# Compile
make
# Install
make install
# cgi-lib.pl - http://cgi-lib.berkeley.edu # Change to the FreeBSD Ports directory for
cgi-lib.pl cd /usr/ports/www/cgi-lib.pl
# Install make install
# Below is an example CGI
that uses PERL that you can use later after you have Apache
installed
# A basic html page with form fields that submits to a pl script
that reads the values passed to it
# Example web page simple.html
(that calls simple.pl) vi
/usr/local/www/data/simple.html
# Example PERL CGI Script
simple.pl vi
/usr/local/www/cgi-bin/simple.pl
# Edit Apache config to allow cgi and pl files to execute by
editing, un-commenting and adding 3 things
vi
/usr/local/etc/apache22/httpd.conf
Options FollowSymLinks ExecCGI
ScriptAlias /cgi-bin/ "/usr/local/www/cgi-bin/"
AddHandler cgi-script .cgi .pl
# Test out the script
http://YourServer/simple.html
# Clean up cd /usr/ports/www/cgi-lib.pl
make clean distclean
FreeTDS - Library that enables UNIX (via Perl) to talk to Microsoft SQL
Servers (and Sybase) # Change to your desired "source" storage
directory cd /usr/src
# Configure cd freetds-?.??/
./configure --enable-msdblib --with-tdsver=8.0
# Compile & Install
make install clean
# PHP tests for a FreeTDS installation by looking
for files that FreeTDS no longer installs touch
/usr/local/include/tds.h
touch /usr/local/lib/libtds.a
# Change to the source directory cd DBD-Sybase-?.??
# Set a few shell variables temporarily
SYBASE=/usr/local/
export SYBASE
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$SYBASE/lib
export LD_LIBRARY_PATH
# Add the needed environment variables
(so it they survive reboots)
to /etc/rc.local
vi /etc/rc.local
# Fix dbdimp.c before compiling or you will get an
error: >
dbdimp.c:800: error: 'BLK_VERSION_150' undeclared (first use in this
function)
> dbdimp.c:800: error: (Each undeclared identifier is reported only
once
> dbdimp.c:800: error: for each function it appears in.)
# This is really a FreeTDS bug - they define
the CS_VERSION_1xx symbols, but not the corresponding
BLK_VERSION_xxx symbols.
# Create the Makefile - press "Enter" on any
questions to accept default settings
perl Makefile.PL
# Compile
make
# make test
# Install
make install clean
# Optional test script - safe to ignore /
skip this
# Test
a connection to a Microsoft SQL Server
# (You should already have a database called "test" a table
"authors" a field "Name")
# Create a scripts directory if one does not already exist
cd /opt
mkdir scripts
cd /opt/scripts
# Create a script for testing
vi /opt/scripts/my.pl
# Make the script executable
chmod +x /opt/scripts/my.pl
# Run the script
/opt/scripts/my.pl
# Note: Edit freetds.conf to suit your
needs
vi /usr/local/etc/freetds.conf
# UNIXODBC -
http://www.unixodbc.org # Install unixODBC from ports
cd /usr/ports/databases/unixODBC/
make install clean distclean
Net-SNMP - SNMP Trap Receiver (traplogd) logging service + SNMP tool set # Add SNMP
TT cd /usr/ports/net-mgmt/snmptt
make install clean distclean
# Create
some directories and edit the snmptrapd.conf: cd /usr/local/etc
mkdir snmp
vi /usr/local/etc/snmp/snmptrapd.conf
# Create an “rc” script to start at boot time: vi /usr/local/etc/rc.d/snmpd
vi /usr/local/etc/rc.d/snmptrapd
#
Make the startup script executable:
chmod +x /usr/local/etc/rc.d/snmpd
chmod +x /usr/local/etc/rc.d/snmptrapd
# Edit rc.conf to allow remote syslog
messages since you now allow remote traps!
vi /etc/rc.conf
# Edit syslog.conf and add "local7.*" to
the "/var/log/messages" line:
vi /etc/syslog.conf
*.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err;local7.*
/var/log/messages
# Restart Syslog
killall -HUP syslogd
# Notes
# MIBS are here: /usr/local/share/snmp/mibs
# Optional
# Edit snmpd.conf to
suit your needs (Remember to fix /etc/rc.conf - snmpd_enable="YES"
if you want the agent turned on - security risky!)
vi /etc/snmpd.config
# The agent section is not complete yet - use at
your own risk
/usr/local/bin/snmpconf -G
/usr/local/bin/snmpconf -r none -g basic_setup
# Note: This section about the "agent"
(snmpd) is not complete - My intention was to get the "server"
(traplogd) running quickly.
#
Your help is welcomed here!
PHP - Scripting language preferred by many web based applications # Add IMAP c-Client with SSL support to
PHP
cd /usr/src
fetch
ftp://ftp.cac.washington.edu/imap/imap-2007e.tar.gz
tar xvf imap-2007e.tar.gz
cd /usr/src/imap-2007e
make bsf
# Add xmlrpc support to PHP
cd /usr/ports/net/xmlrpc-epi/
make install clean distclean
# Add
some compatibility for Linux applications by creating a symbolic
link ln -sv
/usr/local/bin/php /usr/bin/php
# Edit the
"php.ini" to suit your needs! vi
/usr/local/lib/php.ini
# You may want to add:
/usr/local/lib/php to your php.ini include_path
include_path = ".:/usr/local/lib/php" # Turn on zlib compressed output
#
zlib.output_compression = On
# Tune a few other parameters as you see
fit
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
register_globals = Off
post_max_size = 128M
upload_tmp_dir = /tmp
upload_max_filesize = 128M
sendmail_path = /usr/sbin/sendmail
magic_quotes_gpc = On
session.save_path = "/tmp"
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = On
# Edit httpd.conf to allow "main.php" as a default web page for a
directory listing, add main.php to the end of this line: vi
/usr/local/etc/apache22/httpd.conf
DirectoryIndex index.html
index.php
# Add a "mysqltop" user with
no password
and no ability to make changes and only usable via localhost for the
"mtop" CLI tool
/usr/local/bin/mysql --user=mysql --password=mysqlpassword
mysql
GRANT USAGE ON mysql.* TO 'pma'@'localhost'
IDENTIFIED BY 'pmapassword';
GRANT SELECT (
Host, User, Select_priv, Insert_priv, Update_priv,
Delete_priv,
Create_priv, Drop_priv, Reload_priv, Shutdown_priv,
Process_priv,
File_priv, Grant_priv, References_priv, Index_priv,
Alter_priv,
Show_db_priv, Super_priv, Create_tmp_table_priv,
Lock_tables_priv,
Execute_priv, Repl_slave_priv, Repl_client_priv
) ON mysql.user TO 'pma'@'localhost';
GRANT SELECT ON mysql.db TO 'pma'@'localhost';
GRANT SELECT ON mysql.host TO 'pma'@'localhost';
GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv)
ON mysql.tables_priv TO 'pma'@'localhost';
GRANT USAGE ON mysql.* TO 'pma'@"%"
IDENTIFIED BY 'pmapassword';
GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@"%";
GRANT SELECT (
Host, User, Select_priv, Insert_priv, Update_priv,
Delete_priv,
Create_priv, Drop_priv, Reload_priv, Shutdown_priv,
Process_priv,
File_priv, Grant_priv, References_priv, Index_priv,
Alter_priv,
Show_db_priv, Super_priv, Create_tmp_table_priv,
Lock_tables_priv,
Execute_priv, Repl_slave_priv, Repl_client_priv
) ON mysql.user TO 'pma'@"%";
GRANT SELECT ON mysql.db TO 'pma'@"%";
GRANT SELECT ON mysql.host TO 'pma'@"%";
GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv)
ON mysql.tables_priv TO 'pma'@"%";
GRANT ALL ON phpmyadmin.* TO
pma@localhost IDENTIFIED BY 'pmapassword';
GRANT ALL ON phpmyadmin.* TO
pma@"%" IDENTIFIED BY 'pmapassword';
#
Add
a “cmsftpuser” user to your system: mkdir /usr/home
ln -sv /usr/home /home pw useradd
cmsftpuser -n
cmsftpuser -G
www -s
/usr/local/bin/bash -d
/home/cmsftpuser/
passwd
cmsftpuser
cmsftpuserpassword
cmsftpuserpassword mkdir /home/cmsftpuser/
chown -R
cmsftpuser:www
/home/cmsftpuser/
cd /usr/ports/ftp/proftpd
make install clean distclean
vi /usr/local/etc/proftpd.conf
vi /etc/rc.conf
# Log in to Webmin and fix the proftpd binary location in the
module configuration for ProFTPd
# https://YourServer:100000 # Path to ProFTPD executable:
shutdown -r now
# Joomla!
- Joomla is an award-winning content management system
# Configure some modules after install completes
# The Dcraw module was installed, but needs configuration to be
activated
# The ImageMagick module was installed, but needs configuration
to be activated
# The Multiroot module was installed, but needs configuration to
be activated
# The NetPBM module was installed, but needs configuration to be
activated
# The Nokia Image Upload module was installed, but needs
configuration to be activated
# The URL Rewrite module was installed, but needs configuration
to be activated
TeamSpeak - TeamSpeak is flexible, powerful, scalable
software which enables people to speak with one another over the
Internet
# Install Tripwire cd /usr/ports/security/tripwire make install #
Answer questions and set various passwords (remember these
passwords) when prompted.
#
Setup email addresses for notification as described here: #
http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/s1-tripwire-update-policy.html#S2-TRIPWIRE-EMAIL mv /usr/local/etc/tripwire/twpol.txt /usr/local/etc/tripwire/twpol.txt.original vi /usr/local/etc/tripwire/twpol.txt # Be sure to replace every instance of YourEmail@YourDomain.com with
your actual email address! # Make sure you edit the "HOSTNAME=" variable! (Find out your
hostname from a prompt by typing: hostname )
# Update your site policy /usr/local/sbin/twadmin --create-polfile -S
/usr/local/etc/tripwire/site.key /usr/local/etc/tripwire/twpol.txt
# Create a new database /usr/local/sbin/tripwire --init
# Make sure tripwire runs
daily cp
/usr/ports/security/tripwire/work/tripwire-2.4.1.2-src/contrib/tripwire-check
/etc/periodic/daily/998.tripwire-check chmod +x
/etc/periodic/daily/998.tripwire-check # Edit the default
script and fix two lines! vi
/etc/periodic/daily/998.tripwire-check
# Run tripwire manually as
desired (try it at least once now) /usr/local/sbin/tripwire --check
# Tripwire Reports (*.twr) are kept
here: /var/db/tripwire/report/ # Get a list of your reports ls /var/db/tripwire/report # View a report /usr/local/sbin/twprint -m r --twrfile
/var/db/tripwire/report/<name>.twr
# NOTE:
After you see your first report, you will want
to cleanup tripwire's configuration # to stop checking for
things that don't exist, this means deleting lines in twpol.txt vi /usr/local/etc/tripwire/twpol.txt
# You will then need to update your policy
file and create a new database again /usr/local/sbin/twadmin
--create-polfile -S /usr/local/etc/tripwire/site.key
/usr/local/etc/tripwire/twpol.txt /usr/local/sbin/tripwire --init # Run tripwire manually again and view the new report to verify your
policy is error free /usr/local/sbin/tripwire --check
# Create a MySQL username and password for Cacti /usr/local/bin/mysql --user=root --password=mysqlpassword
mysql
GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword';
GRANT ALL ON cacti.* TO cactiuser@"%" IDENTIFIED BY 'cactipassword';
flush privileges;
exit
# Edit include/config.php and specify the MySQL
user, password and database for your Cacti configuration
#vi /usr/local/www/data/cacti/include/config.php
#$database_default =
"cacti"; #$database_hostname = "localhost"; #$database_username = "cactiuser"; #$database_password = "cactipassword"; #$config['url_path'] = '/cacti/';
#cp
/usr/local/www/data/cacti/include/config.php
/usr/local/www/data/cacti/include/config.php
perl -i.bak -p -e 's/database_username = "\w*";/database_username =
"cactiuser";/ig'
/usr/local/www/data/cacti/include/config.php
perl -i.bak -p -e 's/database_password = "\w*";/database_password =
"cactipassword";/ig'
/usr/local/www/data/cacti/include/config.php
# Add a line to the very bottom of your /etc/crontab file
#vi /etc/crontab
#
echo "# Cacti Poller" >> /etc/crontab
echo "*/5 * * * * root /usr/local/bin/php
/usr/local/www/data/cacti/poller.php > /dev/null 2>&1" >>
/etc/crontab
# Point your web browser to:
http://YourServersIP/cacti/
# Log in the with a
username/password of admin
# You will be required to change this password immediately.
# Make sure to fill in all of the path variables carefully and
correctly on the following screen.
# Set the file permissions in the web directories so the web server
has permission to display them
chown -R www:www /usr/local/www/data
Syslog-NG - Syslog logging service with database support # Install SyslogNG
cd /usr/ports/sysutils/syslog-ng3
make
make install
# Copy the sample configuration file to get you started
cp /usr/local/etc/syslog-ng/syslog-ng.conf.sample /usr/local/etc/syslog-ng.conf
# Edit your startup parameters to enable starting on reboot by
adding two lines
vi /etc/rc.conf
syslog_ng_enable="YES"
syslogd_enable="NO"
syslogd_program="/usr/local/sbin/syslog-ng"
syslogd_flags=""
# Edit the SyslogNG configuration file to suit your needs
vi /usr/local/etc/syslog-ng.conf
#
# *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err /var/log/messages
#
log { source(src); filter(f_notice); filter(f_not_authpriv);
destination(messages); };
log { source(src); filter(f_kern); filter(f_debug);
destination(messages); };
log { source(src); filter(f_lpr); filter(f_info);
destination(messages); };
log { source(src); filter(f_mail); filter(f_crit);
destination(messages); };
log { source(src); filter(f_news); filter(f_err);
destination(messages); };
# HERE IS THE NEW LINE YOU NEED TO ADD
log { source(src); filter(f_local7); destination(messages); };
# Shut down the standard FreeBSD syslogd
kill `cat /var/run/syslog.pid`
# Start the new syslog-ng:
/usr/local/etc/rc.d/syslog-ng start
#
/usr/local/sbin/syslog-ng
# At this point you have swapped out the FreeBSD
built-in Syslog with the newer SyslogNG
ntop - Network application monitoring
and NetFlow tool
Snort - Network intrusion detection
system with Oinkmaster and BASE
Nessus - Network Vulnerability Scanner
Cisco Router Audit Tool - An automated Cisco configuration checking
system
IV. End User Applications for UNIX Workstations
VNC - The vncviewer for connecting to
servers
# Install a basic vncviewer
cd /usr/ports/net/tightvnc
make install clean distclean
# Launch it:
vncviewer
RDesktop - The rdesktop client
for connecting to Microsoft Terminal Service from UNIX
# rdesktop is
an open source client for Windows NT Terminal Server and Windows
2000/2003 Terminal Services
cd /usr/ports/net/rdesktop
make install clean distclean
# Example:
rdesktop 172.28.0.10 &
X Window System - A graphical window based environment for end users
KDE - K Desktop Environment
Firefox
Opera
Open Office
xv - Graphics viewer
Cygwin/X - Display "X11"
applications running in FreeBSD on your Windows workstation
Now that you have a basic FreeBSD UNIX machine:
Head on over to www.NMSWorld.com
to install "Network Management" related software like:
TFTPd, DHCPd, NTop, Nessus, Snort, MRTG, RRDTool, Cacti and more!