Securing your Linux Server

First off setup your firewall, ubuntu comes with iptables by default.
mkdir /etc/iptables
vi /etc/iptables/rules
Add the following to your /etc/iptables/rules file
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
 
# Accept any related or established connections
-I INPUT  1 -m state --state RELATED,ESTABLISHED -j ACCEPT
-I OUTPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT
 
# Allow all traffic on the loopback interface
-A INPUT  -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
 
# Outbound DNS lookups
-A OUTPUT -o eth0 -p udp -m udp --dport 53 -j ACCEPT
 
# Outbound PING requests
-A OUTPUT -p icmp -j ACCEPT
 
# Outbound Network Time Protocol (NTP) request
-A OUTPUT -p udp --dport 123 --sport 123 -j ACCEPT
 
# Outbound HTTP
-A OUTPUT -o eth0 -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT
 
# Incoming DNS requests
-A INPUT -i eth0 -p udp -m udp --dport 53 -m state --state NEW -j ACCEPT
-A INPUT -i eth0 -p tcp -m udp --dport 53 -m state --state NEW -j ACCEPT
 
# Incoming SSH
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -j ACCEPT
 
COMMIT
Apply the ruleset with a timeout through iptables-apply, and if you lose the connection, fix your rules and try again before continuing.
iptables-apply /etc/iptables/rules
Applying new ruleset... done.
Can you establish NEW connections to the machine? (y/N) y
... then my job is done. See you next time.
Create the file /etc/network/if-pre-up.d/iptables, with the following content. This will automatically load your IPTables rules when you start the server. /etc/network/if-pre-up.d/iptables
#!/bin/bash
iptables-restore < /etc/iptables/rules
Now give it execute permissions, and execute the file to ensure it loads properly.
chmod +x /etc/network/if-pre-up.d/iptables
/etc/network/if-pre-up.d/iptables


How to change your linux username and home dir

This will all have to be done as root, either login as root or sudo su. Change the username and the home folder to the new name that you want.
usermod -l  -d /home/ -m
Change the group name to the new name that you want.
groupmod -n
and your done.


TinyDNS (DJBDNS) Installation

I love DJBDNS. Its fast and secure, and superior to BIND in many ways, imho. You will need to be root for this. First, install the packages:
apt-get install daemontools
apt-get install daemontools-run
apt-get install ucspi-tcp
apt-get install djbdns
Then, add the necessary user accounts:
adduser --no-create-home --disabled-login --shell /bin/false dnslog
adduser --no-create-home --disabled-login --shell /bin/false tinydns
Configuration. Step 1:
tinydns-conf tinydns dnslog /etc/tinydns/ EXTERNAL.IP.ADDRESS
(where EXTERNAL.IP.ADDRESS == your internet IP) Step 2:
mkdir /etc/service ; cd /etc/service ; ln -sf /etc/tinydns/
Start it:
initctl start svscan
Check it:
svstat /etc/service/tinydns
Stop it:
svc -d /etc/service/tinydns
Start it:
svc -u /etc/service/tinydns