Archive for November, 2005

Setting up ip aliases in freebsd

Often times in a server environment your going to need to setup multiple ip addresses to the same ethernet card, it’s really a simple procedure, and the way that I generally do these things is create a file called /etc/rc.aliases and include the alias line in there:

If the IP is on the same netmask:

/sbin/ifconfig fxp0 alias 192.0.3.9 netmask 255.255.255.255

Otherwise, just specify the network address and netmask as usual:

/sbin/ifconfig fxp0 alias 172.16.0.223 netmask 255.255.255.0

once you’ve added each line, then add a line in the /etc/rc.local file

sh /etc/rc.aliases

This way when you want to edit the aliases on each server you have them all in one location.

Comments (1)

FreeBSD servers and keyboards

One of the minor issues I have with freebsd out of the box is that when I have a server network of a few hundred servers, I can’t just plug in a keyboard when we’re having an issue with the networking.

This is a common issue, the freebsd kernel doesn’t support just plug and play keyboards, however there is an easy fix to this mess.. well, easy if your comfortable recompiling a kernel (which you should be).

# cd /usr/src/sys/i386/conf
# cp GENERIC MYKERNEL

vi MYKERNEL

search for:

device atkbd0 at atkbdc? irq 1 flags 0×1

and replace the line with:

device atkbd0 at atkbdc? irq 1

save it (:wq!)

and then

# /usr/sbin/config MYKERNEL

# cd ../compile/MYKERNEL
(For FreeBSD versions prior to 5.0, use the following form instead: # cd ../../compile/MYKERNEL)

# make depend
# make
# make install
If everything went cleanly..
# shutdown -r now

and it should come back with a kernel that allows you to just plug in a PS2 style keyboard without any issues.

Comments

NTP — Keeping your clock in sync

One of the most insane things about working in the unix world is that it complains when the system clock on your computer is wrong. There is nothing more disturbing then when you create a tarball on another machine and extract it on yours and it complains that the files were created in the future.

A great way to deal with this problem is a system called ntp, network time protocol.

Network Time Protocol (RFC-1305), or more commonly known as NTP is pretty simple to setup, most OS’s are simply an RPM or ports tree install away.

(freebsd)
Connect to your machine and su - to root, then:

# cd /usr/ports/net/ntp
# make

# make install
# rehash

once thats done, simply run:

# ntpdate time.nist.gov
5 Nov 19:46:40 ntpdate[46439]: step time server 192.43.244.18 offset -2.467839 sec
#

This will update your server to the current time.

My suggestion is to set this up as a nightly cronjob,

# vi /etc/crontab

and add the line:

0 2 * * * root /usr/sbin/ntpdate time.nist.gov > /dev/null

and restart cron (

# killall -HUP cron

And you should be good to go!

Comments

using tar via ssh — for remote file transfers

Having to move large sums of data between boxes is part of an admins life… and sometimes those machines are across the country, and your moving a bunch of sensitive data, and the bosses want to make sure no one can sniff at it… ok, whatever boss ;)

So here’s what I do, use friendly unix tar, and ssh pipe it to another machine.

Lemme show you some examples:
This shows you how to send files FROM the local machine TO a remote machine.

$ cd directory-with-files
$ tar cf - . | ssh username@remoteserver.com “cd /directory-to-put-files; tar xf -” [ENTER]

Ok, you may be asking me to explain this madness:
Change to a directory with files you want to transfer

tar cf - . - create a tar file, with the name “-”, which means output to screen, in the directory “.” (currently in, or right here)

| ssh username@remoteserver - setup an ssh connection to the remote server
“cd /directory-to-put-files; tar xf -” [ENTER] - once connected, change directorys on the local machine, and then EXTRACT that tar file named “-” or output to the screen.

In this case, the output to the screen will be piped thru ssh to the other computer and boom your set.



Now, in order to reverse the logic and transfer FROM a server TO the local machine:

$ cd directory-to-put-files
$ ssh username@remoteserver.com “cd /directory-to-get-files; tar cf - .” | tar xf - [ENTER]

Try it out :)

Comments (1)

How to find the current working directory of a process…

Ok, this might sound insane, but this is the type of question you get asked sometimes, or the situation where you need to know comes up.

I was once asked what the current working directory was of a process on the server… often times I don’t even think about it, however the script was writing files, and we had no idea where ;)

I tracked it down to a pretty simple method

> ps -awux | grep [process]

root 90 0.0 0.0 1016 228 ?? Is 27Apr05 1:01.81 /usr/sbin/cron

> ls -l /proc/[pid from above, which is 90]/cwd

lrwxrwxrwx 1 root root 0 Nov 4 12:56 /proc/90/cwd -> /var/spool

And it’s current working directory is /var/spool

Neat :)

Comments

man and a new one I just stumbled on….

Ok, I feel stupid, however I never realized that I could search man pages!

For those that don’t know, unix offers a built in “manual” command called “man”… sometimes it’s helpful, sometimes it’s there just for reference. It’s easy

$ man command

in this case man ls

LS(1) FreeBSD General Commands Manual LS(1)

NAME
ls - list directory contents

SYNOPSIS
ls [-ABCFGHLPRTWabcdfghiklmnopqrstuwx1] [file …]

DESCRIPTION
For each operand that names a file of a type other than directory, ls
displays its name as well as any requested, associated information. For
each operand that names a file of type directory, ls displays the names
of files contained within that directory, as well as any requested, asso-
ciated information.[and on and on]


man is a great thing, however sometimes you end up forgetting the command your using, and thats when my new little friend helps out…

$ man -k search-scring[ENTER]

This is awsome, now I can find all the insane instances of locate :) man -k locate

cfree(3) - free up allocated memory
index(3) - locate character in string
locate(1) - find filenames quickly
locate.updatedb(8) - update locate database
memchr(3) - locate byte in byte string
mmap(2) - allocate memory, or map files or devices into memory
pthread_mutex_destroy(3) - free resources allocated for a mutex
rindex(3) - locate character in string
strchr(3) - locate character in string
strpbrk(3) - locate multiple characters in string
strrchr(3) - locate character in string
strstr(3), strcasestr(3), strnstr(3) - locate a substring in a string
usbhid(3), hid_get_report_desc(3), hid_use_report_desc(3), hid_dispose_report_desc(3), hid_start_par
se(3), hid_end_parse(3), hid_get_item(3), hid_report_size(3), hid_locate(3), hid_usage_page(3), hid_
usage_in_page(3), hid_init(3), hid_get_data(3), hid_set_data(3) - USB HID access routines
whereis(1) - locate programs
which(1) - locate a program file in the user’s path

Give it a whirl!

Comments

« Previous entries ·