Friday, December 30, 2011

Hard disk are getting bigger and bigger. Network interface card (NIC) and switch are getting cheaper and cheaper. It usually means more services can squeeze into a server. Combining multiple network interface into 1 big pipe would be a big plus for services that is bandwidth hungry. e.g. file server, email server & etc

Combining 2 or more network interface have a few advantages. One of them is load balancing. Load balancing enables the network interface card to share the load among the 2 or more network interface card defined. It serves as redundancy as well. But load balancing does not makes full use of the 2 or more network interface, it is meant to share network traffic load.

To fully utilize 2 or more network interface links, link aggregation should be used. Link aggregation is a method to combine 2 or more network interface to become a bigger pipe. It is also a way to combine 2 or more interface to use the same IP address. Using link aggregation can also create redundancy, if one of the link fails, the other links will take over.

This post is using FreeBSD as a server because FreeBSD have all the ports (software packages) you will need and server administration on it is made to ease systems administration daily task.Without further ado, below are the steps to configure 2 (or more) network interfaces to work as 1 big trunk or round robin :

Wednesday, December 28, 2011

Prevent default gateway route and resolv.conf being overwritten by DHCP

/etc/dhclient.confdhclient requires a configuration file, /etc/dhclient.conf. Typically the file contains only comments, the defaults being reasonably sane. This configuration file is described by the dhclient.conf(5) manual page.

/sbin/dhclientdhclient is statically linked and resides in /sbin. The dhclient(8) manual page gives more information about dhclient.

/sbin/dhclient-scriptdhclient-script is the FreeBSD-specific DHCP client configuration script. It is described in dhclient-script(8), but should not need any user modification to function properly.

/var/db/dhclient.leases
The DHCP client keeps a database of valid leases in this file, which is written as a log. dhclient.leases(5) gives a slightly longer description.

# man dhclient

# man dhclient-script

# man dhclient.conf

# man dhclient.leases

# cat /var/db/dhclient.leases.fxp0

# less /sbin/dhclient-script

To connect to a DHCP server in the background while other startup continues (asynchronous mode), use the "DHCP" value in /etc/rc.conf:

# vim /etc/rc.conf
ifconfig_fxp0="DHCP"

To pause startup while DHCP completes, use synchronous mode with the "SYNCDHCP" value:

# vim /etc/rc.conf
ifconfig_fxp0="SYNCDHCP"

Note: preferred method.

Create a dhclient hook script:
# vim /etc/dhclient-enter-hooks
### these two functions below will prevent dhclient from deleting and adding routes.
### Have a look at /sbin/dhclient-script. You can redefine all the functions in dhclient-enter-hooks.
add_new_routes() {
return 0
}

delete_old_routes () {
return 0
}

### this will prevent /etc/resolv.conf being overwritten as it 'overloads' the function of dhclient.
add_new_resolv_conf() {
# We don't want /etc/resolv.conf changed
# So this is an empty function
return 0
}

Sunday, December 25, 2011

Storage are getting cheaper and cheaper. Almost a year ago, a 250 GB 2.5" portable hard disk would cost 120 bucks. But now, it only cost 100 bucks for a 500 GB hard disk. Size are getting bigger and bigger with the same monetary value but does the hard disk spins fast enough to fetch the big "gigabytes" in time? Of cause, given "enough" time, any rate of spin could fetch any size of data. Files are getting larger and larger, especially audio & video files. Fetching the files in an reasonable time is crucial.

Before we proceed to check out the command on how to check hard disk transfer speed or read timings, we will need to familiarize our self with hard disk naming convention. Here is a simple guide on how to identify hard disk naming convention in /dev (where device node are store) :

FreeBSD is getting more and more attention due to its stability and (well done) documentation. Geeks and nerds are getting their hands into installing FreeBSD onto their Desktop or Laptop. Some might ask "Eh ??? Why ain't ya mentioning the servers? Is BSD.". Sound card, sound card belongs to multimedia. It's mostly meant for entertainment so it's gonna stay on the "personal" thing. e.g. Personal Computer, laptop, notebook, rig, moo or whatever you called it. :p

