Saturday, May 29, 2010

HOW-TO: Harden A Fresh CentOS 5.x Server

SkyHi @ Saturday, May 29, 2010
HOW-TO: Harden A Fresh CentOS 5.x Server


set -ve

# Script to harden a fresh CentOS 4 or 5 base server install, which installs

# any updated packages plus a few useful extras, removes unnecessary

# services and setuid bits, and does a little performance tuning. Running it more than once shouldn't hurt anything.


# Run with:


wget -O- | sh


# Update rpm and yum if possible. (Limit dependencies.)


yum -y install rpm yum

# Installing useful packages


yum -y install joe tcpdump mtr postfix strace zsh gdb perl vixie-cron logrotate

# Removing unnecessary daemons and setuid binaries


yum -y remove squid krb5-workstation cups at rsh sudo isdn4k-utils sendmail \

slocate apmd irda-utils mt-st gpm samba-common sendmail-cf talk \

up2date ypbind yp-tools wvdial lockdev procmail xorg-x11-font-utils \

pam_ccreds gdm bluez-utils yum-updatesd

# Upgrading to latest packages


yum -y upgrade

# Removing unnecessary setuid bits


find / /usr -xdev -type f -perm +04000 | \

grep -vP '^(/bin/(su|ping|traceroute)|/usr/bin/(passwd|chsh|crontab)|/usr/libexec/openssh/ssh-keysign)$' | \

xargs -r chmod ug-s

# Removing unnecessary setgid bits


find / /usr -xdev -type f -perm +02000 | \

grep -vP '^(/usr/sbin/(utempter|postdrop|postqueue)|/usr/bin/ssh-agent)$' | \

xargs -r chmod g-s

# Setting nosuid,nodev on user partitions, noatime on ext2 and ext3


perl -i~ -p -e 's/(\sext[23]\s+)(defaults)(?=\s)/$1$2,noatime/;next if m#\s/(?:usr|bin)?\s#;next unless m#\s(ext[23]|tmpfs|auto)\s#;s/(?<=\s)(defaults(?:,noatime)?)(?=\s

)/$1,nosuid,nodev/' /etc/fstab

# Adding blackhole routes for bogons


[ -f /etc/sysconfig/network-scripts/route-lo ] || cat <<EOF > /etc/sysconfig/network-scripts/route-lo








# Add useful settings to /etc/sysctl.conf


grep -q kernel.panic /etc/sysctl.conf || cat<<EOF >> /etc/sysctl.conf

# Reboot a minute after an Oops


kernel.panic = 60

# Syncookies make SYN flood attacks ineffective


net.ipv4.tcp_syncookies = 1

# Ignore bad ICMP


net.ipv4.icmp_echo_ignore_broadcasts = 1

net.ipv4.icmp_ignore_bogus_error_responses = 1

# Reply to ARPs only from correct interface (required for DSR load-balancers)


net.ipv4.conf.all.arp_announce = 2

net.ipv4.conf.all.arp_ignore = 1


sysctl -p

# Allow any following commands to fail without stopping


set +e

# Shutting down unwanted services


for d in acpid rpcidmapd rpcgssd nfslock netfs portmap avahi-daemon avahi-dnsconfd pcscd bluetooth; do

chkconfig $d off

service $d stop


# Turn on cron-based auto-updates


yum -y install yum-cron

for d in crond yum yum-cron; do

chkconfig $d on

service $d start



Thanks to webicero for creating this guides.

For more informations and guides about harndening and securing your server, you may also read the guides in


Installing suPHP on Centos 5

SkyHi @ Saturday, May 29, 2010
suPHP is a tool that allows PHP scripts to be executed with the permissions of their owners. By not running PHP script using web server’s user rights, suPHP increase the server security.

First install httpd-devel and compiler tools:

yum install httpd-devel gcc gcc-c++ make

Download suPHP source code and extract it

tar -xvzf suphp-0.7.1.tar.gz
cd suphp-0.7.1

Now we compile suPHP

./configure --with-apxs=/usr/sbin/apxs --with-apache-user=apache --with-logfile=/var/log/httpd/suphp_log --with-setid-mode=paranoid --sysconfdir=/etc --with-apr=/usr/bin/apr-1-config --with-php=/usr/bin/php-cgi --enable-SUPHP_USE_USERGROUP=yes

