Configuring Network on FreeBSD

Home / Configuring Network on FreeBSD

Configuring Network on FreeBSD

December 5, 2015 | Uncategorized | No Comments

Network is an important matter for system, especially for FreeBSD.

In this article we will discuss about how to configuring network on FreeBSD and learn some important notes of it.

For this I use FreeBSD 8.3 for amd64, although you can also use another version or architecture.

There are two method for configuring network, by using sysinstall and editing rc.conf.

Sysinstall Method

The easiest method for configuring network is using sysinstall, by invoking

sysinstall

A Graphical User Interface (text based though) will prompt you. You can do network configuration by choosing Configure menu for doing Post Installation.

Accessing rc.conf

Another method will be accessing rc.conf directly. This method require you to edit rc.conf manually. Later on this article, we will mostly cover things for rc.conf.

Setting IP

IP or Internet Protocol address is an address which tell where are us in the world of internet. There are two type of IP address we can assigned to our network card: static address or dynamic address.

If you want to set IP address statically, edit rc.conf and add this line:

ifconfig_em0="inet 192.168.1.5 netmask 255.255.255.0"
defaultrouter="192.168.1.1"

In that example, we set our network card, which is recognized as em0, to have IP address 192.168.1.5 with netmask / subnet 255.255.255.0. The ethernet card recognized by your machine might be different, so you should find out what is the name of your ethernet card. A simple command to do so:

systat -ifstat

The default router, like the name, is used to tell our machine where is the router we must communicate.

If you want to set IP address dynamically using DHCP, edit rc.conf and add this line:

ifconfig_em0="DHCP"

Setting Nameserver (DNS)

To set default DNS server used by our machine, edit /etc/resolv.conf and write this:

nameserver 192.168.1.1

Our machine then use the 192.168.1.1 provided to doing some query for name. In other word, using nameserver as stated above as default nameserver. Change 192.168.1.1 to your need. A common DNS server used is Google DNS which located on 8.8.8.8.

Setting Hostname

Hostname is the identifier for machine in the network. Normally it is formed by machine name and domain name. This example add line to rc.conf and set hostname to freebsd.celestial-being.net:

hostname="freebsd.celestial-being.net"

IP Address Aliasing

IP Address Aliasing means a single network card can have more than 1 IP address. For example this will gives your ethernet card 3 IP address:

ifconfig_em0="inet 192.168.0.53 netmask 255.255.255.0"
ifconfig_em0_alias0="inet 192.168.0.54 netmask 255.255.255.0"
ifconfig_em0_alias1="inet 192.168.0.55 netmask 255.255.255.0"
defaultrouter="192.168.0.1"

Multiple Network Cards in One Machine

Having multiple network cards in one machine is not a problem. Just configuring them both in rc.conf as you would normally, but with only one default router line. The hostname line for each needs to follow directly after the card is declared. For example:

ifconfig_em0="inet 192.168.1.5 netmask 255.255.255.0"
hostname="freebsd.celestial-being.net"
ifconfig_em1="inet 10.10.10.5 netmask 255.0.0.0"
hostname="arsenal.celestial-being.net"
defaultrouter="10.10.10.1"

Multiple netword cards on different networks

Having multiple cards in one machine on the same network is a simple matter, but setting the cards to seperate networks is another matter. They are both setup normally as above with the IPs declared statically, and the defaultrouter set to the network you want the machine to use for everything that isn’t specifically set to go out on the other card.

To see what router is set to default use the command

netstat -r

The first router on the list is the default router. Since FreeBSD sometimes changes the route if there is a problem it works best to create a start up script to set the route you want traffic to default to

#!/bin/sh
route change default 192.168.0.1 >> /dev/null
echo "DefRouteChange"

Getting this all to work can be tricky, and sometimes depends on the order the network cards are listed rc.conf, but it can be done.

Sending the hostname to the DHCP server

On many DSL modems and routers the hostname will not show up for FreeBSD machines when they are set to DHCP. To fix this you can add the following lines to /etc/dhclient.conf and replace the network card and hostname with your own

interface "em0" {
   send host-name "freebsd"
}

About Author

about author

xathrya

A man who is obsessed to low level technology.

Leave a Reply

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

Social media & sharing icons powered by UltimatelySocial