Back to the topic. This post will try to demo on how to install sound card driver onto FreeBSD.

Some commands or file to take note of :
kldunload <-- unload a driver module kldstat <-- list module driver loaded onto the memory /boot/defaults/loader.conf <-- default config files which list all supported drivers lspci <-- similar to pciconf but it will need to be install from the ports /usr/ports/sysutils/pciutils The common steps 1. Check the present/existence of the hardware. Sound cards fall under the "multimedia" "class". pciconf -lv e.g. hdac0@pci0:0:27:0: card=0x02731028 chip=0x284b8086 rev=0x03 hdr=0x00 vendor = 'Intel Corporation' device = '82801H &SUBSYS_81EC1043&REV_02\3&11583659&0&D8' class = multimedia subclass = HDA 2. We will need to load all the common drivers into the memory so that when it matches, we will know what is the sound card driver name. kldload sound kldload snd_driver 3. Check whether is the sound card drivers loaded in step 2, matches any. cat /dev/sndstat 4. If it any of the drivers manages to match the hardware, the sound card driver will bind on it. Note down the driver name shown in step 3. e.g. FreeBSD Audio Driver (newpcm: 32bit 2007061600/i386) Installed devices: pcm0: at cad 0 nid 1 on hdac0 kld snd_hda [MPSAFE] (1p:1v/1r:1v channels duplex default) Where "snd_hda" is the driver name. 5. To load the driver every time (or permanently) FreeBSD boots, edit the file /boot/loader.conf with such pattern: _load="YES"

e.g.
snd_hda_load="YES"

Alternative

1. Some of the sound cards driver module are not available in the kernel, it will need to use the OSS (Open Sound System driver) ports in /usr/ports/audio/oss. Install it by :
cd /usr/ports/audio/oss
make install clean

2. Insert the line :
"oss_enable="YES"
into /etc/rc.conf

3. Start the OSS service by :
/usr/local/etc/rc.d/oss start

4. To check whether the device driver for the sound card works or not, use
cat /dev/sndstat

One of the task installing a new FreeBSD box was dealing with IP addresses. Usually, google a web based calculator would do the trick. But today's task is a bit different.

IPv6. A whole row of hexadecimal spinning in front of my eyes, just to figure out what is the range of IP that is usable. Web based IP calculator (based on java script) are not accessible using console based internet browser (links & lynx).

Spontaneously, searching the apt repository return some very interesting stuff.

Console based IP calculator. sipcalc.

Not only it is intelligent enough to figure out the input but also it is intelligent enough to generate useful output. Surprisingly, the output is scripting friendly (using grep and sed will parse the output).

These are the steps to install it under FreeBSD & Debian based distribution (e.g. Ubuntu) :In FreeBSD :

By default, ports uses 1 connection to download and thus unbearably slow when a server rate limit the connection. Alternatively, we can tell ports to use external utility in order to open multiple connections and download simultaneously.

Firstly, install the utility "axel" by :

# cd /usr/ports/ftp/axel ;make install clean

Next, tell ports to use the external utility to perform downloading task. Insert the following lines into /etc/make.conf :

The parameter "-n 4" is to tell "axel" break the file into 4 parts and download simultaneously; "-a" is to show an alternate download progress bar. Do take note that, DO NOT set the simultaneously connection ("-n") too many as it takes time for the server to tear down the connection after the downloads terminate. This could block other people from downloading it. After all, these software are the "Best" & "Freely" available to everyone.

After accidentally cat a tar or zip file or left out some pipe and echo the whole file of random string, on to the screen; it can mess up the font of the screen and result in missing of characters or blinking characters or ever the cursor is missing from the screen. No worries, just a 5 character will make your screen back to original display :

Just type :
# reset

and press enter. It might hang there for a few seconds then the usual prompt would come back. In case it does not, just press once enter key.

Another Method:
# cd /usr/ports/sysutils/sysinfo ; make install clean distclean ; rehash
===> The following configuration options are available for sysinfo-1.0.1:
DMIDECODE=on "Include information from the dmidecode tool"
PORTAUDIT=on "Include information from the portaudit tool"
===> Use 'make config' to modify these settings

