Showing posts with label unix commands. Show all posts
Showing posts with label unix commands. 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.

Wednesday, July 16, 2008

Configuring IPv6 in CentOS Linux

To configure an IPv6 address manually into your CentOS Linux, there are several files that you can choose to change to:

/etc/sysconfig/networking/profiles/default/ifcfg-eth0
/etc/sysconfig/networking/devices/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0


Choose only one from those files and add the following lines:

IPV6INIT=yes
IPV6ADDR=2001:db8:1234:5678:0001:0002:dead:beef/64

Then, restart your network interface for changes to take effect:

#/etc/init.d/network restart
or
#service network restart

Check your interface configuration:

# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:cf:3f:18
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
---> inet6 addr: 2001:db8:1234:5678:0001:0002:dead:beef/64 Scope:Global
inet6 addr: fe80::20c:29ff:fecf:3f18/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4344229 errors:0 dropped:0 overruns:0 frame:0
TX packets:1734857 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2992698082 (2.7 GiB) TX bytes:102015418 (97.2 MiB)
Interrupt:217 Base address:0x400

Observe the line pointed by the arrow, you have now a global IPv6 address.

IPv6 Documentation Prefix


The IPv6 prefix 2001:db8::/32 that we used in this article is for documentation or experimentation purposes only. But you can still use this address in your local network if you like. If you want more information about this prefix you can visit APNIC's FAQ about IPv6 Documentation Prefix or read RFC 3849: IPv6 Address Prefix Reserved for Documentation.


Enabling IPv6 in CentOS Linux

Usually, IPv6 is enabled by default during installation. But there are times that we want to take control of things manually... just like enabling or disabling IPv6 support in CentOS Linux. Some folks out there may feel that they don't need IPv6 yet and so they turn it off. Some have disabled IPv6 by default during installation but suddenly become curious about IPv6 and want to explore it, I hope this article could be of help.

The IPv6 knob in CentOS can be found at:
/etc/sysconfig/network

If you open it and your system supports IPv6 then it will look like this:
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain

If you don't see the "NETWORKING_IPV6=yes" in your "/etc/sysconfig/network" file, that means you have not enabled IPv6 yet. Or, if you have an IPv6 support and you want to turn it off, you just change "NETWORKING_IPV6" to "no".

You then need to restart your system for changes to take effect.


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.