Halaman

Tampilkan postingan dengan label BSD. Tampilkan semua postingan
Tampilkan postingan dengan label BSD. Tampilkan semua postingan

Minggu, 09 Januari 2011

Net-SNMP on FreeBSD

1. Installation using ports
# cd /usr/ports/net-mgmt/net-snmp
# make install clean

2. List directories and files name that contain "snmpd"
# pkg_info -L net-snmp-5.4.2.1 | grep snmpd
...
/usr/local/sbin/snmpd
/usr/local/share/snmp/snmpd.conf.example
/usr/local/etc/rc.d/snmpd

3. Create snmpd.conf file from the example
# mkdir /usr/local/etc/snmp
# cp /usr/local/share/snmp/snmpd.conf.example /usr/local/etc/snmp/snmpd.conf

4. Edit the file
# vi /usr/local/etc/snmp/snmpd.conf

and modify from:
# sec.name source community
com2sec local localhost COMMUNITY
com2sec mynetwork NETWORK/24 COMMUNITY

become:
# sec.name source community
com2sec local localhost private
com2sec mynetwork 192.168.123.0/28 public

5. Modify rc configuration file
#vi /etc/rc.conf
then add this
snmpd_enable="YES"

6. Start snmp daemon
Check if port 161 active
#sockstat -4 | grep 161
---nothing displayed

Ready to start snmpd
# /usr/local/etc/rc.d/snmpd start
Starting snmpd.

# sockstat -4 | grep 161
root snmpd 16217 10 udp4 *:161 *:*

# ls /var/run | grep snmpd
snmpd.pid

Read the log file
# cat /var/log/snmpd.log

7. Is it works?
# snmpwalk -c private -v1 localhost | grep Address
# snmpwalk -c private -v2c localhost HOST-RESOURCES-MIB::hrSWRunName
# snmpwalk -c public -v1 192.168.123.1 sysDescr
SNMPv2-MIB::sysDescr.0 = STRING: OpenBSD host1.mydomain.com 4.7 GENERIC.MP#449 i386

# snmpwalk -c public -v1 192.168.123.4 sysDescr
SNMPv2-MIB::sysDescr.0 = STRING: FreeBSD host2.mydomain.com 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Thu Jan 15 16:15:25 WIT 2009 root@host2.mydomain.com:/usr/src/sys/i386/compile/BINSARBSD i386

# snmpwalk -c public -v1 192.168.123.1 hrSystemUptime.0
HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (15403177) 1 day, 18:47:11.77

# snmpget -c public -v1 192.168.123.4 hrSystemUptime.0
HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (1598771) 4:26:27.71

# snmpget -c public -v2c 222.xxx.yyy.zzz sysUpTime.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (15976711) 24 day, 20:22:47.11

# snmpget -c private -v1 localhost .1.3.6.1.4.1.2021.100.6.0
# snmpwalk -c public -v1 192.168.123.1 .1.3.6.1.4.1.2021.100.6.0
# snmpstatus -c private -v2c localhost
[UDP: [0.0.0.0]->[127.0.0.1]:161]=>[FreeBSD host2.mydomain.com 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Thu Jan 15 16:15:25 WIT 2009 root@host2.mydomain.com:/usr/src/sys/i386/compile/BINSARBSD i386] Up: 0:44:48.24
Interfaces: 3, Recv/Trans packets: 116458/74594 IP: 85052/74569
1 interface is down!