A multimedia extension created by AMD for its processors, based on / almost equivalent to Intel’s MMX extensions

3DNOWEXT

3DNOW Extended. Also known as AMD’s 3DNow!Enhanced 3DNow!Extensions

APIC

Advanced Programmable Interrupt Controller

CLFSH/CLFlush

Cache Line Flush

CMOV

Conditional Move/Compare Instruction

CMP_Legacy

Register showing the CPU is not Hyper-Threading capable

Constant_TSC

on Intel P-4s, the TSC runs with constant frequency independent of cpu frequency when EST is used

CR8Legacy

-unknown-

CX8

CMPXCHG8B Instruction. (Compare and exchange 8 bytes. Also known as F00F, which is an abbreviation of the hexadecimal encoding of an instruction that exhibits a design flaw in the majority of older Intel Pentium CPU).

CX16

CMPXCHG16B Instruction. (CMPXCHG16B allows for atomic operations on 128-bit double quadword (or oword) data types. This is useful for high resolution counters that could be updated by multiple processors (or cores). Without CMPXCHG16B the only way to perform such an operation is by using a critical section.)

FXSAVE/FXRSTOR. (The FXSAVE instruction writes the current state of the x87 FPU, MMX technology, Streaming SIMD Extensions, and Streaming SIMD Extensions 2 data, control, and status registers to the destination operand. The destination is a 512-byte memory location. FXRSTOR will restore the state saves).

FXSR_OPT

-unknown-

HT

Hyper-Transport. Note that the same abbreviation might is also used to indicate Hyper Threading (see below)

HTT/HT

Hyper-Threading. An Intel technology that allows quasi-parallel execution of different instructions on a single core. The single core is seen by applications as if it were two (or potentially more) cores. However, two true CPU cores are almost always faster than a single core with HyperThreading. This flag indicates support in the CPU when checking the flags in /proc/cpuinfo on Linux systems. For more info how you can detect active HyperThreading, see the first comment in my blog post about this page at [2]

It is rumoured to stand for MultiMedia eXtension or Multiple Math or Matrix Math eXtension, but officially it is a meaningless acronym trademarked by Intel

MMXEXT

MMX Extensions – an enhanced set of instructions compared to MMX

MON/MONITOR

CPU Monitor

MSR

RDMSR and WRMSR Support

MTRR

Memory Type Range Register

NX

No eXecute, a flag that can be set on memory pages to disable execution of code in these pages

PAE

Physical Address Extensions. PAE is the added ability of the IA32 processor to address more than 4 GB of physical memory using Intel’s 36bit page addresses instead of the standard 32bit page addresses to access a total of 64GB of RAM. Also supported by many AMD chips

PAT

Page Attribute Table

PBE

Pending Break Encoding

PGE

PTE Global Bit

PNI

Prescott New Instruction. This was the codename for SSE3 before it was released on the Intel Prescott processor (which was later added to the Pentium 4 family name).

PSE

Page Size Extensions. (See PSE36)

PSE36

Page Size Extensions 36. IA-32 supports two methods to access memory above 4 GB (32 bits), PSE and PAE. PSE is the older and far less used version. For more information, take a look at [1].

SEP

SYSENTER and SYSEXIT

SS

Self-Snoop

SSE

Streaming SIMD Extensions. Developed by Intel for its Pentium III but also implemented by AMD processors from Athlon XP onwards

The -w parameter tells ps to use 132 columns to display information. If the -w option is specified more than once, ps will use as many columns as necessary without regard for your window size, which will display the full output.

Another similar problem with less command:

# less -S /usr/ports/UPDATING

The -S options tells less command to not chop the long lines after the terminal width.

As of version 7.3, Xorg can often work without any configuration file by simply typing at prompt:

% startx
Starting with version 7.4, Xorg can use HAL to autodetect keyboards and mice. The sysutils/hal and devel/dbus ports are installed as dependencies of x11/xorg, but must be enabled by the following entries in the /etc/rc.conf file:

hald_enable="YES"
dbus_enable="YES"

