FreeBSD FAQs

What is FreeBSD?
How do I find out what version of FreeBSD my server is running?
How do I find out what program is listening on a specific TCP Port?
How do I access my IP configuration?
How do I view a real-time list of processes, CPU usage, and memory?
How do I keep my system up to date?
How do I add/remove/edit users?
How do I determine how much hard disk space I have available?
What is RAID and how can it benefit me?
How do I change my server’s time?

What is FreeBSD?

FreeBSD is an advanced operating system (OS) for x86 compatible, AMD64 compatible, Alpha, IA-64, PC-98, and UltraSPARC architectures. FreeBSD grew out of the BSD (Berkeley Software Development) code base, which was developed at UC Berkeley. The current production release is version 5.4, and the current legacy release is 4.11. This platform is currently maintained by a large team of individuals.

How do I find out what version of FreeBSD my server is running?

To print the current hardware platform, system name, current release level, OS implementation, and version level (in this order);

# uname –a
FreeBSD freebsd.servepath.com 5.3-RELEASE FreeBSD 5.3-RELEASE Thu Jun 2 18:08:18 PST 2005 root@servepath.com:/usr/obj/usr/src/sys/SP i686

How do I find out what program is listening on a specific TCP port?

To get the list of TCP ports (not to be confused with the ports package management system) in state LISTEN,

# sockstat -4

The output of the above command will display the sockets that are open. The ports in state LISTEN are the ones with *:* listed under the FOREIGN ADDRESS column. To kill the process listening on a given port, retrieve the PID from the entry and

# kill -9 <pid>

For more information regarding how to start/stop services in FreeBSD, please see ServePath’s FreeBSD Server Security Checklist.

How do I access my IP configuration?

In FreeBSD, all of the IP configuration is done through /etc/rc.conf. See the below for a breakdown of core IP configuration options.

# Standard ServePath VLAN (transit/customer) on interface fxp0
Ifconfig_fxp0=”inet 10.0.0.1 netmask 255.255.255.252”
Ifconfig_fxp0_alias0=”inet 10.0.0.2 netmask 255.255.255.252”
Ifconfig_fxp0_alias1=”inet 10.0.0.3 netmask 255.255.255.252”
Ifconfig_fxp0_alias2=”inet 192.168.1.4 netmask 255.255.255.248”
Defaultrouter=”192.168.1.1”

The above configuration in /etc/rc.conf will give your server’s interface fxp0 the IP address of 10.0.0.1, fxp0:0 10.0.0.2, fxp0:1 10.0.0.3, and fxp0:2 10.100.0.1. The sub-interface fxp0:2 is the Internet gateway, as noted by the defaultrouter entry. This server will then be accessible via the Internet on ALL of the sub-interfaces defined (10.0.0.1, 10.0.0.2, 10.0.0.3, 192.168.1.4).

How do I view a real-time list of my processes, CPU, and memory?

In order to see a real-time list of system resources, execute the following:

# top –s1

The above will call a ‘top’ session that will update every second. By default, the processes are sorted in ascending order of CPU usage.

How do I keep my system up to date?

The ports collection (FreeBSD’s package management system) is installed into /usr/ports by ServePath. The first thing to do is to make sure that the latest patch sets have been installed.

# cd /usr/ports
# cd sysutils/portupgrade && make all install && cd /usr/ports
# cd sysutils/portsnap && make all install && cd /usr/local/etc
# mv portsnap.conf.sample portsnap.conf && cd /usr/local/sbin
# ./portsnap fetch && ./portsnap extract

The above commands will install two programs, portupgrade, and portsnap. These programs update the installed applications and uninstalled sources, respectively. These two programs work together in keeping FreeBSD up to date.

In order to apply the updated patch sets, execute the below:

# /usr/local/sbin/portsnap fetch
# /usr/local/sbin/portsnap update

In order to upgrade the installed applications, execute:

# /usr/local/sbin/portupgrade –a

How do I add/remove/edit users?

To add a user,

# adduser (provided prompted information)

To remove a user,

# rmuser ftpuser
Matching password entry:
ftpuser:*:1003:1003::0:0:FTP User:/home/ftpuser:/bin/csh

Is this the entry you wish to remove? y
Remove user's home directory (/home/ftpuser)? y
Removing user (ftpuser): mailspool home passwd.

To change a user’s password (only the root user can change user passwords),

# passwd adminsp
Changing local password for adminsp
New Password:
Retype New Password:

(Any time the FreeBSD system prompts for a password, nothing is displayed on the screen to keep from disclosing the length of the password.)

How do I determine how much disk space I have available?

In order to see how much disk space is available, execute the df (‘disk free’) command.

# df -h          
Filesystem Size Used Avail Capacity Mounted on
/dev/ad0s1a 72G 1.1G 65G 2% /
Devfs 1.0K 1.0K 0B 100% /dev

- Filesystem: This is the partition for which the information is gathered.
- Size: This is the amount of total space on the partition.
- Used: This is the amount of used space on the partition.
- Avail: This is the amount of available space on the partition.
- Capacity: Used / Avail
- Mounted on: This is the mount point of the partition.

What is RAID and how can it benefit me?

Raid basics

How do I change my server’s time?

ServePath provides an NTP (Network Time Protocol) server, which can be used to ensure the correct time. To do so, a time zone must be defined. Find the desired time zone in /usr/share/zoneinfo. (The following shell code sets the time zone to Pacific Standard Time (PST).)

# cd /usr/ports/net/ntp
# make all install
# rm –f /etc/localtime
# ln –s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

Once the time zone is set, to execute the following to sync the current time with ServePath’s NTP server.

# cd /usr/ports/net/ntp
# make all install

Once the NTP package has been downloaded and installed,

# /usr/sbin/ntpdate ntp.servepath.com
Looking for host ntp.servepath.com and service ntp
host found : ntp.servepath.com
2 Jun 21:20:13 ntpdate[12897]: adjust time server 216.93.160.62 offset
-0.181082 sec

will sync the local clock with the ServePath NTP servers.