make install

Next create suphp.conf to configure Apache so it will call suPHP for interpreting PHP scripts

nano /etc/httpd/conf.d/suphp.conf

Add this configuration:

LoadModule suphp_module modules/
suPHP_Engine on
AddType application/x-httpd-php .php
&lt;Directory />
suPHP_AddHandler application/x-httpd-php

Save the file and the next step is to disable mod_php configuration as we are now using suPHP

mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.disabled

After we finished with Apache configuration, next we create suphp.conf file which contain suPHP configuration

nano /etc/suphp.conf

and copy this to the new file:

;Path to logfile


;User Apache is running as

;Path all scripts have to be in

;Path to chroot() to before executing script

; Security options

;Check wheter script is within DOCUMENT_ROOT

;Send minor error messages to browser

;PATH environment variable

;Umask to set, specify in octal notation

; Minimum UID

; Minimum GID

After Apache and suPHP is configured, we need to add suPHP_UserGroup option on each virtual hosting we hosted on the server. For example, the virtual host would look like:

DocumentRoot /home/user/public_html
&lt;Directory "/home/user/public_html">
allow from all
Options +Indexes
ErrorLog /var/log/httpd/
LogLevel warn
suPHP_UserGroup user user

"user" should be replaced with the real username on your server who own the PHP scripts. Make sure all file owned by the "user" username otherwise you’ll get 500 error code (Internal Server Error).

Now let's test the configuration

service httpd configtest

if everything is OK, restart the Apache server

service httpd restart

Bookmark and Share
Related Article

yum update script

SkyHi @ Saturday, May 29, 2010

So the other week I have been working on my dedicated box, just to make it a bit easier to work with in the future. One of the things I was trying to understand and learn was yum update and bash scripting. So why not combine the two? Right.. This blog entry is the result, hopefully also of some use to others.

I am on a CentOS 5 (5.2) 32bit Server, and I use yum to automatically update, delete, upgrade, and install packages. This way that’s a bit easier for me to run my server and keep it up to date. For example, when there’s one or more updates you can type yum update, or yum upgrade to get everything. Anyway, look into that if you’re interested.

So once in a while when you log into your box you can do yum upgrade and have it do it’s thing. This should help you fix known bugs, upgrade to newer releases, and fix known security issues. This doesn’t sound like a bad thing.

But when I log into SSH2 I am not a root user, and I am there for other tasks, so it is really easy to forget. And because I don’t trust to have a crontab entry auto upgrade and overwrite config files, etc .. I prefer to actually “be there” when it happens and have the choice to y/n to questions.

What I can do is install a crontab entry that runs a script daily. This script can check if there are updates, and emails me if that’s the case. This way I don’t have to think about it really and it just goes to my Gmail “server” label.

In my crontab I put the following:

0 0 * * * /etc/scripts/checkyum

And the checkyum script looks like this:



# Program: E-mail available yum updates <checkyum>


# Original Author: Matty < matty91 at gmail dot com >

# Updated by Floris for personal use.


# Current Version: 1.2.Floris


# License:

#   This program is distributed in the hope that it will be useful,

#   but WITHOUT ANY WARRANTY; without even the implied warranty of




export PATH

# Locations of binaries






# Who to E-mail with new updates


if [ ! -f ${YUM} ]


echo “Cannot find ${YUM}”

exit 1


if [ ! -f ${MKTEMP} ]


echo “Cannot find ${MKTEMP}”

exit 1


if [ ! -f ${MAIL} ]


echo “Cannot find ${MAIL}”

exit 1


if [ ! -f ${GREP} ]


echo “Cannot find ${GREP}”

exit 1


# Dump the yum results to a safe working file

WORK=`${MKTEMP} /tmp/yum.results.XXXXXX`

${YUM} -e0 -d0 check-update > ${WORK}

# If there are updates available, E-mail them

if [ -s ${WORK} ]


REPORT=`${MKTEMP} /tmp/`

echo “==== The following updates are available for ${HOST} ===” > ${REPORT}

cat ${WORK} >> ${REPORT}

cat ${REPORT} | mail YOUR@EMAIL


# Cleanup temporary files

rm ${REPORT} ${WORK}

There’s nothing else to it, and every so often you get an email that looks like this:

==== The following updates are available for YOUR_SERVER ===

nss_ldap.i386                            253-13.el5_2.1         updates

Which you can ignore, or you can go into the box, and run yum upgrade to process it.

Hm, I likey!


mitigate (D)DoS attacks

SkyHi @ Saturday, May 29, 2010
(D)DoS Deflate is a lightweight bash shell script designed to assist in the process of blocking a denial of service attack. It utilizes the command below to create a list of IP addresses connected to the server, along with their total number of connections. It is one of the simplest and easiest to install solutions at the software level.

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

IP addresses with over a pre-configured number of connections are automatically blocked in the server's firewall, which can be direct iptables or Advanced Policy Firewall (APF). (We highly recommend that you use APF on your server in general, but deflate will work without it.)
Notable Features

It is possible to whitelist IP addresses, via /usr/local/ddos/ignore.ip.list.
Simple configuration file: /usr/local/ddos/ddos.conf
IP addresses are automatically unblocked after a preconfigured time limit (default: 600 seconds)
The script can run at a chosen frequency via the configuration file (default: 1 minute)
You can receive email alerts when IP addresses are blocked.


chmod 0700

if [ -d '/usr/local/ddos' ]; then
 echo; echo; echo "Please un-install the previous version first"
 exit 0
 mkdir /usr/local/ddos
echo; echo 'Installing DOS-Deflate 0.6'; echo
echo; echo -n 'Downloading source files...'
wget -q -O /usr/local/ddos/ddos.conf
echo -n '.'
wget -q -O /usr/local/ddos/LICENSE
echo -n '.'
wget -q -O /usr/local/ddos/ignore.ip.list
echo -n '.'
wget -q -O /usr/local/ddos/
chmod 0755 /usr/local/ddos/
cp -s /usr/local/ddos/ /usr/local/sbin/ddos
echo '...done'

echo; echo -n 'Creating cron to run script every minute.....(Default setting)'
/usr/local/ddos/ --cron > /dev/null 2>&1
echo '.....done'
echo; echo 'Installation has completed.'
echo 'Config file is at /usr/local/ddos/ddos.conf'
echo 'Please send in your comments and/or suggestions to'
cat /usr/local/ddos/LICENSE | less


chmod 0700 uninstall.ddos


CentOS patching --exclude=kernel,kernel-headers

SkyHi @ Saturday, May 29, 2010
In my normal everyday job, I am tasked with managing and maintaining about 30-40 production CentOS servers. Being a security guy, I maintain a pretty rigorous patching routine. However, because these servers are customer production servers, one very important caveat is that I need to do everything I can to minimize customer downtime.

Normally when I patch a server, my routine is:

yum check-update (check what updates are available)

yum -y update (update everything)

And if the list produced by check-update shows the kernel or kernel-headers packages in the list, I promptly reboot the server. This translates into about 5 minutes of downtime for the customer as the server reboots.

So that got me thinking. Is every kernel update critical or can they easily be delayed? So then I stumbled across this excellent plug-in for yum.


Name : yum-changelog
Arch : noarch
Version: 1.1.10
Release: 9.el5.centos
Size : 12 k
Repo : installed
Summary: Yum plugin for viewing package changelogs before/after updating
This plugin adds a command line option to allow viewing package changelog
deltas before or after updating packages.

Perfect! That will allow me to see exactly what is changing with each new version of the kernel. So I install that with:

yum install yum-changelog

Now we can use yum to show us the change log for certain packages. So, if I want to see the change log for the kernel related package, I could run something like:

yum update kernel kernel-headers --changelog

This will produce output similiar to:

Changes in packages about to be updated:

kernel-headers - 2.6.18-92.1.22.el5.x86_64
* Wed Dec 17 06:00:00 2008 Karanbir Singh [2.6.18-92.1.22.el5.centos]
- Roll in CentOS Branding

* Sat Dec 6 06:00:00 2008 Jiri Pirko [2.6.18-92.1.22.el5]
- [misc] hugepages: ia64 stack overflow and corrupt memory (Larry Woodman ) [474347 472802]
- [misc] allow hugepage allocation to use most of memory (Larry Woodman ) [474760 438889]

Ah, ha. As I suspected. Two memory related bugfixes and CentOS branding. Because we are currently not expirencing any memory related issues, this patch does NOT rate as critical and warrent immediate customer downtime. This can be delayed.