Note: HAL (Hardware Abstraction Layer) is a daemon that allows desktop applications to readily access hardware information, to locate and use such hardware regardless of bus or device type. In this way a desktop GUI can present all resources to its user in a seamless and uniform manner.

Note: DBUS In computing, D-Bus (Desktop Bus) is a simple inter-process communication (IPC) open-source system for software applications to communicate with one another. Heavily influenced by KDE2–3's DCOP system, D-Bus has replaced DCOP in the KDE 4 release. An implementation of D-Bus supports most POSIX operating systems, and a port for Windows exists. It is used by Qt 4 and GNOME. In GNOME it has gradually replaced most parts of the earlier Bonobo mechanism.

Note: someone says if you enable hald_enable, you will get "Freebsd 8 kernel fault and automatic reboot"

Another possible solution might be remove the virtual CD-ROM from your virtual machine.

> can you explain to me what is it : dbus_enable="YES" and
> hald_enable="YES" in file /etc/rc.conf? What is their function?

In explicit correspondence with their names, these settings enable to run dbus and hald. dbus is a D-Bus messaging daemon, hald is a HAL daemon. These programs are using in X environment to automount DVD's, flashcards and another, even mices and keyboards.

Since Xorg 1.7.5 running dbus and hald is required in some hardware equipment.
===
Those enable the startup of the DBUS and HAL services via their control files in /usr/local/etc/rc.d. Those services are often needed for X, and programs related to X (KDE, Gnome, Xfce, and many programs that have "Use DBUS for something" compile time options set).

Sadly, those don't provide "man dbus" or "man hal" in a very impolite manner. I'm sure you can find more documentation on the web, but it may already be outdated.

If you ask what HAL and DBUS actually *ARE*, I'm not sure what to answer - to me, they are both useless. :-)

Removing the entries in /etc/rc.conf may cause problems for some of your programs, or may even make your X stop working properly.
===
hald is an interface between devices and programs. It listens for attachment/detachment of input devices (keyboard, mouse, etc.) and informs listening programs of those events.

dbus is an interprocess communication system that allows programs to connect to and exchange messages with other programs. It allows the kernel, for example, to interact with your desktop. Rather than you interacting directly with the kernel, dbus acts as a middle man, controlling the communications between the two and only allowing you to perform actions which are considered "safe" or "reasonable".

These services should be started (either manually or by rebooting) before further Xorg configuration is attempted.

The automatic configuration may fail to work with some hardware, or may not set things up quite as desired. In these cases, manual configuration will be necessary.

Note: Desktop environments like GNOME, KDE or Xfce have tools allowing the user to easily set the screen parameters such as the resolution. So if the default configuration is not acceptable and you planned to install a desktop environment then just continue with the installation of the desktop environment and use the appropriate screen settings tool.

Starting with Xorg 7.4 and above, this test produces a black screen which may make it difficult to diagnose whether X11 is working properly. The older behavior is still available by using the retro option:

# Xorg -config xorg.conf.new -retro
If a black and grey grid and an X mouse cursor appear, the configuration was successful. To exit the test, switch to the virtual console used to start it by pressing Ctrl+Alt+Fn (F1 for the first virtual console) and press Ctrl+C.

If ibus cannot start or the panel does not appear, please ensure
that you are using up-to-date python.
There's a bug in python 2.5, which may prevent the panel from appearing.
-------------------------------------------------------------------
To display this message again, type /usr/sbin/pkg_info -D ibus-1.3.9_1

There are many times when a port installs another port and that port will have a screen that pops up asking for input so if you want to walk away while things are getting compiled you will want to use the recursive version of the command:

# make config-recursive
# make config-recursive
# make install
# make clean distclean

or to use default options to install:
# make -DBATCH install
or
# make BATCH=yes install

config-recursive is very handy, but don't forget to run it twice. You may enable a dependency the first time through that has its own configuration options.

I usually run this twice or until it produces no output. It's possible to enable a dependency on your first run through that has its own configuration.

Friday, December 16, 2011

Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit[1] and is Python's de-facto standard GUI,[2] and is included with the standard Windows install of Python.

