Monthly Archives: February 2015

How is FreeBSD different then Linux

This article gives a basic overview of the major differences between FreeBSD and Linux with regards to IP networking, application installs, and starting/stopping services. The assumption is the reader has a good basic understanding of Linux to start of with. We will cover three areas: 1) IP networking, 2) package installation, and 3) starting/stopping services both manually and automated.

IP Networking

I have covered IP settings in previous articles pertaining to Centos and Debian. Debian uses the /etc/system/interfaces file, and Centos uses the /etc/sysconfig/networking-scripts/if-eth0 file.

FreeBSD is different. Everything is in /etc/rc.conf – not just IP settings but everything pertaining to the entire system is in /etc/rc.conf. Thats sounds great right? Basically, FreeBSD has /etc/defaults/rc.conf which contains everything for default settings, but whatever it sees in /etc/rc.conf at bootup overrides the default. Here is the sample rc.conf syntax for basic IP settings:

ifconfig_em0="208.50.100.5 netmask 255.255.255.0 up"
defaultrouter="208.50.100.1"

And for IPv6 add the additional lines:

ipv6_enable="YES"
ipv6_network_interfaces="lo0 em0"
ipv6_ifconfig_em0="2610:bf00:50:100::5/64"
ipv6_defaultrouter="2610:bf00:50:100::1"

In this case our network interface is em0 – we know that from bootup or by looking at the output of dmesg command. Name resolution is still controlled by /etc/resolv.conf as it is in Linux. If you want to add IPv4 aliases, the rc.conf syntax is:

ifconfig_em0_alias0=”208.50.100.6 netmask 255.255.255.255″
ifconfig_em0_alias1=”208.50.128.7 netmask 255.255.255.255″
ifconfig_em0_alias2=”208.50.100.8 netmask 255.255.255.255″

Software Package Installation

In Linux, apt-get and yum are the common tools for adding packages. FreeBSD has a completely different way of doing this. There are two main ways to add software packages: 1) the ports repository, or 2) the sysinstall utility.

The ports repository is a large directly/file tree located in /usr/ports – under that directory there are categories, like /usr/ports/databases, and within the category directory you will find the individual packages, like /usr/ports/databases/mysql51-server. The install the package you go into the packages directory (i.e. /usr/ports/databases/mysql51-server) and run “make && make install”. This will download the most recent tarball, applying system specific patches, compile, and then install the package. If the package has configurable options, a TEXT GUI will pop-up asking you to make those optional selections.

Obviously, the ports to work you need to have the most recent /usr/ports or even have it at all. If you did not install it when creating the system, you can always add it later using the sysinstall utility – /usr/sbin/sysinstall.

sysinstall

sysinstall is a TEXT GUI system that allows you to do many things (too many for me to describe), one of those things is adding distributions. If you dont have /usr/ports installed, go into sysinstall, select “Configuration”, then select “Distributions”, then scroll down and select “Ports”. When you continue from there, it will ask where to install from and you can select the FreeBSD FTP servers to install over the network.

While inside the sysinstall utility you may notice that the utility itself can be used to install software packages. From the main screen, select “Configure”, then select “Packages”. You can now browse through the same category tree and select, for example, Databases -> Mysql 5.1 Server. When you continue through the process, you will again be asked from where to install and you can select the FreeBSD FTP servers.

A sysinstall package add is different then a ports add because the package is not compiled, rather, a pre-compiled package is downloaded and installed.

System Services – Starting, Stopping, Automation

Lastly, how do you start and stop services and set services for automatic start at bootup? Again, this is vastly different then Linux methods, but again, its all covered in /etc/rc.conf. First, the actual scripts for starting and stopping services that have been been added via ports or the sysinstall package system will always be located in /usr/local/etc/rc.d – the exception being core OS services which are located in /etc/rc.d – things like nfsserver or sendmail (on FreeBSD sendmail is a core base service).

So if you have installed apache22, starting and stopping is done by:

/usr/local/etc/rc.d/apache22 stop
or
/usr/local/etc/rc.d/apache22 start

What about automation? That is done in rc.conf as follows:

apache22_enable="YES"

99% of the time the name of the script located in /usr/local/etc/rc.d is the syntax for the above _enable statement, but there are cases where it differs. To be sure, open up the init script located in /usr/local/etc/rc.d and look for its “name” directive which is located near the top. The name is the service name. Oddly enough, mysql is a culprit of this. The mysql service name is mysql, but the init script in /usr/local/etc/rc.d is named mysql-server, so if you added mysql-server_enable=”YES” to /etc/rc.conf it would not work, it has to be mysql_enable=”YES”.

TCP/IP Networking in Linux without a GUI

There are a few major Linux distributions these days, Centos/RHES, Ubuntu, and Debian. They all differ slightly in how they natively handle IP configuration.

For starters, lets first understand the universal way to IP config ANY Linux OS (this also applies to BSD Unix and Solaris). This is done with the ifconfig and route command. ifconfig places an IP address on an interface and route places the default gateway in the routing table. When using ifconfig you just need to know the interface name, if you dont know the interface name, simple type the command:

ifconfig -a

This will display all the connected interfaces, so if you have two NICs on your server it may list an eth0 and eth1. For our example, lets assume we are connecting a Cat5 cable to eth0 and we want to configure the following network setup:

IP Address: 200.50.100.5
Netmask: 255.255.255.0
Default Gateway: 200.50.100.1

The IP configuration is handled by the following command:

ifconfig eth0 200.50.100.5 netmask 255.255.255.0 up

To add the default gateway, we use the following command:

route add default gw 200.50.100.1

Obviously, if you reboot the system these settings will be lost. So now lets look at how to manually config the IP settings for bootup. Both Debian and Ubuntu use the same setup, it involves editing the interfaces file. CentOS/RHES is a bit different, we’ll cover that one last.

For Ubuntu/Debian, edit the file /etc/network/interfaces and add the following lines:

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 200.50.100.5
netmask 255.255.255.0
network 200.50.100.0
broadcast 200.50.100.255
gateway 200.50.100.1

The broadcast and network entries are technically not needed, but you might as well add them. After you save this file, use the ifup command to activate and bring up the eth0 interface:

ifup eth0

Finally, make sure you edit /etc/resolv.conf and add your DNS resolvers, the syntax is as follows:

nameserver 8.8.8.8
nameserver 4.4.4.2

Lets take a look at Centos/RHES and how they configure IP networking. Instead of using a singular config file, each interface has its own file located in /etc/sysconfig/network-scripts and the file name format is ifcfg-INT where INT is the name of your interface. In our example, our interface is eth0, so the file we will be editing is /etc/sysconfig/network-scripts/ifcfg-eth0 and the contents of that file is as below:

DEVICE=eth0
BOOTPROTO=static
BROADCAST=200.5.100.255
HWADDR=00:13:72:65:B0:AD
IPADDR=200.50.100.5
NETMASK=255.255.255.0
NETWORK=200.50.100.0
ONBOOT=yes

Again, some of the above lines are not required, HWADDR, NETWORK, and BROADCAST are not required but definitely add them if you know them. The HWADDR is the interfaces MAC Address, which you can find out by typing “ifconfig eth0″. The default gateway setting in CentOS/RHES is handled in a separate file. Edit the file /etc/sysconfig/network and add the following lines:

NETWORKING=yes
HOSTNAME=foobar.domain.com
GATEWAY=200.50.100.1

Once the files are edited, you again run the command “ifup eth0″ to bring up the interface. The default gateway and hostname settings will be active on reboot, otherwise you have to restart networking for those changes to take effect, this is done by running:

/etc/init.d/network restart