So now I can apply the other patches and exclude the kernel upgrades with:

yum update --exclude=kernel,kernel-headers

Now, I have a script that runs nightly on all my CentOS servers. This script gathers nightly statistics, logs entries, etc from my servers and emails it to me. This is pretty much jsut a CentOS port of my old Gentoo Update Script, with some CentOS speficic changes and additional features. The other thing it does, is generate a list (via yum check-update) of all the updates required. So the question now is, now can I get this interactive command to run via an automated script? The easiest way I could come up with is:

echo n | yum update kernel kernel-headers --changelog

Probably not the cleanest way, but does the job very well.


Yum Check or Install Updates Script

SkyHi @ Saturday, May 29, 2010
Here's a quick script that will check yum updates and email you when there are new updates available.

Split into two sections, one script is for all package updates, and the other script is for letting us know if we need to reboot when a new kernel package has been installed.

Script to check for updates:

# checks for yum updates and emails if there are any available
# Eric Thern
# Zoidial Incorporated
# last update:
# Dec 30, 2008

# change this to your email

# no need to change anything below here


$yum check-update >& $yumtmp



case $yumstatus in
# no updates!
exit 0
number=$(cat $yumtmp | egrep '(.i386|.x86_64|.noarch|.src)' | wc -l)
updates=$(cat $yumtmp | egrep '(.i386|.x86_64|.noarch|.src)')
echo "
There are $number updates available on host $hostname at $date

The available updates are:
" | /bin/mail -s "UPDATE: $number updates available for $hostname" $email

# clean up

rm -f /tmp/yum-check-update.*