As with most other modern Tk bindings, Tkinter is implemented as a Python wrapper around a complete Tcl interpreter embedded in the Python interpreter. Tkinter calls are translated into Tcl commands which are fed to this embedded interpreter, thus making it possible to mix Python and Tcl in a single application.
Python 2.7 and Python 3.1 incorporate the "themed Tk" ("ttk") functionality of Tk 8.5.[3][4] This allows Tk widgets to be easily themed to look like the native desktop environment in which the application is running, thereby addressing a long-standing criticism of Tk (and hence of Tkinter).
There are several popular GUI library alternatives available, such as wxPython, PyQt and PyGTK.

cx_Freeze - is a set of scripts and modules for freezing Python scripts into executables in much the same way that py2exe and py2app do. Unlike these two tools, cx_Freeze is cross platform and should work on any platform that Python itself works on. It requires Python 2.3 or higher since it makes use of the zip import facility which was introduced in that version.

===
scru: If you know C, you can make a bootstrap app that embeds the interpreter and then runs your script. I think it's just a few lines of code, but you would have to distribute python30.dll alongside the parts of the standard library that your program uses.
===
Nicholas Knight: There's nothing stopping you from including a prebuilt Python environment in your package/installer and either creating an appropriate shortcut to launch the Python app, or creating a separate executable that launches the Python app (or even linking the Python interpreter into the executable and using it like that...). It just takes some more effort making sure you've got all the right pieces (like .dlls) where they need to be.

Dynamips - is an emulator program that was written to emulate Cisco routers. Dynamips runs on Linux , Mac OS X or Windows and can emulate the hardware of the Cisco series routing platforms by directly booting an actual Cisco IOS software image into the emulator.

Dynagen - is a front-end for use with the Dynamips Cisco router emulator. It uses an INI-like configuration file to provision Dynamips emulator networks. It takes care of specifying the right port adapters, generating and matching up those pesky NIO descriptors, specifying bridges, frame-relay, ATM switches, etc. It also provides a management CLI for listing devices, suspending and reloading instances, determining and managing idle-pc values, performing packet captures, etc.

Saturday, December 10, 2011

How do I set / change the speed ( duplex settings ) on my FreeBSD network card? I'd like to change default 10Mbps to 100Mbps or vice versa. Linux user can use ethtool to set an Ethernet card speed and duplex, can I use the same command on FreeBSD?

A. ethtool is not required on FreeBSD. By default, the NIC auto-negotiates the speed and duplex of the connection. Make sure port speed set correctly on your switch. You need use the ifconfig command to configure the speed and duplex settings on the adapter. You also need to update your /etc/rc.conf file to set speed and duplex configuration.

FreeBSD is a Unix-like free operating system. You can install to choose third party software on FreeBSD from the Ports Collection. Many services such as POP3 server daemons, IMAP, etc. could be started using the inetd.

However, networking can be stop or started using special script located in /etc/rc.d/ directory. This directory includes script to stop or start network, and other services such as SSH server.
FreeBSD 5.x/6.x and above version - start or stop network

FreeBSD 5.x/6.x and above version comes with netif script to start, restart, stop network service. You need to login as a root user. Then you can use following commands:

To start FreeBSD network service:
# /etc/rc.d/netif start

To stop FreeBSD network service:
# /etc/rc.d/netif stop

To restart FreeBSD network service:
# /etc/rc.d/netif restart

Manual method using ifconfig

To stop network card (NIC) on-fly:
# ifconfig network-interface down

To start network card (NIC) on fly:
# ifconfig network-interface up

To list down network interface:
# ifconfig -d

To list up network interface:
# ifconfig -u

FreeBSD Update / restart routing tables / service

It is also necessary to update routing table after restating networking service, enter:
# /etc/rc.d/routing restart

How do I restart network service over ssh session?

You need to type the commands as follows in order to avoid any problems:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart

FreeBSD 4.x and prior version only - start, restart, stop network service

1) To start network service under FreeBSD you need to copy special
script as follows:

# cp /usr/share/examples/etc/netstart /etc/network

2) Execute script:

. /etc/network

OR

sh /etc/network

Please note that script will do all necessary work for you i.e. it will start network, routing, firewall etc.