# snmpstatus -c public -v2c 192.168.123.1
[UDP: [0.0.0.0]->[192.168.123.1]:161]=>[OpenBSD host1.mydomain.com 4.7 GENERIC.MP#449 i386] Up: 1 day, 19:15:49.53
Interfaces: 7, Recv/Trans packets: 337656/162218 IP: 219127/159655
3 interfaces are down!

# snmptest -c public -v 1 localhost
Variable: system.sysDescr.0
Variable:
Received Get Response from UDP: [0.0.0.0]->[127.0.0.1]:161
requestid 0xCC474EF errstat 0x0 errindex 0x0
SNMPv2-MIB::sysDescr.0 = STRING: FreeBSD host2.mydomain.com 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Thu Jan 15 16:15:25 WIT 2009 root@host2.mydomain.com:/usr/src/sys/i386/compile/BINSARBSD i386
Variable:

You may be interested in these OID:
# snmpget -c private -v1 localhost .1.3.6.1.2.1.1.1.0

probably these too
1.3.6.1.2.1.2.2.1.10.1
1.3.6.1.2.1.2.2.1.16.1
1.3.6.1.4.1.2021
1.3.6.1.4.1.2021.2
1.3.6.1.4.1.2021.100.6.0
1.3.6.1.4.1.2021.100.11.0

In this writing, snmpd works with SNMP version 1 and 2c and some snmpd command has been used.

Rabu, 05 Januari 2011

Relaying or redirecting access to another IP/Port

I have a machine with two cards: xl0 (192.168.168.168 and it's alias 10.10.10.10)
xl1 (222.xx.xx.xx). They would serve an internal and external connection respectively to a web server named test.fer.com. Every web access from internet will be passed to xl1, and xl0 for intranet use, and the real web server run on another machine (10.10.10.11) will serve any request.

For this configuration to work, a port must be listening on www port. I have use Apache and applied virtual host, it works fine.

I would try another way, using relayd on OpenBSD 4.7.
relayd is a daemon to relay and dynamically redirect incoming connections to a target host. Its main purposes are to run as a load-balancer, application layer gateway, or transparent proxy.

The daemon is able to monitor groups of hosts for availability, which is determined by checking for a specific service common to a host group. When availability is confirmed, layer 3 and/or layer 7 forwarding services are set up by relayd.

Layer 3 redirection happens at the packet level; to configure it, relayd communicates with pf.
To allow relayd to properly set up pfrules, the following line is required in the filter section of pf.conf:

anchor "relayd/*"

Layer 7 relaying happens at the application level and is handled by relayd itself.
Various application level filtering and protocol-specific-balancing options are available for relays.

Here an example of relayd.conf or relay daemon configuration file
#
# Macros
relayd_lokal="10.10.10.10"
relayd_lokal_int="xl0"
relayd_ip="222.xx.xx.xx"
relayd_port ="80"
relayd_int="xl1"
mywebserver ="10.10.10.11"

table { $mywebserver }
serverku_port="80"

# Global Options
interval 10
timeout 1000
prefork 5

log updates

redirect anchor_name {
listen on $relayd_ip port $relayd_port interface $relayd_int
# tag every packet that goes thru the rdr rule with RELAYD
tag RELAYD
sticky-address
forward to port $serverku_port mode roundrobin check tcp
}


http protocol "www_service" {
tcp { nodelay, socket buffer 65536 }
header append "$REMOTE_ADDR" to "X-Forwarded-For"
header append "$SERVER_ADDR:$SEVER_PORT" to "X-Forwarded-By"
}

relay "www_forwarder" {
listen on $relayd_lokal port $relayd_port
protocol "www_service"
forward to $mywebserver port $serverku_port
}


Remind that in pf.conf to put rule something like this:
pass in log on $ext_if inet proto tcp from any to $mywebserver port 80 flags S/SA synproxy state tagged RELAYD

Adding a file set later on OpenBSD

I have to install the gd library that requires the X components and experiencing this error
=================================
#cd /usr/ports/graphics/gd
#make install
===> Checking files for gd-2.0.35p0
>> Fetch http://www.libgd.org//releases/gd-2.0.35.tar.gz
..
installation failed (I forgot the error messages)
After installing xbase47.tgz and repeat the installation of gd, pieces of the following error appears

===> Verifying specs: jpeg.>=62 png.>=2 iconv.>=2 jpeg.>=62 png.>=2 iconv.>=2 c expat fontconfig freetype m z
Missing library for fontconfig
Missing library for freetype
=================================

Previously, I chose file sets without X components. Lately, I have to install some package that requires one or more files sets that are not selected before.
As you recall, when installing OpenBSD, we select the following file sets to be installed:

bsd - This is the Kernel. REQUIRED.
bsd.mp - Multi-processor (SMP) kernel
bsd.rd - RAM disk kernel
base47.tgz - Contains the base OpenBSD system. REQUIRED.
etc47.tgz - Contains all the files in /etc. REQUIRED.
comp47.tgz - Contains the compiler and its tools, headers and libraries.
man47.tgz - Contains man pages
misc47.tgz - Contains misc info, setup documentation
game47.tgz - Contains the games for OpenBSD
xbase47.tgz - Contains the base libraries and utilities for X11
xetc47.tgz - Contains the /etc/X11 and /etc/fonts configuration files
xfont47.tgz - Contains X11's font server and fonts
xserv47.tgz - Contains X11's X servers
xshare47.tgz - Contains manpages, locale settings, includes, etc. for X

For the case above, there are two ways I can do:
First, use the installation media such as CD-ROM, and choose Upgrade (rather than Install).
Second, use tar command to install the file on the root of the filesystem.

I chose the last way and do these:
1. Download these file sets and save them into the directory /home/binsar.
# wget -nd -P /home/binsar http://ftp.jaist.ac.jp/pub/OpenBSD/4.7/i386/xbase47.tgz
# wget -nd -P /home/binsar http://ftp.jaist.ac.jp/pub/OpenBSD/4.7/i386/xshare47.tgz
--2011-01-05 05:38:15-- http://ftp.jaist.ac.jp/pub/OpenBSD/4.7/i386/xshare47.tgz
Connecting to ftp.jaist.ac.jp (ftp.jaist.ac.jp)|150.65.7.130|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2946170 (2.8M) [application/x-gzip]
Saving to: `/home/binsar/xshare47.tgz'
100%[======================================>] 2,946,170 135K/s in 22s
2011-01-05 05:38:37 (131 KB/s) - `/home/binsar/xshare47.tgz' saved [2946170/2946170]

2. Install the file sets into root directory (The 'p' option in the tar command in order to restore the file permissions properly!!!).

#tar xzvphf /home/binsar/xbase47.tgz -C /
#tar xzvphf /home/binsar/xshare47.tgz -C /

3. Update the shared library cache (without rebooting) by run ldconfig to add all the X libraries to the cache:
# ldconfig -m /usr/X11R6/lib


or simply reboot my system, and this will be done automatically by the rc startup script.

4. Try install the gd library
#cd /usr/ports/graphics/gd
#make install clean
# pkg_info
...
autoconf-2.61p3 automatically configure source code on many Un*x platforms
bzip2-1.0.5 block-sorting file compressor, unencumbered
cvsup-16.1hp2-no_x11 network file distribution system
db-4.6.21p0 Berkeley DB package, revision 4
gd-2.0.35p0 library for dynamic creation of images
gdbm-1.8.3p0 GNU dbm
...

Jumat, 08 Oktober 2010

Installation of Mondes' LAB1

Steps to install Mondes' LAB1. This was done remotely via telnet, from 11.50pm to 02.30am.

1. Install Apache web server with prefork MPM (apache-2.0.63_16)
#cd /usr/ports/www/apache20 (released 2008-01-19)
#make install clean
(current Apache is v2.2.16, released 2010-07-25)


2. Install current version of PHP5 (php5-5.3.3_2, released 2010-07-22)
#cd /usr/ports/lang/php5
#make install clean
***************************************************************
Make sure index.php is part of your DirectoryIndex.
You should add the following to your Apache configuration file:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
***************************************************************
This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system.
/usr/local/libexec/apache2/libphp5.so
/usr/local/bin/php
/usr/local/bin/php-cgi

AddType application/x-httpd-php .php <<.html>>
AddType application/x-httpd-php-source .phps


3. Install mysql shared extension for php (php5-mysql-5.3.3_2)
#cd /usr/ports/databases/php5-mysql
#make install clean
***************************************************************
The following line has been added to your /usr/local/etc/php/extensions.ini configuration file to automatically load the installed extension:
extension=mysql.so
***************************************************************


4. Install session shared extension for php (php5-session-5.3.3_2)
#cd /usr/ports/www/php5-session
#make install clean
***************************************************************
The following line has been added to your /usr/local/etc/php/extensions.ini
configuration file to automatically load the installed extension:
extension=session.so
***************************************************************


5. Install gd shared extension for php (php5-session-5.3.3_2)
#cd /usr/ports/graphics/php5-gd
#make install clean
****************************************************************************
The following line has been added to your /usr/local/etc/php/extensions.ini
configuration file to automatically load the installed extension:
extension=gd.so
****************************************************************************

6. Install text-based web browser
#cd /usr/local/www/lynx
#make install clean
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/bin/lynx


7. Make FreeBSD reread the files in the path so it knows what's there
#rehash


8. Adding PHP5 module to Apache
#cd /usr/local/etc/apache2/
===>modify httpd.conf


9. Create test page
# echo ""  >> /usr/local/www/data/tester.php


10.Test the installation
#apachectl start
#lynx localhost/tester.php

ready for web management (RADIUS and Monitoring).

Rabu, 24 Maret 2010

Apache status di Debian dan BSD

1. DEBIAN
debpc:~# uname -a
Linux debpc 2.6.26-2-686 #1 SMP Wed Aug 19 06:06:52 UTC 2009 i686 GNU/Linux

debpc:~# apache2 -v
Server version: Apache/2.2.9 (Debian)Server built: Nov 14 2009 20:23:49
debpc:~# /etc/init.d/apache2 restart
Restarting web server: apache2 ... waiting .

debpc:~# ps -ef | grep apache2 | grep -v grep
root 8825 1 0 08:39 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 8832 8825 0 08:39 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 8833 8825 0 08:39 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 8834 8825 0 08:39 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 8835 8825 0 08:39 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 8836 8825 0 08:39 ? 00:00:00 /usr/sbin/apache2 -k start

debpc:~# ps ax | grep apache2 | grep -v grep
 8825 ? Ss 0:00 /usr/sbin/apache2 -k start
 8832 ? S 0:00 /usr/sbin/apache2 -k start
 8833 ? S 0:00 /usr/sbin/apache2 -k start
 8834 ? S 0:00 /usr/sbin/apache2 -k start
 8835 ? S 0:00 /usr/sbin/apache2 -k start
 8836 ? S 0:00 /usr/sbin/apache2 -k start

debpc:~# ps -ef | grep apache2 | grep -v grep| wc -l
6
debpc:~# netstat -l | grep www
tcp 0 0 192.168.70.11:www *:* LISTEN
tcp 0 0 192.168.70.10:www *:* LISTEN


2. OpenBSD
# uname -a
OpenBSD tobi.binsar.com 4.4 GENERIC#1021 i386

# httpd -v
Server version: Apache/1.3.29 (Unix)

# apachectl stop
/usr/sbin/apachectl stop: httpd stopped

# apachectl start
/usr/sbin/apachectl start: httpd started

# apachectl restart
/usr/sbin/apachectl restart: httpd restarted

# ps axu | grep httpd
www 25207 0.0 0.9 1536 2412 ?? Ss Thu10PM 0:07.98 httpd: parent
www 28902 0.0 0.7 1544 1904 ?? I Thu10PM 0:00.08 httpd: child
www 30060 0.0 0.7 1544 1868 ?? I Thu10PM 0:00.09 httpd: child
www 27591 0.0 0.7 1544 1908 ?? I Thu10PM 0:00.12 httpd: child
www 14283 0.0 0.7 1544 1920 ?? I Thu10PM 0:00.11 httpd: child
www 12608 0.0 0.7 1544 1936 ?? I Thu10PM 0:00.10 httpd: child
www 28818 0.0 0.7 1544 1872 ?? I Thu10PM 0:00.10 httpd: child
www 25051 0.0 0.7 1536 1928 ?? I Thu10PM 0:00.10 httpd: child
www 3824 0.0 0.7 1544 1876 ?? I Fri12AM 0:00.06 httpd: child
www 3047 0.0 0.7 1544 1908 ?? I Fri12AM 0:00.08 httpd: child
www 27223 0.0 0.7 1544 1932 ?? I Fri12AM 0:00.07 httpd: child


3. FreeBSD
fbdpc# uname -a
FreeBSD fbdpc.binsar.com 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Thu Jan 15 16:15:25 WIT 2009 root@fbdpc.binsar.com:/usr/src/sys/i386/compile/FERRYBSD i386

fbdpc# httpd -v
Server version: Apache/2.2.9 (FreeBSD)
Server built: Jan 9 2009 16:10:00

fbdpc# ps ax | grep httpd | grep -v grep
13007 ?? Ss 0:04.31 /usr/local/sbin/httpd -k start
13073 ?? I 0:02.68 /usr/local/sbin/httpd -k start
13074 ?? I 0:02.59 /usr/local/sbin/httpd -k start
13075 ?? I 0:02.45 /usr/local/sbin/httpd -k start
13077 ?? I 0:02.52 /usr/local/sbin/httpd -k start
13078 ?? I 0:02.54 /usr/local/sbin/httpd -k start
13098 ?? I 0:02.03 /usr/local/sbin/httpd -k start
32289 ?? I 0:01.79 /usr/local/sbin/httpd -k start
32290 ?? I 0:01.75 /usr/local/sbin/httpd -k start
32291 ?? I 0:01.66 /usr/local/sbin/httpd -k start
32599 ?? I 0:01.29 /usr/local/sbin/httpd -k start