Debian VPS (OpenVZ) Quick Setup

Fix getty processes causing log file growth

Comment out all but the first (tty1) getty entries

vim /etc/inittab
...
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
1:2345:respawn:/sbin/getty 38400 tty1
#2:23:respawn:/sbin/getty 38400 tty2
#3:23:respawn:/sbin/getty 38400 tty3
#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6
...
telinit q

Set IPTables

$ip=*yourip*
$sshport = 22

#echo to /etc/iptables.rules
...
*filter

# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT

# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allows all outbound traffic
# You could modify this to only allow certain traffic
-A OUTPUT -j ACCEPT

# Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
#mysql
-A INPUT -p tcp --dport 3306 -j ACCEPT
#other
-A INPUT -p tcp -m multiport --dport 3128,smtp,9000,submission -j ACCEPT
-A INPUT -p udp -m multiport --dport icpv2,58177 -j ACCEPT

# Allows SSH connections from your home IP
# THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE
-A INPUT -p tcp -m state --state NEW -s $ip --dport $sshport -j ACCEPT

# Allow ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT

# log iptables denied calls (access via 'dmesg' command)
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7

# Reject all other inbound - default deny unless explicitly allowed policy:
-A INPUT -j REJECT
-A FORWARD -j REJECT

COMMIT
...

#echo to /etc/iptables.reload.sh
#Note that this doesn't reset any other tables than the default one (so not NAT etc.)
iptables -F
iptables -X
iptables-restore < /etc/iptables.rules chmod u+x /etc/iptables.reload.sh #echo to /etc/rc.local /etc/iptables.reload.sh

Leave a Reply

Your email address will not be published. Required fields are marked *