Friday, February 8, 2008

[Linux] เวลาเราใช้ vmware เพื่อใช้ emu Olive เจอปัญหาเรื่อง console

เวลาเราใช้ vmware เพื่อ emulation Olive ซึ่งโดย default แล้ว olive จะ input/output ทาง console ฉะนั้นทำให้เราไม่สามารถ console กับ vmware ได้
1. ที่ vmware ทำการ add serial port โดยเป็น name pipe
path= /tmp/com1
This end is the server
This other end is an application
2. install software name socat
sudo apt-get install socat
3. run socat
socat -d -d /tmp/com1 pty <-- socat จะทำการ emulate /dev/pts/? จากนั้นเราใช้ minicom use port /dev/pts/?
4. minicom -s

Tuesday, February 5, 2008

[Cisco] Config Router ให้สามารถรับ L2TP over IPSec จาก windows client

aaa new-model
aaa authentication ppp L2TP local
!
username cisco password cisco
!
vpdn enable
!
vpdn-group PPPTP
! Default L2TP VPDN group
accept-dialin
protocol l2tp
virtual-template 10
no l2tp tunnel authentication
!
crypto isakmp policy 10
encr 3des
authentication pre-share
group 2
crypto isakmp key PRESHARED address 0.0.0.0 0.0.0.0
!
!
crypto ipsec transform-set VPN-CLIENT esp-3des esp-sha-hmac
mode transport
crypto ipsec df-bit clear
!
crypto dynamic-map VPN-DYNAMIC-MAP 10
description ## dyanmic crypto map for VPN Users ##
set nat demux
set transform-set VPN-CLIENT
!
!
crypto map VPN-DYNAMIC-CLIENT 10 ipsec-isakmp dynamic VPN-DYNAMIC-MAP
!
interface G0/1
des ### Internet ###
crypto map VPN-DYNAMIC-CLIENT
!
!
interface Virtual-Template10
ip unnumbered Loopback0
peer default ip address pool L2TP_POOL
ppp encrypt mppe 128 required
ppp authentication ms-chap-v2 L2TP
!
ip local pool L2TP_POOL 192.168.1.1 192.168.1.10

