Showing posts with label FreeBSD. Show all posts
Showing posts with label FreeBSD. Show all posts

Saturday, November 15, 2008

FreeBSD 101: Creating a Bridge using FreeBSD

The reason why I came across with this application is that I want to sniff and examine packets lurking around the network. I could not use my switch since I only have an unmanageable switch so I cannot configure it to do port mirroring. I tried to look for hubs but could not find either. But I do have a machine that has multiple Network Interface Cards in it so I look for ways to configure these ports to broadcast frames/packets that it received from one port to all of the other ports so I can sniff any of the packets that enter in any of the ports.

I have done this before with the help of a friend but I cannot remember the exact details on how to do it. I'm not that type of guy who takes down notes for every new procedures/configurations I have done. So I spent some time googling around and finally found this link. I am going to summarize the procedures by posting a simple shell script that will create a bridge interface in FreeBSD.

#!/bin/sh
# Filename: createbridge.sh

# load the kernel loadable module
/sbin/kldload /boot/kernel/if_bridge.ko

# create a bridge interface
/sbin/ifconfig bridge0 create

# add the network interfaces you want as member of the bridge
/sbin/ifconfig bridge0 addm em0 addm em1 addm em2

# bring these interfaces up
/sbin/ifconfig em0 up
/sbin/ifconfig em1 up
/sbin/ifconfig em2 up

# then you can assign an ip address to your bridge interface if you want
/sbin/ifconfig bridge0 inet 192.168.1.1/24



Save this script at /usr/local/etc/rc.d so that it will get executed during boot-up process. Then make the script executable and execute it:

# chmod 755 /usr/local/etc/rc.d/createbridge.sh
# /usr/local/etc/rc.d/createbridge.sh


Just as there are many ways to kill a cat, there are also other ways to create a bridge interface in FreeBSD. One of which is to do it using rc.conf. But I think you still need to add "device if_bridge" into your kernel configuration /usr/src/sys/{arch}/conf/GENERIC so that it will be dynamically loaded by the kernel everytime you create a bridge interface.

Wednesday, August 20, 2008

FreeBSD 101 - Ports

This is probably one of the advantage of FreeBSD among other unix like operating systems. Installing or adding software packages is made easy through FreeBSD port collection. You can install a new software package in FreeBSD by going to the ports directory /usr/ports. If for example you want to install perl version 5.8, you go to /usr/ports/lang/perl5.8. Then type the following commands:
# make 
...
# make install
...

Or you type it in one line:
# make ; make install 


If you happen to install FreeBSD without the port collection, you can install it using portsnap. Follow these easy steps:

# mkdir /usr/ports
# pkg_add -r portsnap
# portsnap fetch
# portsnap extract

Your first step is to create first your ports directory if it does not exist yet, then you install portsnap, next is you download the ports collection and lastly, you install a new ports collection.

There are other ways to install FreeBSD port collection, first you can use sysinstall which is simpler to do than portsnap(oppsss!) or you can use cvsup method.

Saturday, April 12, 2008

FreeBSD 101 - Adding New User


adduser command


In system adminstration, one of the first thing that you need to know is how to create or add a new user. It is a good practice not to use the 'root' account especially when you access your system remotely. We need to create a new user account with basic privilages and just allow this user to switch to 'superuser' whenever it is needed.

To add a new user in freebsd you just execute the 'adduser' command at the prompt but make sure you are using your root account when doing this.


# adduser (press enter)
Username: obispo (type the username to be added and press enter)

Full name: ark obispo (type the full name of the user account or you just press enter)

Uid (Leave empty for default): (just press enter)

Login group [obispo]: (just press enter)

Login group is obispo. Invite obispo into other groups? []: wheel (if you allow this account to be able to switch to 'superuser', type wheel then press enter or else, just press enter)

Login class [default]: (just press enter)

Shell (sh csh tcsh nologin) [sh]: (choose the shell you want to use or just press enter)

Home directory [/home/obispo]: (just press enter)

Use password-based authentication? [yes]: (just press enter)

Use an empty password? (yes/no) [no]: (just press enter)

Use a random password? (yes/no) [no]: (just press enter)

Enter password: (type in the password for obispo then press enter)

Enter password again: (retype the password for obispo the press enter)

Lock out the account after creation? [no]: (just press enter)

Username : obispo
Password : **************
Full Name : ark obispo
Uid : 1007
Class :
Groups : obispo wheel
Home : /home/obispo
Shell : /bin/sh
Locked : no
OK? (yes/no): yes (type 'yes' then press enter)

adduser: INFO: Successfully added (obispo) to the user database.
Add another user? (yes/no): no (type 'yes' if you want to add another user, otherwise, type 'no' then then press enter)

Goodbye!

#


Adding a new user to a group


If it so happen that you already have added a new user into your system and you want this user to be able to switched to 'superuser' mode, edit the file /etc/group using favorite unix text editor and append the username at the wheel group like the one shown below:


wheel:*:0:root,obispo


To switch from your newly created account to superuser, just type the command 'su' and supply your superuser(or root) password.