Script to check kernel (here we use 'ovzkernel' since we're running with an openvz kernel, if you have a stock centos kernel, change this to 'kernel')

latestkernel=$(rpm -q ovzkernel |tail -n1|sed -e 's/kernel-//')

echo "$latestkernel"

if uname -a | grep -qv "$latestkernel"; then
echo "Running Kernel is" `uname -r` "but latest installed rpm is ${latestkernel}" |\
mail -s "UPDATE: ${HOSTNAME} reboot required" $email

Crontab entries:

30 21 * * * /root/bin/ >/dev/null 2>&1
30 21 * * * /root/bin/ >/dev/null 2>&1

Run at 9:30 every night. Change times and paths to suit.


CentOS / RHEL Configure Yum Automatic Update Retrieval and Installation

SkyHi @ Saturday, May 29, 2010

The yum command line tool is used to install and update software packages under RHEL / CentOS Linux server. I know how to apply updates using yum update command line, but I'd like to use cron to manually update packages where appropriate. How do I configure yum to install software patches / updates automatically with cron?

You can use yum-updatesd service provided with CentOS / RHEL servers. However, this service provides a few overheads. You can create daily or weekly updates with the following shell script. Create

  • /etc/cron.daily/ to apply updates one a day.
  • /etc/cron.weekly/ to apply updates once a week.

Sample shell script to update system

A shell script that instructs yum to update any packages it finds via cron:

$YUM -y -R 120 -d 0 -e 0 update yum
$YUM -y -R 10 -e 0 -d 0 update

(Code listing -01: /etc/cron.daily/


  1. First command will update yum itself and next will apply system updates.
  2. -R 120 : Sets the maximum amount of time yum will wait before performing a command
  3. -e 0 : Sets the error level to 0 (range 0 - 10). 0 means print only critical errors about which you must be told.
  4. -d 0 : Sets the debugging level to 0 - turns up or down the amount of things that are printed. (range: 0 - 10).
  5. -y : Assume yes; assume that the answer to any question which would be asked is yes.

Make sure you setup executable permission:
# chmod +x /etc/cron.daily/


Thursday, May 27, 2010

Quickly - how to download a file to the ESX 3.x service console?

SkyHi @ Thursday, May 27, 2010
The VMware ESX 3.x is missing wget package so you can't use wget command to download anything from the Internet as you wish. In spite of wget, the service console provides lwp-* tools which are simple perl scripts based on LWP and URI perl modules and which allow to do some basic tasks around the HTTP protocol.

The tools are part of perl-libwww-perl package. The package is installed by default. The most important tool is lwp-download which you can use for downloading files. Let's check the steps how to download something:
  1. esxcfg-firewall --allowOutgoing
    • allow outgoing connections from service console
  2. lwp-download http://dfn.dl..../apcupsd-3.14.4-1.el3.i386.rpm
    • download apcupsd package
  3. esxcfg-firewall --blockOutgoing
    • return firewall to the initial state
Beside this, the perl-libwww-perl package contains other tools like lwp-mirror, lwp-request and lwp-rget. Check their man pages for their usage.


ILO Setup

SkyHi @ Thursday, May 27, 2010

ILO Setup

ILO – Integrated Lights Out

This is a very cool feature that allows one to manage the server box remotely. Idea is physically you don’t have to be in the data center to manage servers. ILO interface provides exact same interface as you will see when you have connected monitor, keyboard and mouse to each individual server.

Each server comes with default DNS name for ILO web interface (it’s DHCP enabled! so if your network has DHCP IP addresses available, then it will pick up the one for it’s factory default DNS name.)

Default DNS names usually in the pattern ILO<Serial#OfBox>

For example serial id for server is HPPRO1234567, then DNS name to access server using ILO would be ILOHPPRO1234567 and it would be available at http://ILOHPPRO1234567

It comes with default administrator user id / password. This user id/password should be changed immediately in order to make your server secure.


Once you login using with given credentials, four tabs that are available for use are: System Status, Remote Console, Virtual Devices, Administration

Change ILO Administrator password

Go to “Administration” -> “User Administration” -> “Select a User” -> “View / Modify” Also if needed you can create more users and give them selective permissions to manage the server using ILO.

How to recover the ILO password

In a worst case scenario where you forgot the user id/ password for ILO login, then only way to reset the password is by connecting physically to the box. Make sure monitor and keyboard is connected to box and boot the machine.

Press F8 to enter into ILO Configuration. Then go to Users -> Modify user and change the ILO admin password which can help to get back to use ILO again.


Change the ILO DNS name

  • Before you get started, need to get the static ip address and dns name entry configured for this ILO interface.
  • Now login to ILO web interface using default dns name (http://DefaultDNSNAME) using default user id/password if that’s not yet changed. let’s say http://ILOHPPRO1234567)
  • Click on Administration tab -> settings -> network. Then first disable the DHCP.
  • Enter correct values for IP Address, subnet mask and Gateway IP Address that you allocated for new ILO DNS Name in Eman.
  • Enter new iLO 2 Subsystem Name

And click on “Apply” to make changes effective. Following message will be displayed :

Please wait – iLO 2 is being reset with new changes. You will automatically be redirected to the login page in 59 seconds. If an SSL error message is displayed, please restart your browser and re-login.

It will logout you in one or two minutes. Or you can open the new browser session and now try to login using new ilo DNS name. For example http://newdnsname and it should redirect to login screen.

Troubleshooting ILO DNS Name

But for some reasons if you haven’t configured ILO dns correctly, then you may not be able to access the ILO web interface. In this case to debug the configuration, you need to connect that machine physically.

Following are steps:

  • Connect Monitor to this machine (connect to front port, it’s easy!) and have keyboard connection at the back.
  • Power on the machine. Once system start booting… You will see white screen display “HP Proliant Servers ….” After this keep on pressing F8 key to get you into ILO configuration Screen.
  • Now go to Network -> DHCP menu

    * Make sure DHCP is set to OFF (use spacebar to change the settings)

    * Verify ILO name has correct value.
  • Now go to Menu Network -> TCP/IP Go to IP Address selection You can’t change these settings if DHCP is ON Update IP Address to new ILP DNS entry. Also Enter correct values for subnet and default getway.

Save the settings (F10) and exit. Now you should be able to login to ILO interface using new dns name like http://newdnsname

Note NIC Mac address

We have connected the server on LAN port 1. Hence note the value of Port 1 NIC MAC address, we will need this value to do the Linux installation using the PXE boot.

Go to tab “System Status” -> “System Information” -> NIC -> Port 1 NIC MAC address


Simple NAT router for ESX

SkyHi @ Thursday, May 27, 2010


Hi Guys,

I'm looking for a simple virtual appliance that I can deploy to my ESX environment to use as a virtual NAT router / firewall to create an isolated network that I can easily give internet access too.

Basic setup: ESX Host, has 2 vswitches configured: 1 is connected to the physical LAN, the other is isolated. I need an appliance that I can add 2 vNICs to, and attach one to the isolated vSwitch, the other to the LAN, to give the isolated network outbound access (so it can reach the internet).

Anyone have an appliance that I can setup quickly to do so?



I like PFSense, they have a VMWare appliance:

Any VM with routing capabilities will do:

  • Linux with some IPTABLES configuration.
  • FreeBSD with its PF (or IPTABLES again).
  • Windows Server with the built-in RRAS.
  • Even Windows client (XP, Vista, 7) with its built-in Internet Connection Sharing can do that.

If you know some Linux and IPTABLES, it's quite easy to set this up; if you're more Windows-oriented, the Routing and Remote Access Service (built-in in Windows Server since 2000) it's very easy to set up and configure on a (virtual) server with two NICs.



NAT in VMWare vSphere/ESX – In a nut shell

This post is about NATing an ESX VM, but first, why do I need NAT:

The SIP protocol is not NAT oblivious. To traverse NAT our application has to replace the DNS in the SIP message contact header to the external FQDN that the message receiver will be sending responses to (A NAT with static routing configured).

Therefore I needed to test our software in a NAT topology.

In the past, when we used VMWare player/workstation, it had a build-in NAT network. But, unfortunately, the ESX hypervisor does not provide a NATed network option.

Seeking alternatives at VMWare’s appliance marketplace, I found and downloaded the Vyatta’s community edition (VC5) router appliance (also downladble from sourceforge), and comes under the GPL license.

After 3-4 hours – guided by the official quick start guide - I had a working NAT configuration in the ESX. Hurray!

Overall, not a hard nut to crack ;) , though I wish VMWare will wise up and just add an build-in NAT option to vSphere.

Left to do:

Obtain some static IPs, so the config won’t break each time the vm reboots and the DHCP lease expires.

Tip #1:

If you want want to access your NATed VM by RDP/VNC, without setting up extra NAT routing rules, consider adding the VM an additional un-NATed NIC, but when doing so, make sure that the OS routing tables are set to route through the NIC that is NATed.

Tip #2:

This short vyatta user installation report also helped me a bit.

Here’s the complete configuration script I ended up feeding to the appliance console (network topology is similar to the one presented in the Vyatta’s getting stated guide):

Where: is your department’s DNS server is the VMs NATed private IP address (provided by the DHCP).

The script contains a NAT forward rule for VNC (port 5900)

set system host-name vyatta-nat
set interfaces ethernet eth0 address dhcp
set service ssh
set service https
# restart the appliance to switch from console remote desktop to SSH:

#login with user and password
show interfaces

set interfaces ethernet eth1 address


delete service dhcp-server
set service dhcp-server shared-network-name ETH1_POOL subnet start stop
set service dhcp-server shared-network-name ETH1_POOL subnet default-router
set service dhcp-server shared-network-name ETH1_POOL subnet dns-server
show service dhcp-server

set service nat rule 1 source address
set service nat rule 1 outbound-interface eth0
set service nat rule 1 type masquerade
show service nat
show nat rules
set service nat rule 20 type destination
set service nat rule 20 inbound-interface eth0
# use a negative fake address to so that all incoming communication will be nated
#set service nat rule 20 destination address !
#Forward traffic to address
set service nat rule 20 inside-address address
set service nat rule 20 protocol tcp
set service nat rule 20 destination port 5900



SmoothWall Express as NAT on ESXi

It’s odd that ESXi doesn’t come with an NAT implementation. Even more strange is that it’s not easy to find a simple-to-use virtual appliance to fit the gap.

From the VMWare community, there are suggestions on using Freesco or m0n0wall. However, both are not as easy to setup as I like. Finally, I found SmoothWall Express 3.0 VMWare image but there lacks doc on using the image.

Here is a quick setup guide to use the appliance as an NAT server,

  • From ESXi server, create a vSwitch and connect it to host NIC. Add a virtual machine network, say external, to it.
  • Create another vSwitch without NIC. Add a virtual machine network, say protected, to it.
  • Download SmoothWall Express 3.0 VMWare.
  • Extract the VM files.
  • Use VMWare Converter to convert the VM and upload to ESXi server:
    • eth0->connect to protected network
    • eth1->connect to external network

  • Login the SmoothWall VM with account root and password happydays.
  • run setup:
    • Keyboard mapping->us
    • Networking
      • Network configuration type->GREEN + RED
      • Drivers and card assignments: Green->eth0 / Red->eth1
      • Address settings: Green->internal IP / Red->external IP
      • DNS and Gateway settings: for external interface

    • DHCP Server Configuartion
      • Enable it. Add internal address range. DNS is the internal IP in address setting.

  • Update the root/admin/user passwords
  • Connect a Windows VM to the protected network to verify DHCP is working properly.
  • From the Windows VM, browse to https://internal_ip:441.
  • Logon with account admin and the new password you set.
  • Click Maintenance->Update->Update to install patches from mySmoothWall. Reboot afterward.



OpenBSD as a Simple NAT Router

To setup a simple NAT router/firewall using OpenBSD, use these steps as a general guideline. I’m assuming that you have general knowledge of OpenBSD.

First, configure the network interfaces appropriately. Typically, this will involve editing the hostname.<NIC type> file. In a VMware ESX Server environment, OpenBSD uses pcn0 for the first virtual NIC, pcn1 for the second virtual NIC, etc., so the appropriate configuration files would be hostname.pcn0, hostname.pcn1, and so forth.

Next, enable IP forwarding by editing /etc/sysctl.conf and making the following change (the line is present in a default installation, you just need to uncomment it):


Next, we’ll need to enable the OpenBSD packet filter, pf. This is typically done by creating/editing the file /etc/rc.conf.local and making sure the following line is present:


Next, we’ll configure pf for network address translation (NAT) and simple packet filtering. If you’ve never configured pf before, I highly recommend this OpenBSD PF guide; it will introduce you to the functionality of this very powerful packet filtering engine. (Sometimes I wish Mac OS X would switch to using pf.) You configure pf by placing a ruleset into /etc/pf.conf.

Here’s a quick sample ruleset (keep in mind this is based on OpenBSD running as a virtual machine in a VMware environment):

# Set some variables for use later

# Skip all loopback traffic
set skip on lo

# Scrub all traffic
scrub in

# Perform NAT on external interface
nat on $ext_if from $int_if:network -> ($ext_if:0)

# Define default behavior
block in
pass out keep state

# Allow inbound traffic on internal interface
pass quick on $int_if

# Protect against spoofing
antispoof quick for { lo $int_if }

# Allow other traffic
pass in on $ext_if proto tcp to ($ext_if) port ssh flags S/SA keep state
pass in inet proto icmp from $allowed_hosts icmp-type $icmp_types keep state

This is a really, really simple configuration, but it will get the job done. (I did title this “OpenBSD as a Simple NAT Router”, after all.)

For more advanced configurations, I highly recommended reviewing the OpenBSD documentation (which, by the way, is very thorough and very extensive; kudos to the OpenBSD team for their documentation efforts.)


pfSense as router(nat) for ESX Vsphere

SkyHi @ Thursday, May 27, 2010
0 Members and 2 Guests are viewing this topic.
Offline Offline

Posts: 6

View Profile
« on: November 16, 2009, 12:00:07 pm »


I am new bie to Pfsense. I have ESX Server 4 (vsphere) having 2 NIC .
Right Now only 1 NIC is connected to Internet and having PUBLIC IP say
I want to secure Virtual Machine running on it.
What should i know to configure PFsense on ESX Server(Vsphere).

Is there any tutorial or recommendation for it.



Heitor Lessa
Full Member
Offline Offline

Posts: 116

View Profile
« Reply #1 on: November 20, 2009, 05:47:08 am »

HI there,

Actually I´m using pfsense under VMware ESXi with 2 nic*, both internal network and works fine.

What kind doubt do you have exactly?

How to configure 2 nic on pfsense under ESXi?

First you need to know what nic is from internet (public address), on this case will be WAN nic
Second you need to adjust one more nic on "Configuration" --> "Networking" on VMware to add your LAN nic.

To install choose what nic is WAN e what nic is LAN.. for example:

em0 -> LAN
em1 -> WAN

About security, pfsense uses pf firewall and you´ll need to know how to configure policies, rules, nat. But this ... deppends of you.

Anyway, I´m here for any questions about installation and configure under ESX.

Heitor Lessa


Offline Offline

Posts: 6

View Profile
« Reply #2 on: November 20, 2009, 11:12:58 am »

First of all i THANKS for your reply.

I have 2 Virtual Machine on Vmware ESXi and i want to protect it from Pfsense.

I have installed Pfsense on Vmware ESXi with One Physical NIC.

I have assigned em0 to LAN & em1 to WAN Interface.

em0----> Vswitch0 ----LAN Interface. (

em1----> Vswitch0 ----WAN Interface.(

These are my concern.

How can i access WebGUI on WAN Interface ?
Can i used Public IP Address on Lan Interface ?

My Virtual Machine is also on Public Ip ( which i want to protect from Pfsense.



Heitor Lessa
Full Member
Offline Offline

Posts: 116

View Profile
« Reply #3 on: November 20, 2009, 07:41:06 pm »


I have 4 VM under ESXi, but my environment is totally different of yours.

Anyway, answer some questions.

How can i access WebGUI on WAN Interface ?
Yes, it´s possible, for this propose you need to uncheck box "Block Private Addres" IF you need to access from your LAN, IF ELSE you just need allow port 80 on firewall rules or OTHER IF you change the WebGUI port, sure.

Can i used Public IP Address on Lan Interface ?
In LAN Interfaces you configure private ip address and not Public address ^^, until you can, but isn´t a best practice in security relation and standards.

Try not use just one NIC for pfsense firewall, use 2 nic and configure it on Networking as Virtual Switch and assign on pfsense, if not you can have a bottleneck.

About protect your other server, you REALLY need to configure public address in your other server?
You can configure an internal address and put gateway for your firewall (pfsense), and to access any service in this server, you can redirect traffic using NAT.

But this, I still not try this feature on pfsense, it´s better you ask in Firewalling topic.



Offline Offline

Posts: 6

View Profile
« Reply #4 on: November 23, 2009, 05:28:12 am »

Thank you so much for this support.

I have added you on my MSN.

I am using one Physical Nic and two two logical NIC which connected to Virutal Switch.
I am able to connect WebGui on Wan Interface and ping it perfectly.

Now my major concern is that My Virtual Machine is on Public IP Address and i want to protect it from
Pfsense which is sitted infornt of my Virtual Machine.

For this what i have to do.

Can you share me your environment with Two Physical Nic.



Heitor Lessa
Full Member
Offline Offline

Posts: 116

View Profile
« Reply #5 on: November 25, 2009, 08:09:53 am »

You´re Welcome.

I still not received your ack for MSN.

But if you wanna add me on Skype is -> heitor.flessa

How I said, you may ask for firewalling topic for pfsense expert, but I throught that is not possible if you don´t redirect to pfsense gateway.

Sure I can.

We talk on MSN or skype.

Heitor Lessa


Full Member
Offline Offline

Posts: 98

View Profile
« Reply #6 on: December 22, 2009, 06:12:44 pm »

Here's how to set up your VMs on ESXi with 2 NICs. As they say, a picture is worth a thousand words:



Offline Offline

Posts: 8

View Profile
« Reply #7 on: December 23, 2009, 04:51:17 pm »

You're wording is confusing me on this one. Protect the vm from pfsense? Do you mean protect the vm from outside using pfsense?

I use pfsense under esxi similar to other post. But have 3 virtual nics and two real ones.

Vswitch0 is local network
vswitch1 is my FIOS connection/Wan
vswitch2 is virtual for DMZ.

Pfsense setup
Lan - le0 (vswitch0)
wam - le1 (vswitch1)
OPT2 - le2 (vswitch2) (DMZ)
OPT3 - Tun0 (openvpn to connect to lan from outside)
OPT4 - tun1 (openvpn connection to office for work)

I would think if you want to protect those other machines with pfsense. Option would be port forward or 1:1 nat

Do these machines need to have public ip? I just redirect ports to my web server and other things mainly to DMZ on inside.


Offline Offline

Posts: 5

View Profile
« Reply #8 on: February 25, 2010, 02:15:44 pm »

Here's how to set up your VMs on ESXi with 2 NICs. As they say, a picture is worth a thousand words:


I like the setup. I am going to setup like yours Smiley.

One NIC going to the WAN port of the FIOS router. The other NIC for internal connections with VMs.