#######
Windows XP Setup
1. Start -> Control Panel -> Network Connections
2. Menu File --> New Connection
3. Next --> Select: Connection to the network at my workspace --> Next
4. Select: Virtual Private Network Connection --> Next
5. Enter connection name
6. Select: Do not dial the initial connection --> Next
7. Enter IP Address of VPN Server --> Next --> Finish
8. Show dialog --> Properties --> Security Tab
9. Select: Advanced (customer settings)
10. IPSec Settings --> Use pre-shared key for authentication --> Enter pre-share key --> OK (ex. PRESHARED
11. Enter username,password then Connect (ex. username cisco, password cisco)

[Cisco] ต้องการให้ user ใน LAN ต้อง authentication ก่อนการใช้งาน internet

conf t

aaa new-model
!
!
aaa authentication login default local
aaa authorization exec default local
aaa authorization auth-proxy default local

ip auth-proxy auth-proxy-banner http ^C
Please authentication first before access internet !!!
^C
ip auth-proxy name PROXY_AUTH http inactivity-time 10
!
int f0/0
des ## LAN ##
ip access-group FW in
ip auth-proxy PROXY_AUTH
no sh
!
ip http server
ip http access-class 55
access-list 55 deny any
!
ip access-list extended FW
deny ip any any

##
sh ip access-list FW <-- เมื่อ authen ผ่าน acl จะสร้างโดยอัติโนมัติ
sh ip auth-proxy cache
!
!
User ต้องเรียก web อะไรก็ได้จากนั้นจะถูก redirect page เพื่อไป authentication และเมื่อ username และ password ถูกก็จะสามารถใช้งาน internet ได้

Monday, February 4, 2008

[Cisco] ต้องการดูว่าใครกำลังติดต่ออยู่กับใคร ด้วย ip flow

conf t
ip flow-top-talkers
top 50
sort-by-bytes
int g0/1
des ## connect to internet ##
ip flow ingress
ip flow egress

#sh ip flow top-talker

[Cisco] แก้ไข Numbering Access-list

เมื่อก่อนเวลาเราแก้ไข access-list ที่เป็นตัวเลข เราไม่สามารถลบบางบรรทัดได้ ใน IOS รุ่นใหม่สามารถแก้ไขได้ทำได้โดยใช้ command เหมือนกับ naming access-list
ตัวอย่างเรามี access-list
access-list 100 permit ip 1.1.1.1 0.0.0.0 any
access-list 100 permit ip 2.2.2.2 0.0.0.0 any
access-list 100 permit ip 3.3.3.3 0.0.0.0 any
ต้องการลบ access-list บรรทัดที่ 2
ip access-list extended 100
no permit ip 2.2.2.2 0.0.0.0 any
ต้องการ verify
sh ip access-list 100
access-list 100 permit ip 1.1.1.1 0.0.0.0 any
access-list 100 permit ip 3.3.3.3 0.0.0.0 any

Monday, January 28, 2008

[CCIE] ผ่าน CCIE (R/S) LAB แล้วววววววว

หลังจากสอบครั้งแรกเมื่อ 5 ตุลาคม 2550 ผลออกมา FAIL
พอกลับจากญี่ปุ่นก็อ่านหนังสือ ทำ lab ใหม่อีกครั้งเน้น Multicast กับ QoS
วันที่ 23 มกราคม 2551 ไปสอบ lab อีกครั้ง มั่นใจกว่าครั้งแรกผลออกมา PASS ครับ
ตั้งใจจะสอบ Track Service Provider อีกตัวไม่รู้ว่าจะทำได้หรือเปล่า แต่ก็จะลองสอบดูครับ

Sunday, January 20, 2008

[Cisco] ต้องการ clear tcp connection (bgp, line vty) ของตัว router

วิธี clear tcp connection

R1#sh tcp brief
TCB Local Address Foreign Address (state)
65DA2FF8 160.1.12.1.22 160.1.12.2.55667 ESTAB
R1#cle
R1#clear tcp tcb 65DA2FF8
[confirm]
[OK]
R1#sh tcp brief
R1#

Friday, January 11, 2008

[Cisco] Reflexive Access-list

ต้องการเขียน access-list คล้ายๆ firewall คือต้องมี packet initial ออกจากขา inside router ไป outside ก่อน แล้วถึงจะ permit packet ที่กลับเข้ามา
interface s0
des ** outside **
ip add x.x.x.x y.y.y.y
ip access-group ACL_IN in
ip access-group ACL_OUT out
ip access-list extended ACL_IN
permit tcp any any eq bgp
permit tcp any eq bgp any
permit icmp any any
evaluate REFLEX
ip access-list extended ACL_OUT
permit ip any any REFLEX
referrence:

[Cisco] OSPF เลือก best path

OSPF เลือก bestpath
step1: เลือก type ของ route
1. O Intra Area ( ภายใน area เดียวกัน)
2. IA Inter Area ( ระหว่าง area )
3. E1 External type 1 ( จาก route ที่เกิดจากการ redistribute type 1)
4. E2 External type 2 (จาก router ที่เกิดจากการ redistribute type 2 และ default การ redistribute จะเป็น type 2 )
step2: เลือกค่า cost น้อย
ตัวอย่าง สมมติว่ามี route 192.168.1.0/24 มา 2 ทาง โดย
1. path แรกเป็น type E1 มี cost 100
2. path ที่สองเป้น type E2 มีค่า cost 10
จะเลือก path ใดระหว่าง path 1 หรือ 2 ????

[Cisco] BGP เลือก Best path

GP เลือก Best path มีขั้นตอนคือ

ให้จำคำย่อ
W L L A O M N I
ข้อสำคัญข้อแรกของทุก routing ของการเลือก best path คือ ip next hop จะต้องมีอยู่จริงใน routing
W = Weight (propietary cisco ใช้เฉพาะภายใน router ตัวเดียวเท่านั้น)
L = local preferrence (default เป็น 100)
L = local inject ( route ที่เกิดจากการ inject เข้า BGP ของตัวเอง)
A = AS-path ( เลือก path ที่สั้นที่สุด)
O = Origin code โดยจะเลือกค่า i <>
M = ค่า MED หรือ metric เลือกค่าน้อย
N = Neighbor type เลือก eBGP ก่อน iBGP
I = เอาค่า cost IGP metric ค่าที่น้อยที่สุดของ next hop
ถ้ามีการ config maximum-path และทุกขั้นตอนมีค่าเท่ากัน ก็จะ load-balance
แต่ถ้าไม่มีการ config maximum-path
1.จะเลือก router-id ค่าน้อย
2.ถ้ามีการ config route-reflect ให้เลือก prefix ที่มาจาก cluster-list ที่สั้นที่สุด
3.เลือก neighbor ip address ค่าน้อย
ถ้าเท่ากันทุกขั้นตอนจะ load-balance

[Cisco] BGP สร้างเงื่อนไขในการ advertise

ต้องการสร้างเงื่อนไขในการ advertise network A โดยตรวจสอบก่อนว่า network B นั้นมีอยู่ใน BGP หรือไม่ถ้าไม่มีให้ advertise network A

Ex.
router bgp 100
network 10.10.10.0 mask 255.255.255.0
neighbor 172.16.1.1 remote-as 200
neighbor 172.16.1.1 advertise-map ADVERTISE non-exist-map NON-EXIST
ip prefix-list NETWORK_A permit 10.10.10.0/24
ip prefix-list CHECK_NETWORK_B permit 192.168.1.0 mask 255.255.255.0
route-map ADVERTISE permit 10
match ip address prefix NETWORK_A
route-map NON-EXIST permit 10
match ip address prefix CHECK_NETWORK_B
จากตัวอย่างเรามีการตรวจสอบ BGP routing table ก่อนว่ามี network 192.168.1.0/24 อยู่หรือเปล่า ถ้าไม่มีจะทำการ Advertise 10.10.10.0/24 แต่ถ้ามีจะไม่ advertise

[Cisco] Legacy QoS (guarantee bandwidth)

thank you h**p://awanetwork.blogspot.com/2007/09/custom-queueing.html

QoS | Custom Queueing

CQ implementation WRR, up to 16 user queues, threshold based on number of bytes. Service use Round-robin we need requires configuration. CQ is used to create a bandwidth reservation in output queue of an interface. So no direction option on applied to the interface, fact that queueing is always outbound.

I have simple sample of CQ, objective is guaranteed the following amount of bandwidth that traffic leaving its Ethernet interface. I want 3 traffic define are ftp, telnet www and default for else logical. Each queue would be guaranteed bandwidth in a ratio of 5:2:2:1 on a total value 16000 bytes or 128 kbps, which results in 8000/16000, 3200/16000, 3200/16000, 1600/16000. With the CQ if there is traffic of type A and B waiting to be sent, but no traffic of type C, type A and B are not limited to a maximum of 50% and 20%. Instead A and B are guaranteed a minimum of 50% and 20% in the case of congestion.

#final running-config

...
queue-list 1 protocol ip 1 tcp ftp
queue-list 1 protocol ip 2 tcp telnet
queue-list 1 protocol ip 3 tcp www
queue-list 1 default 4
queue-list 1 queue 1 byte-count 8000
queue-list 1 queue 2 byte-count 3200
queue-list 1 queue 3 byte-count 1600

interface FastEthernet0/0
ip address 192.168.0.1 255.255.255.0
duplex auto
speed auto
custom-queue-list 1
...


#step-by-step configuring define queue (required)
R1(config)#queue-list ?
<1-16> Queue list number

R1(config)#queue-list 1 ?
default Set custom queue for unspecified datagrams
interface Establish priorities for packets from a named interface
lowest-custom Set lowest number of queue to be treated as custom
protocol priority queueing by protocol
queue Configure parameters for a particular queue
stun Establish priorities for stun packets

R1(config)#queue-list 1 protocol ?
aarp AppleTalk ARP
appletalk AppleTalk
arp IP ARP
bridge Bridging
bstun Block Serial Tunnel
cdp Cisco Discovery Protocol
clns ISO CLNS
clns_es ISO CLNS End System
clns_is ISO CLNS Intermediate System
cmns ISO CMNS
compressedtcp Compressed TCP (VJ)
decnet DECnet
decnet_node DECnet Node
decnet_router-l1 DECnet Router L1
decnet_router-l2 DECnet Router L2
dlsw Data Link Switching (Direct encapsulation only)
http HTTP
ip IP
ipv6 IPV6
ipx Novell IPX
llc2 llc2
pad PAD links
pppoe PPP over Ethernet
qllc qllc protocol
rsrb Remote Source-Route Bridging
snapshot Snapshot routing support
stun Serial Tunnel

R1(config)#queue-list 1 protocol ip ?
<0-16> queue number

R1(config)#queue-list 1 protocol ip 1 ?
fragments Prioritize fragmented IP packets
gt Classify packets greater than a specified size
list To specify an access list
lt Classify packets less than a specified size
tcp Prioritize TCP packets 'to' or 'from' the specified port
udp Prioritize UDP packets 'to' or 'from' the specified port


R1(config)#queue-list 1 protocol ip 1 tcp ?
<0-65535> Port number
bgp Border Gateway Protocol (179)
chargen Character generator (19)
cmd Remote commands (rcmd, 514)
daytime Daytime (13)
discard Discard (9)
domain Domain Name Service (53)
drip Dynamic Routing Information Protocol (3949)
echo Echo (7)
exec Exec (rsh, 512)
finger Finger (79)
ftp File Transfer Protocol (21)
ftp-data FTP data connections (20)
gopher Gopher (70)
hostname NIC hostname server (101)
ident Ident Protocol (113)
irc Internet Relay Chat (194)
klogin Kerberos login (543)
kshell Kerberos shell (544)
login Login (rlogin, 513)
lpd Printer service (515)
nntp Network News Transport Protocol (119)
pim-auto-rp PIM Auto-RP (496)
pop2 Post Office Protocol v2 (109)
pop3 Post Office Protocol v3 (110)
smtp Simple Mail Transport Protocol (25)
sunrpc Sun Remote Procedure Call (111)
syslog Syslog (514)
tacacs TAC Access Control System (49)
talk Talk (517)
telnet Telnet (23)
time Time (37)
uucp Unix-to-Unix Copy Program (540)
whois Nicname (43)
www World Wide Web (HTTP, 80)

R1(config)#queue-list 1 protocol ip 1 tcp ftp ?


#step-by-step configuring specify queue (optional)
R1(config)#queue-list 1 ?
default Set custom queue for unspecified datagrams
interface Establish priorities for packets from a named interface
lowest-custom Set lowest number of queue to be treated as custom
protocol priority queueing by protocol
queue Configure parameters for a particular queue
stun Establish priorities for stun packets

R1(config)#queue-list 1 queue ?
<0-16> queue number

R1(config)#queue-list 1 queue 1 ?
byte-count Specify size in bytes of a particular queue
limit Set queue entry limit of a particular queue

R1(config)#queue-list 1 queue 1 byte-count ?
<1-16777215> size in bytes

o use byte-count for average number of bytes
o use limit for maximum number of packet

#step-by-step configuring applied on interface (required)
R1(config-if)#?
Interface configuration commands:
...
custom-queue-list Assign a custom queue list to an interface
...

R1(config-if)#custom-queue-list ?
<1-16> Custom queue list number

R1(config-if)#custom-queue-list 1 ?


#monitor or verify CQ (optional)
R1#sh int f0/0
FastEthernet0/0 is up, line protocol is up
Hardware is Gt96k FE, address is c200.02d4.0000 (bia c200.02d4.0000)
Internet address is 192.168.0.1/24
MTU 1500 bytes, BW 10000 Kbit, DLY 1000 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Half-duplex, 10Mb/s, 100BaseTX/FX
ARP type: ARPA, ARP Timeout 04:00:00
Last input never, output 00:00:03, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: custom-list 1
Output queues: (queue #: size/max/drops)
0: 0/20/0 1: 0/20/0 2: 0/20/0 3: 0/20/0 4: 0/20/0
5: 0/20/0 6: 0/20/0 7: 0/20/0 8: 0/20/0 9: 0/20/0
10: 0/20/0 11: 0/20/0 12: 0/20/0 13: 0/20/0 14: 0/20/0
15: 0/20/0 16: 0/20/0
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
0 packets input, 0 bytes
Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog
0 input packets with dribble condition detected
92 packets output, 9553 bytes, 0 underruns
0 output errors, 0 collisions, 2 interface resets
0 babbles, 0 late collision, 0 deferred
0 lost carrier, 0 no carrier
0 output buffer failures, 0 output buffers swapped out

R1#sh queueing ?
interface
custom custom queueing list configuration
fair fair queueing configuration
priority priority queueing list configuration
random-detect random early detection configuration
| Output modifiers


R1#sh queueing custom ?
| Output modifiers


R1#sh queueing custom
Current custom queue configuration:

List Queue Args
1 4 default
1 1 protocol ip tcp port ftp
1 2 protocol ip tcp port telnet
1 3 protocol ip tcp port www
1 1 byte-count 8000
1 2 byte-count 3200
1 3 byte-count 1600

[Cisco] Object tracking w/ SLA

กรณีต้องการตรวจสอบ static route และ nexthop ว่าสามารถ reachable ได้หรือเปล่า

ip sla monitor 1 <-- id 1 type echo protocol ipIcmpEcho 192.168.1.1 <------ check next-hop 192.168.1.1 can reachable ( ping ) frequency <-- option สำหรับ ระยะเวลาในการ Monitor แต่ละรอบเวลา( interval ) ip sla monitor schedule 1 life forever start-time now <----- start operation id 1 track 1 rtr 1 <-- track id 1 ให้มีการอ้างอิง ip sla monitor 1 ip route 1.1.1.1 255.255.255.255 fast0/0 192.168.1.1 track 1 <-- มีการ config static route โดยชี้ next-hop ออกทาง interface f0/0 -> 192.168.1.1 และก่อนที่จะ install เข้าไปใน routing table ให้ตรวจสอบ track id 1 ว่า state up หรือไม่

#sh track 1 <-- display track id 1 operation state
#sh ip sla monitor operational-state 1 <-- display operation-state sla id 1
#sh ip sla monitor configuration 1 <-- display configuration sla id 1 detail

[Cisco] ทำ acl สำหรับ ตรวจสอบ mac-address และ ip address

Dynamic ARP Inspection

vlan 500
name CLIENT
ip arp inspection vlan 500
ip arp inspection validate src-mac ip
ip arp inspection filter ARP1 vlan 500 static

arp access-list ARP1
permit ip host 192.168.1.1 mac host 0010.8ba1.aabb

interface GigabitEthernet1/0/12
switchport access vlan 500
switchport mode access
end

Thursday, August 9, 2007

[Linux] perl script สำหรับไป show config ของ cisco

perl script สำหรับเก็บ config cisco โดยดึงข้อมูลจาก Database ของ cacti แล้ว telnet ไป show running-config แล้วมาเก็บไว้ จากนั้นก็ทำการ compare กับของเดิมที่มีอยู่โดยใช้ unix diff command ถ้า config มีการเปลี่ยนแปลงให้ส่งเมล์

#!/usr/bin/perl
use Net::Telnet::Cisco;
use DBI();
use File::Copy;
use MIME::Lite;
#$|++;

$diff_cmd ="/usr/bin/diff -b -B -i -w ";
$mail_server = "mail.server.co.th";
$mail_from = 'tacacs@server.co.th';
$mail_to = 'admin@server.co.th';

$username = 'cisco_priv15';
$password = 'cisco_password';

$db_name = 'cacti';
$db_username = 'cacti';
$db_password = 'cacti';

$mail_diff_enable = 1;
$mail_diff_alert = 0;


($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;

$backup_path = sprintf "./config-backup/%4d%02d%02d", $year+1900,$mon+1,$mday;
$backup_lastest = "./config-backup/lastest";
$mail_data ="";
$config_change_count = 0;
mkdir($backup_path);

# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=localhost",$db_username,$db_password,{'RaiseError' => 1});
my $sth = $dbh->prepare("SELECT id,description,hostname FROM host WHERE hostname != '127.0.0.1' and disabled != 'on' ");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
#print "Found a row: id = $ref->{'id'}, description = $ref->{'description'}, hostname = $ref->{'hostname'}\n";

$session = ""; # restore to default value
my $session = Net::Telnet::Cisco->new(Host => $ref->{'hostname'}, Errmode => "return");
if($session){
$session->login($username, $password);

$session->cmd('term len 0');
@output = $session->cmd('show running-config');
$num = @output;

if($num > 2 ){
$backup_file = $backup_path."/".$ref->{'description'}."_".$ref->{'hostname'}.".cfg";
$backup_lastest_file = $backup_lastest."/".$ref->{'description'}."_".$ref->{'hostname'}.".cfg";
#print "backup file: $backup_file\n";
#print "backup lastest file: $backup_lastest_file\n";
open(FP,">$backup_file");
for( $i = 3 ; $i < $num ; $i++){ # suppress header file
$cfg = $output[$i];
print FP $cfg;
}
if( -e "$backup_lastest_file"){
$diff = `$diff_cmd $backup_lastest_file $backup_file`;
if($diff){
$mail_data = $mail_data."#==============================================\n";
$mail_data = $mail_data."# Hostname: ".$ref->{'description'}." (".$ref->{'hostname'}.")\n";
$mail_data = $mail_data."#==============================================\n";
$mail_data = $mail_data."$diff\n";
$mail_diff_alert = 1;
$config_change_count++;
#print $mail_data;
}
}
copy($backup_file, $backup_lastest_file);
close(FP);
}


$session->close;
}else{
print "Can't remote telnet to $ref->{'hostname'}\n";
}
}
if($mail_diff_alert && $mail_diff_enable){
$msg = MIME::Lite->new(
From =>"$mail_from",
To =>"$mail_to",
Subject =>"Config has modified $config_change_count host(s) : $time",
Data =>"$mail_data");
$msg->send('smtp', "$mail_server", Timeout=>60);
}

$sth->finish();

$dbh->disconnect();