Tuesday, May 29, 2007

[Linux] setup jffnms แล้วจะ create postgresql database แล้ว error

แก้ไข
vi /var/lib/pgsql/data/pg_hba.conf
เพิ่ม
local all all trust
host all all 127.0.0.1 255.255.255.255 trust
แล้ว restart

Thursday, May 24, 2007

[Linux] Squid จะต้องการให้มีการ redirect url โดยดูจาก source ip

จะใช้ squid ทำตัวเป็น redirector โดยให้ดูจาก rule ที่กำหนด
#vi /etc/squid/squid.conf
url_rewrite_program /home/kitti/squid_redirect.pl
#vi /home/kitti/squid_redirect.pl

#!/usr/bin/perl
$|=1;

sub print_log
{
local($msg) = @_;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$time=sprintf "%4d-%02d-%02d %02d:%02d:%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec;
open(LOG,"+>>$log_file");
print LOG "$time : $msg";
close(LOG);
}

$rules_file = "/etc/squid/rules.conf";
$log_file = "/var/log/squid/redirect.log";
open (RULE,$rules_file);
&print_log("-- redirector start --\n");
while (<>) {
@X = split;
seek(RULE,0,0);
$url = $X[0];
($ip,$fqdn) = split(/\//,$X[1]);
$number=1;
$flag=0;
$line_no=0;
$go_url = $url;
while(){
chomp;
$line = $_;
if((!($line =~ /^[\#\;\t ]/))&&($line)){
($src_ip,$dst_url,$action,$redirect) = split(/[ |\t]+/,$line);
if(($url =~ /$redirect/)&&($ip =~ /$src_ip/)) {
$flag = 1;
$go_url = $url;
$action = "direct-to";
}elsif (($url =~ /$dst_url/)&&($ip =~ /$src_ip/)) {
$line_no = $number;
if($action eq 'bypass'){
$go_url = $url;
$flag = 1;
}elsif ($action eq 'redirect-to'){
$go_url = "302:$redirect";
$flag = 1;
}
}
}
$number++;
if($flag){ last; }
}
print "$go_url\n";
#&print_log("squid request: @X\n");
&print_log("ip:$ip, url:$url, rule:$line_no, action:$action, redirect:$go_url\n");

}
close(RULE);
&print_log("-- redirector exit-- \n");
exit(0);
#===============================================================

#vi /etc/squid/rules.conf
# description
;src-ip url action
1.1.1.1 www.domain1.com bypass
127.0.0.1 www.domain2.co.th bypass
.* www.domain3.com bypass
.* domain4.co.th bypass
.* .* redirect-to http://www.default-domain.co.th

Wednesday, May 16, 2007

[Linux] ใช้ firefox บน ubuntu แล้วเปิด Link ที่เป็น telnet:// ไม่ได้

อันเนื่องมาจากเปิด www.traceroute.org แล้วจะให้ firefox เรียก telnet ขึ้นมาให้เลย
1. ที่ address bar พิมพ์ about:config
2. click ขวา แล้วเลือก new->boolean
network.protocol-handler.external.telnet = true แล้ว Ok
3. click ขวาเพิ่มอีก new->string
network.protocol-handler.app.telnet = /usr/bin/firefox-telnet.sh
4. sudo vi /usr/bin/firefox-telnet.sh

#!/bin/bash
gnome-terminal -e "telnet ${1##telnet://}"

Wednesday, May 2, 2007

[CCIE] วันนี้มาคุยเรื่อง Cisco 7200 Simulator กัน

ขอขอบคุณ
http://www.ipflow.utc.fr/blog/
http://dynagen.org/
http://hacki.at/7200emu/

สำหรับคนที่ต้องการทำ lab ของinternetworkexpert iewb v4. โดยอุปกรณ์ของผมมีดังนี้
- Notebook DELL D620 Core2Duo 1.83 Ram 2G x 1 (OS Linux Ubuntu 7.04 ผมรู้สึกว่ามันเร็วกว่า XP)
- Catalyst 3750 x 4
- Catalyst 2950 x 1
- USB hub 4 port
- USB ethernet x 3 (เวลาไปซื้อเอาที่เป็น chipset realtek rtl8150 )น่ะครับแพงหน่อยประมาณ 500บาท ที่พันธ์ทิพย์ มันจะมียี้ห้อราคาถูกแนะนำว่าอย่าไปซื้อน่ะครับมันเห็นพร้อมกันไม่ได้มาก ที่จริงแล้วควรซื้อมาเท่ากับจำนวนของ router ที่ต่อออกไป switch 4 ตัวผมนับดูแล้วประมาณ 12 ตัวครับ แต่พอดีผมมี 2950 อยู่ก็เลยจะทำ trunk จาก DELL ไปหา 2950 แล้วต่อจาก 2950 ไปหา core switch ทั้ง 4 ตัวเพื่อประหยัด USB ethernet (แต่จะมี R6 ต่อไปหา core switchไม่ผ่าน 2950 ต้องใช้ usb ethernet ต่อกันตรงๆ เพราะว่าจะต้อง enable 802.1q ที่ R6 ด้วย)

จากตัว simulator มันค่อนข้างจะบริโภค CPU กับ RAM ครับ idea ของผมก็คือทุกอย่างที่ run อยู่จะต้องอยู่บน ram เพราะว่าเวลา access จะได้เร็วๆ และก็ใช้ idlepc, ghostios
ถ้าใครมี idea ดีก็บอกด้วยน่ะครับ
- สร้าง ramdisk 384M เพื่อที่จะได้ access ที่ ram จะได้เร็วๆกว่า harddisk (make_ramdisk.sh)
vi /boot/grub/menu.lst
kernel /boot/vmlinuz-2.6.20-15-lowlatency root=UUID=cd4fa939-5e2a-4450-82fb-45a11a435658 ro quiet splash verbose ramdisk_size=384000

แล้วก็ reboot

vi make_ramdisk.sh
#!/bin/sh

dd if=/dev/zero of=/dev/ram0 bs=1k count=384000
mke2fs -vm0 /dev/ram0 384000
mkdir -p /mnt/ramdisk
mount /dev/ram0 /mnt/ramdisk
mkdir -p /mnt/ramdisk/working
เวลา run script
$sudo ./make_ramdisk.sh

- สร้าง interface trunking ระหว่าง linux กับ 2950 (make_if_trunk.sh)
eth2 ทำเป็น mode promiscuous ด้วยไม่งั้นเดี๋ยวมีปัญหาเรื่องรับ packet multicast จุดนี้ผมงงอยู่หลายวัน พอ on ospf R1 กับ SW1 มันไม่ได้ทั้งๆที่เห็น multicast packet ออกจาก SW1 แล้ว ใช้ tcpdump มาจับ packet ดูก็ไม่เห็น ปรากฏว่า tcpdump มันไม่ทำตัวเป็น promisc ตั้งแต่ linux kernel 2.2+ จึงไม่เห็น multicast ที่เข้ามา แต่พอใช้ program ethereal มา sniff packet แล้วสามารถใช้ได้ในช่วงที่ sniff packet เหตุเพราะตัว linux เองมันก็จะ discard packet ที่ destination ไม่ใช่ตัวมันเอง เลยจึงจำเป็นต้องทำเป็น Mode สำส่อนเลย
#!/bin/sh
echo "Loading 802.1q module"
modprobe 8021q
ifconfig eth2 down
ifconfig eth3 down
ifconfig eth4 down
ifconfig eth2 promisc up
ifconfig eth3 promisc up
ifconfig eth4 promisc up
echo "Configuring VLAN_id to interface eth2"
vconfig add eth2 2
vconfig add eth2 3
vconfig add eth2 4
vconfig add eth2 5
vconfig add eth2 6
vconfig add eth2 7
vconfig add eth2 8
vconfig add eth2 9
vconfig add eth2 10
vconfig add eth2 11
echo "Creating interface for each vlans"
ifconfig eth2.2 promisc up
ifconfig eth2.3 promisc up
ifconfig eth2.4 promisc up
ifconfig eth2.5 promisc up
ifconfig eth2.6 promisc up
ifconfig eth2.7 promisc up
ifconfig eth2.8 promisc up
ifconfig eth2.9 promisc up
ifconfig eth2.10 promisc up
ifconfig eth2.11 promisc up

เวลา run script
$sudo ./make_if_trunk.sh

- ทำการ run process dynamips (start-dynamips.sh)
#!/bin/sh
cd /var/log/
sudo nice dynamips -H 3601 &
sudo nice dynamips -H 3602 &
sudo nice dynamips -H 3603 &
sudo nice dynamips -H 3604 &
sudo nice dynamips -H 3605 &
sudo nice dynamips -H 3606 &
sudo nice dynamips -H 3607 &
sudo nice dynamips -H 3608 &
sudo nice dynamips -H 3609 &
sudo nice dynamips -H 3610 &

เวลา run script
$sudo ./start-dynamips.sh

- script สำหรับ run dynagen (start-ccie-x.sh)
#!/bin/sh
cp -f /home/kitti/DATA/Dynamips/iewb4/working/c3600_R[1-6]_nvram /mnt/ramdisk/working/
sudo -u kitti /usr/local/dynagen/dynagen /home/kitti/DATA/Dynamips/iewb4/config/ccie-x.net
echo "Sync data..please wait...."
cp -f /mnt/ramdisk/working/* /home/kitti/DATA/Dynamips/iewb4/working/

เวลา run script
$sudo ./start-ccie-x.sh

- config file ของ dynagen (ccie-x.net)

#------------------------------------------
#Begin Dynagen config file
autostart = False
ghostios = true
sparsemem = true
mmap = false

###############################################################################
#
# Internetwork Expert Routing & Switching topology Version 4.0 mappings for dynamips/dynagen
# by: Brian McGahan, CCIE #8593
# bmcgahan@internetworkexpert.com
#
# For more information:
# Dynamips: http://www.ipflow.utc.fr/index.php/Cisco_7200_Simulator
# Dynagen: http://dyna-gen.sourceforge.net/
# Hacki's Forum: http://hacki.at/7200emu/index.php
# Internetwork Expert's Forum: http://forum.internetworkexpert.com
#
###############################################################################

##################################################
#
# Define global router parameters for instance 1
#
##################################################


[localhost:3601]
udp = 11000

workingdir = /mnt/ramdisk/working

[[3640]]
#
# Specify 3640 IOS image on Windows here:
image = /home/kitti/DATA/Dynamips/iewb4/images/c3640-jk9o3s-m.123-21.bin

ram = 73
disk0 = 0
disk1 = 0

[[Router R1]]
model = 3640
console = 2001
slot0 = NM-1FE-TX
slot1 = NM-4T
F0/0 = NIO_gen_eth:eth2.11
S1/0 = FRSW 1
idlepc = 0x6046e3ec


##################################################
#
# Define global router parameters for instance 2
#
##################################################


[localhost:3602]
udp = 12000

workingdir = /mnt/ramdisk/working
[[3640]]
#
# Specify 3640 IOS image on Windows here:
image = /home/kitti/DATA/Dynamips/iewb4/images/c3640-jk9o3s-m.123-21.bin

ram = 73
disk0 = 0
disk1 = 0

[[Router R2]]
model = 3640
console = 2002
slot0 = NM-1FE-TX
slot1 = NM-4T
F0/0 = NIO_gen_eth:eth2.2
S1/0 = FRSW 2
idlepc = 0x6046e3ec


##################################################
#
# Define global router parameters for instance 3
#
##################################################


[localhost:3603]
udp = 13000

workingdir = /mnt/ramdisk/working
[[3640]]
#
# Specify 3640 IOS image on Windows here:
image = /home/kitti/DATA/Dynamips/iewb4/images/c3640-jk9o3s-m.123-21.bin

ram = 73
disk0 = 0
disk1 = 0

[[Router R3]]
model = 3640
console = 2003
slot0 = NM-4E
slot1 = NM-4T
S1/0 = FRSW 3
S1/1 = FRSW 13
S1/2 = R1 S1/1
S1/3 = R2 S1/1
E0/0 = NIO_gen_eth:eth2.3
E0/1 = NIO_gen_eth:eth2.4
idlepc = 0x6046e3ec


##################################################
#
# Define global router parameters for instance 4
#
##################################################


[localhost:3604]
udp = 14000

workingdir = /mnt/ramdisk/working
[[3640]]
#
# Specify 3640 IOS image on Windows here:
image = /home/kitti/DATA/Dynamips/iewb4/images/c3640-jk9o3s-m.123-21.bin

ram = 73
disk0 = 0
disk1 = 0

[[Router R4]]
model = 3640
console = 2004
slot0 = NM-4E
slot1 = NM-4T
E0/0 = NIO_gen_eth:eth2.5
E0/1 = NIO_gen_eth:eth2.6
S1/0 = FRSW 4
S1/1 = R5 S1/1
idlepc = 0x6046e3ec


##################################################
#
# Define global router parameters for instance 5
#
##################################################


[localhost:3605]
udp = 15000

workingdir = /mnt/ramdisk/working
[[3640]]
#
# Specify 3640 IOS image on Windows here:
image = /home/kitti/DATA/Dynamips/iewb4/images/c3640-jk9o3s-m.123-21.bin

ram = 73
disk0 = 0
disk1 = 0

[[Router R5]]
model = 3640
console = 2005
slot0 = NM-4E
slot1 = NM-4T
E0/0 = NIO_gen_eth:eth2.7
E0/1 = NIO_gen_eth:eth2.8
S1/0 = FRSW 5
idlepc = 0x6046e3ec


##################################################
#
# Define global router parameters for instance 6
#
##################################################


[localhost:3606]
udp = 16000

workingdir = /mnt/ramdisk/working
[[3640]]
#
# Specify 3640 IOS image on Windows here:
image = /home/kitti/DATA/Dynamips/iewb4/images/c3640-jk9o3s-m.123-21.bin

ram = 73
disk0 = 0
disk1 = 0

[[Router R6]]
model = 3640
console = 2006
slot0 = NM-4E
slot1 = NM-4T
E0/0 = NIO_gen_eth:eth3
E0/1 = NIO_gen_eth:eth4
S1/0 = FRSW 6
idlepc = 0x6046e3ec


##################################################
#
# Define global router parameters for instance 11
#
##################################################


[localhost:3607]
udp = 17000

workingdir = /mnt/ramdisk/working
[[3640]]
#
# Specify 3640 IOS image on Windows here:
image = /home/kitti/DATA/Dynamips/iewb4/images/c3640-jk9o3s-m.123-21.bin

ram = 73
disk0 = 0
disk1 = 0

[[Router BB1]]
model = 3640
console = 2007
slot1 = NM-4T
S1/0 = BB3 S1/0
S1/1 = FRSW 21
cnfg = /home/kitti/DATA/Dynamips/iewb4/working/BB1.initial.config.txt
idlepc = 0x6046e3ec



##################################################
#
# Define global router parameters for instance 12
#
##################################################


[localhost:3608]
udp = 18000

workingdir = /mnt/ramdisk/working
[[3640]]
#
# Specify 3640 IOS image on Windows here:
image = /home/kitti/DATA/Dynamips/iewb4/images/c3640-jk9o3s-m.123-21.bin

ram = 73
disk0 = 0
disk1 = 0

[[Router BB2]]
model = 3640
console = 2008
slot0 = NM-4E
E0/0 = NIO_gen_eth:eth2.9
cnfg = /home/kitti/DATA/Dynamips/iewb4/working/BB2.initial.config.txt
idlepc = 0x6046e3ec



##################################################
#
# Define global router parameters for instance 13
#
##################################################


[localhost:3609]
udp = 19000

workingdir = /mnt/ramdisk/working
[[3640]]
#
# Specify 3640 IOS image on Windows here:
image = /home/kitti/DATA/Dynamips/iewb4/images/c3640-jk9o3s-m.123-21.bin

ram = 73
disk0 = 0
disk1 = 0

[[Router BB3]]
model = 3640
console = 2009
slot0 = NM-4E
slot1 = NM-4T
E0/0 = NIO_gen_eth:eth2.10
E0/3 = NIO_gen_eth:eth0
cnfg = /home/kitti/DATA/Dynamips/iewb4/working/BB3.initial.config.txt
idlepc = 0x6046e3ec


##################################################
#
# Define Frame-relay parameter
#
##################################################

[[FRSW FRSW]]

# R1 to FRSW
1:102 = 2:201
1:103 = 3:301
1:113 = 13:311
1:104 = 4:401
1:105 = 5:501

# R2 to FRSW
2:203 = 3:302
2:213 = 13:312
2:204 = 4:402
2:205 = 5:502

# R3 to FRSW
3:304 = 4:403
3:305 = 5:503
13:314 = 4:413
13:315 = 5:513

# R4 to FRSW
4:405 = 5:504

# R6 to FRSW
6:51 = 21:51
6:100 = 21:100
6:101 = 21:101
6:201 = 21:201
6:301 = 21:301
6:401 = 21:401

#End Dynagen config file
#------------------------------------------

- สุดท้ายก็ IOS ของ router ที่จะใช้ครับ