Thứ Ba, 13 tháng 5, 2014

TDR Cable Test on EX switches

 http://dataplumber.wordpress.com/2012/02/24/tdr-cable-test-on-ex-switches-cli-procedure/

TDR Cable Test on EX switches – CLI procedure…

24 02 2012

1 Votes

I recently wrote up my experience with a cable-test wizard in the JWeb interface, and was prompted to give it a go at the CLI. Turns out you can do that too of course…

First, kick the test off:
root@EX4200> request diagnostics tdr start interface ge-1/0/2    

Interface TDR detail:
Test status                     : Test successfully executed  ge-1/0/2 

{master:0}
root@EX4200>
You need to wait a while for the test to run before typing the command to show the results – if you’re too keen you will see this:
root@EX4200> show diagnostics tdr interface ge-1/0/2 

Interface TDR detail:
Interface name                  : ge-1/0/2
Test status                     : Started

{master:0}
root@EX4200>
After about 30 seconds, issue the command again and you’ll see the results:
root@EX4200> show diagnostics tdr interface ge-1/0/2    

Interface TDR detail:
Interface name                  : ge-1/0/2
Test status                     : Passed
Link status                     : Down
MDI pair                        : 1-2
  Cable status                  : Open
  Distance fault                : 3 Meters
  Polartiy swap                 : N/A
  Skew time                     : N/A
MDI pair                        : 3-6
  Cable status                  : Open
  Distance fault                : 3 Meters
  Polartiy swap                 : N/A
  Skew time                     : N/A
MDI pair                        : 4-5
  Cable status                  : Open
  Distance fault                : 2 Meters
  Polartiy swap                 : N/A
  Skew time                     : N/A
MDI pair                        : 7-8
  Cable status                  : Open
  Distance fault                : 3 Meters
  Polartiy swap                 : N/A
  Skew time                     : N/A
Channel pair                    : 1
  Pair swap                     : N/A
Channel pair                    : 2
  Pair swap                     : N/A
Downshift                       : N/A   
                                        
{master:0}
root@EX4200> 

Thứ Hai, 5 tháng 5, 2014

check IP with Python

#!/usr/bin/python
import os, smtplib
from threading import Thread

def sendmail(subject):
        "Sends an email to the specified recipent "
        username = 'hoangtienthanh@gmail.com'
        password = 'xxxx'

        server = smtplib.SMTP('smtp.gmail.com:587')
        server.starttls()
        server.login(username, password)

        fromAddr ='hoangtienthanh@gmail.com'
        toAddr = 'thanhht@ssgroup.com.vn'

        header = 'To: ' + toAddr + '\n' + 'From: ' + fromAddr + '\n' + 'Subject: ' + subject + '\n'
        msg = header + '\nCheck it now!\n'

        server.sendmail(fromAddr, toAddr, msg)
        server.close()

def checkIpDown(ip):
           ISP = ip
           ret = os.system('ping -c 3 ' + ip + ' &> /dev/null')
           fr = open(ip,"r")
           str = fr.read(1)
           fr.close()
    if ISP == "123.30.173.189":
        ISP = "VNPT Internet"
    elif ISP == "123.30.173.190":
        ISP = "VNPT WAN"
    elif ISP == "192.168.10.100":
        ISP = "FPT Internet"
    elif ISP == "192.168.10.101":
        ISP = "FPT WAN"
           if ret != 0 and str == "1":                   
        message = ISP+'  has been DOWN '
        sendmail(message)
        fo1 = open(ip,"w")
        fo1.write("0")
        fo1.close()
        print message
        elif (ret == 0 and str == "0") :
               message = ISP+' has been UP '
           sendmail(message)
               fo2 = open(ip,"w")
               fo2.write("1")
               fo2.close()
           print message
        elif (ret != 0 and str == "0") :
                print ISP, " network not connect " # Co the xoa dong nay

# 173.189: VNPT Internet
# 173.190: VNPT WAN
# 10.100 : FPT Internet
# 10.101 : FPT WAN
ip2Check = ['123.30.173.189','123.30.173.190','192.168.10.100','192.168.10.101']

for ip in ip2Check:
        t = Thread(target=checkIpDown, args=(ip,))
        t.start()

 Note: please, begin, create file name 123.30.173.189, 123.30.173.190, 192.168.10.100 , 192.168.10.101 with content 0 (down) or 1 (up)

freshinstall on Centos

cent5repo() { yum -y groupinstall "Development Tools" yum -y install wget wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm rpm -i rpmforge-release-0.5.2-2.el5.rf.*.rpm } cent6repo() { yum -y groupinstall "Development Tools" yum -y install wget wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt rpm -K rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm rpm -ivh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm } installbase() { yum install -y ntp.x86_64 nc.x86_64 tcpdump.x86_64 } vntimezone() { rm -rf /etc/localtime; cp /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime; /etc/init.d/ntpd stop; ntpdate 0.centos.pool.ntp.org; /etc/init.d/ntpd start } disselinux() { echo "SELINUX=disabled" > /etc/selinux/config; echo "SELINUXTYPE=targeted" >> /etc/selinux/config; setenforce 0 } mkbasedir() { mkdir -p /ssg/script /data /source /report/output /report/shell_log chmod 777 /report/shell_log } shellogging() { echo 'DATE=`date +%d-%m-%y.%H:%M:%S`' >> /etc/profile echo "USERL=`whoami`" >> /etc/profile echo 'touch /report/shell_log/$USERL.$DATE' >> /etc/profile echo 'FILE_LOGGING=/report/shell_log/$USERL.$DATE' >> /etc/profile echo 'script -q -a -f $FILE_LOGGING' >> /etc/profile } sshkeyconfig() { if [ ! -d /root/.ssh ]; then mkdir /root/.ssh chmod 755 /root/.ssh fi if [ -f /root/.ssh/authorized_keys ]; then mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk fi cp authorized_keys /root/.ssh/authorized_keys chmod 0600 /root/.ssh/authorized_keys cp -r tunnel_keys /root/.ssh/ chmod 755 /root/.ssh/tunnel_keys chmod 0600 /root/.ssh/tunnel_keys/tunnel_key.dsa } sshdconfig() { mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bk cp sshd_config /etc/ssh/ /etc/init.d/sshd restart } if [ "$1" = "centos5" ]; then echo xxxxxx cent5repo cent5repo echo xxxxxx disselinux disselinux echo xxxxxx installbase installbase echo xxxxxx vntimezone vntimezone echo xxxxxx mkbasedir mkbasedir echo xxxxxx shellogging shellogging echo xxxxxx sshdconfig sshdconfig echo xxxxxx sshkeyconfig sshkeyconfig elif [ "$1" = "centos6" ]; then echo xxxxxx cent5repo cent5repo echo xxxxxx disselinux disselinux echo xxxxxx installbase installbase echo xxxxxx vntimezone vntimezone echo xxxxxx mkbasedir mkbasedir echo xxxxxx shellogging shellogging echo xxxxxx sshdconfig sshdconfig echo xxxxxx sshkeyconfig sshkeyconfig elif [ "$1" = "--help" -o "$1" = "" ]; then echo ' run ./freshinstall.sh {option} or ./freshintall.sh --help option: centos5: if you want to install for centos5.x centos6: if you want to install for centos6.x ' fi

AD Authentication with RHEL 6

We’ve been using AD authentication with our RHEL and CENTOS 4 and 5 systems for some time, now, so I was anxious to see what kinds of changes might have come up with RHEL6. Not much, happily, but there was one change that took a little while to figure out. We’ll run through all the steps, from beginning to end, here.


Install the prerequisites

We’re using samba and samba-winbind for this, so make sure these are installed.
yum install samba samba-winbind
If you’re running RHEL5 and a Windows 2008 R2 domain, you’ll want to use samba3x, instead of the samba. See this article for more information on that front.

Edit the Configuration Files

you’ll want to have the following settings. I’ve grouped them here to make it all more readable. Changes from the default are in blue.

/etc/krb5.conf

default_realm = EXAMPLE.COM dns_lookup_realm = true dns_lookup_kdc = true ticket_lifetime = 24h renew_lifetime = 7d forwardable = yes [realms] EXAMPLE.COM = { default_domain = example.com } [domain_realm] .example.com = EXAMPLE.COM example.com = EXAMPLE.COM
Here we’re defining the kerberos realm and domains. “example.com” will be replaced with your AD domain name. Do note the capitalization; it matters.

/etc/samba/smb.conf

workgroup = example realm = EXAMPLE.COM security = ads idmap uid = 10000-500000 idmap gid = 10000-500000 template shell = /bin/bash winbind use default domain = true winbind offline logon = false winbind nested groups = yes encrypt passwords = yes
Here we’ve told samba to use the kerberos realm EXAMPLE.COM (you’ll substitute your domain from the krb5.conf file). We’re using ads for security (Windows-style), and we’re allocating a bunch of UIDs and GIDs for mapping the domain users and groups to the Linux equivalents.

/etc/nsswitch.conf

passwd: files winbind shadow: files group: files winbind
Here we’re telling the system to look not only in the /etc/passwd and /etc/group files for authentication, but also to use winbind.

Join the Domain

Now’s the fun part: we can join the system to the domain.
chkconfig smb on service smb restart net ads join –U username
where username is a domain user who has permissions to join a computer to the domain. You should get a response that the server has joined your realm.
Depending on your DNS configuration, you might get some errors like the following:
[root@linuxserver1]# net ads join -U username Enter username's password: Using short domain name – EXAMPLE Joined 'LINUXSERVER1' to realm 'example.com' [2010/11/29 16:11:20.643445, 0] libads/kerberos.c:333(ads_kinit_password) kerberos_kinit_password LINUXSERVER1$@EXAMPLE.COM failed: Client not found in Kerberos database [2010/11/29 16:11:20.644894, 0] utils/net_ads.c:1147(net_update_dns_internal) net_update_dns_internal: Failed to connect to our DC! DNS update failed!
So long as your server created a machine account in the domain, you can ignore the above errors. It’s trying to update your DNS server, and if you’re not using a Microsoft DNS server as a part of your domain, it will fail. That’s OK.
Once you’ve joined the domain, we need to start winbind
chkconfig winbind on service winbind start
Assuming winbind starts without any errors, you can test your membership and domain communication with the wbinfo command:
wbinfo –g
This command should list out all of the groups you’ve got configured in your domain.

Configure the home directories

We’ll first want to edit the /etc/oddjobd.conf.d/oddjobd-mkhomedir.conf file; this defaults to creating home directories that are group- and world-readable. We don’t want that. This, BTW, is a change from what we did in RHEL 5 and below.
There are two lines in the /etc/oddjobd.conf.d/oddjobd-mkhomedir.conf file that look like this:
<helper exec="/usr/libexec/oddjob/mkhomedir -u 0022"
Change them to read:
<helper exec="/usr/libexec/oddjob/mkhomedir -u 0077"
Then restart the oddjobd service
service oddjobd restart

Set the domain home permissions

*Note:  the behavior below is reported as fixed in advisory RHBA-2011:0339-2, but I'm leaving the information here for posterity's sake.  
There's a curiousity with the way oddjobd works, here: it seems to be assuming that the default umask is 0022 (644 permissions equivalent). When we change the umask 0077 (700), it not only creates the users' home directories with these permissions, but *also the domain home*. As it turns out, the domain home (/home/DOMAIN) is owned by root. This prevents anyone from being able to get to their home directory.
Unless we change this, users will receive the following error:
Could not chdir to home directory /home/DOMAIN/user: Permission denied -bash: /home/DOMAIN/user/.bash_profile: Permission denied
But if we pre-create the domain home, we should be in good shape:
mkdir /home/DOMAIN chmod 711 /home/DOMAIN
Where DOMAIN is the short name of your AD domain.
There's a bug for this behavior, BTW, at https://bugzilla.redhat.com/show_bug.cgi?id=666418, if you're interested in such things.
This should set you up so that everyone can change directories to this, but no one can read or write to this directory. If you prefer users to be able to enumerate the contents of your DOMAIN directory, change the permissions to 755 instead of 711.

Restrict Logins

We’ll first edit the /etc/pam.d/password-auth file (you can have the OS do this with a GUI front-end for you, if you run authconfig-gtk). This tells pam to use, in addition to the local user store, winbind for authentication.

Domain authentication isn’t that useful unless you can use it to control who can and cannot log in to your server.
#%PAM-1.0 # This file is auto-generated. # User changes will be destroyed the next time authconfig is run. auth required pam_env.so auth sufficient pam_unix.so nullok try_first_pass auth requisite pam_succeed_if.so uid >= 500 quiet auth sufficient pam_winbind.so use_first_pass auth required pam_deny.so account required pam_unix.so broken_shadow account sufficient pam_localuser.so account sufficient pam_succeed_if.so uid < 500 quiet account [default=bad success=ok user_unknown=ignore] pam_winbind.so account required pam_permit.so password requisite pam_cracklib.so try_first_pass retry=3 type= password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok password sufficient pam_winbind.so use_authtok password required pam_deny.so session optional pam_keyinit.so revoke session required pam_limits.so session optional pam_oddjob_mkhomedir.so session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid session required pam_unix.so
The mkhomedir line has PAM create a home directory (defaulting to /home/DOMAIN/username). That’s usually a good idea.
It’s possible to put login restrictions here in the system-auth file, but it’s usually considered best practices to put those in the individual files for the connection methods. We’ll do that now.

/etc/pam.d/sshd

#%PAM-1.0 auth required pam_sepermit.so auth include password-auth auth include system-auth account required pam_nologin.so account include system-auth account sufficient pam_localuser.so account required pam_succeed_if.so user ingroup DOMAIN\linuxadmins password include system-auth # pam_selinux.so close should be the first session rule session required pam_selinux.so close session required pam_loginuid.so # pam_selinux.so open should only be followed by sessions to be executed in the user context session required pam_selinux.so open env_params session optional pam_keyinit.so force revoke session include password-auth
Here we’re telling pam that only users who are in the group linuxadmins are allowed to connect to our server though ssh.

/etc/pam.d/gdm

#%PAM-1.0 auth [success=done ignore=ignore default=bad] pam_selinux_permit.so auth required pam_succeed_if.so user != root quiet auth required pam_env.so auth substack system-auth auth optional pam_gnome_keyring.so account required pam_nologin.so account include system-auth account sufficient pam_succeed_if.so user = DOMAIN\user34 account sufficient pam_succeed_if.so user ingroup DOMAIN\linuxadmins account required pam_succeed_if.so user ingroup DOMAIN\domainadmins password include system-auth session required pam_selinux.so close session required pam_loginuid.so session optional pam_console.so session required pam_selinux.so open session optional pam_keyinit.so force revoke session required pam_namespace.so session optional pam_gnome_keyring.so auto_start session include system-auth
We’re giving more people access to the GUI login, though. Notice that we’re allowing user34, linuxadmins, and domainadmins to log in through GDM.
Posted by

Remove email special from mailbox exchange

#Remove email special from mailbox exchange
#Create new mailbox "TempMailbox", after create new folder in TempMailBox is "Demo"
#Open Exchange management Shell command type :
Add-MailboxPermission -User wgroot@ssgroup.com.vn -AccessRights FullAccess -Identity xxx
Export-Mailbox -Identity xxx@ssgroup.com.vn -SenderKeywords "xxxx@hotmail.com" -TargetMailbox yyyy@ssgroup.com.vn -DeleteContent -TargetFolder Demo

Lệnh tcpdump trên Linux

Lệnh tcpdump trên Linux

Tcpdump: là công cụ được phát triển nhằm mục đích phân tích các gói dữ liệu mạng theo dòng lệnh. Nó cho phép người dùng chặn và hiển thị các gói tin được truyền đi hoặc được nhận trên một mạng mà máy tính có tham gia.
Tcpdump xuất ra màn hình nội dung các gói tin (chạy trên card mạng mà nó đang lắng nghe) phù hợp với biểu thức logic chọn lọc mà người dùng nhập vào. Với option –w người dùng có thể xuất những mô tả về gói tin này ra một file “pcap” để phân tích sau, và có thể đọc nội dung của file “pcap” đó với option –r của lệnh tcpdump, hoặc sử dụng các phần mềm khác như là : Wireshark.
Trong trường hợp không có option –c, lệnh tcpdump sẽ tiếp tục chạy cho đến khi nào nó nhận được một tín hiệu ngắt từ phía người dùng (có thể sử dụng tổ hợp phím ctrl+C hoặc sử dụng lệnh kill). Sau khi kết thúc việc bắt các gói tin, tcpdump sẽ báo cáo các cột sau:
  • Packet capture: số lượng gói tin mà nó bắt được và xử lý.
  • Packet received by filter: số lượng gói tin được nhận bởi bộ lọc.
  • Packet dropped by kernel: số lượng packet đã bị dropped, do thiếu không gian vùng đệm, bởi cơ chế bắt gói tin của hệ điều hành.
1.      Định dạng chung của một dòng giao thức tcpdump là:
time-stamp src > dst:  flags  data-seqno  ack  window urgent options
  • Time-stamp: hiển thị thời gian gói tin được capture.
  • Src và dst: hiển thị địa IP của người gởi và người nhận.
  • Cờ Flag thì bao gồm các giá trị sau:
    • S(SYN): cờ này được sử dụng trong quá trình bắt tay của giao thức TCP.
    • .(ACK): cờ này được sử dụng để thông báo cho bên gửi biết là nó đã nhận được dữ liệu thành công.
    • F(FIN): được sử dụng để đóng kết nối TCP.
    • P(PUSH): thường được đặt ở cuối khối dữ liệu, đánh dấu việc truyền dữ liệu.
    • R(RST): được sử dụng khi muốn thiết lập lại đường truyền.
  • Data-sqeno: số sequence number của gói dữ liệu hiện tại.
  • ACK: mô tả số sequence number tiếp theo của gói tin do bên gởi truyền (số sequence number mà nó mong muốn nhận được).
  • Window: vùng nhớ đệm có sẵn theo hướng khác trên kết nối này.
  • Urgent: cho biết có dữ liệu khẩn cấp trong gói tin.
2.      Một số tùy chọn thông dụng trong lệnh Tcpdump:
  • -i               : sử dụng option này khi người dùng muốn chụp các gói tin trên một interface được chỉ định.
  • -D              : khi sử dụng option này, tcpdump sẽ liệt kê ra tất cả các interface đang hiện hữu trên máy tính mà nó có thể capture được.
  • -c N           : khi sử dụng option này, tcpdump sẽ dừng hoạt động sau khi capture N gói tin.
  • -n              : khi sử dụng option này, tcpdump sẽ không phân giải từ địa chỉ IP sang hostname.
  • -nn            : tương tự như option –n, tuy nhiên tcpdump sẽ không phân giải cả portname.
  • -v               : tăng số lượng thông tin về gói tin mà bạn có thể nhận được, thậm chí có thể tăng thêm với option –vv hoặc –vvv.
  • -s               : định nghĩa snaplength (kích thước) gói tin sẽ lưu lại, sử dụng 0 để mặc định.
  • -q              : khi sử dụng option này thì lệnh tcpdump sẽ hiển thị ít thông tin hơn.
  • -w filename : khi sử dụng option này tcpdump sẽ capture các packet và lưu xuống file chỉ định.
  • -r filename : sử dụng kèm với option –w, dùng để đọc nội dung file đã lưu từ trước.
  • -x              : hiển thị dữ liệu của gói tin capture dưới dạng mã Hex.
  • -xx                        : tương tự option –x tuy nhiên sẽ chuyển đổi cả ethernet header.
  • -X              : hiển thị dữ liệu của gói tin capture dưới dạng mã Hex và ASCII
  • -XX           : tương tự như option –X  tuy nhiên sẽ chuyển đổi luôn cả ethernet header.
  • -A              : hiển thị các packet được capture dưới dạng mã ACSII.
  • -S              : khi tcpdump capture packet, thì nó sẽ chuyển các số sequence number, ACK thành các relative sequense number, relative ACK. Nếu sử dụng option –S này thì nó sẽ không chuyển mà sẽ để mặc định.
  • -F  filename:  dùng để filter các packet với các luật đã được định trước trong tập tin filename.
  • -e               : khi sử dụng option này, thay thì hiển thị địa chỉ IP của người gửi và người nhận, tcpdump sẽ thay thế các địa chỉ này bằng địa chỉ MAC.
  • -t               : khi sử dụng option này, tcpdump sẽ bỏ qua thời gian bắt được gói tin khi hiển thị cho người dùng.
  • -tt              : khi sử dụng option này, thời gian hiển thị trên mỗi dòng lệnh sẽ không được format theo dạng chuẩn.
  • -ttt             : khi sử dụng option này, thời gian hiển thị chính là thời gian chênh lệnh giữa thời gian tcpdump bắt được gói tin của gói tin và gói tin đến trước nó.
  • -tttt            : khi sử dụng option này, sẽ hiển thị thêm ngày vào mỗi dòng lệnh.
  • -ttttt          : khi sử dụng option này, thời gian hiển thị trên mỗi dòng chính là thời gian chênh lệch giữa thời gian tcpdump bắt được gói tin của gói tin hiện tại và gói tin đầu tiên.
  • -K              : với option này tcpdump sẽ bỏ qua việc checksum các gói tin.
  • -N              : khi sử dụng option này tcpdump sẽ không in các quality domain name ra màn hình.
  • -B size      : sử dụng option này để cài đặt buffer_size .
  • -L              : hiển thị danh sách các datalink type mà interface hỗ trợ.
  • -y               : lựa chọn datalinktype khi bắt các gói tin.
3.      Một số bộ lọc cơ bản:
  • dst A         : khi sử dụng option này, tcpdump sẽ chỉ capture các gói tin có địa chỉ đích là “A”, có thể sử dụng kèm với từ khóa net để chỉ định một dãy mạng cụ thể. Ví dụ: tcpdump dst net 192.168.1.0/24.
  • src A         : tương tự như option dst, nhưng thay vì capture các gói tin có địa chỉ đích cụ thể thì nó sẽ capture các gói tin có địa chỉ nguồn như quy định.
  • host A       : khi sử dụng option này, tcpdump sẽ chỉ capture các gói tin có địa chỉ nguồn hoặc địa chỉ đích là “A”.
  • port / port range : khi sử dụng option này, tcpdump sẽ chỉ capture các gói tin có địa chỉ port được chỉ định rõ, hoặc nằm trong khoảng range định trước. Có thể sử dụng kèm với option dst hoặc src.
  • less           : khi sử dụng từ khóa này, tcpdump sẽ lọc (filter) các gói tin có dung lượng nhỏ hơn giá trị chỉ định.
  • greater     : khi sử dụng từ khóa này, tcpdump sẽ lọc (filter) các gói tin có dung lượng  cao hơn giá trị chỉ định.
  • (ether | ip) broadcast: capture các gói tin ip broadcast hoặc ethernet broadcast.
  • (ether | ip | ip6) multicast: capture các gói tin ethernet, ip , ipv6 multicast.
  • Ngoài ra, tcpdump còn có thể capture các gói tin theo các protocol như : udp, tcp, icmp, ipv6  (chỉ cần gõ trực tiếp các từ khóa vào là được). Ví dụ: tcpdump icmp
4.      Một số kết hợp trong tcpdump:
  • AND         : sử dụng từ khóa and hoặc &&.
  • OR            : sử dụng từ khóa or hoặc ||.
  • EXCEPT   : sử dụng từ khóa not hoặc !.
  • Ngoài ra để gom nhóm các điều kiện ta có thể dùng cặp từ khóa ‘’.  Ví dụ:  tcpdump –i eth0 ‘dst host 192.168.1.1 or 192.168.1.10 or 192.168.1.11’
5.      Một số ví dụ của tcpdump:
  • Hiển thị tất cả các interface trên máy tính mà tcpdump có thể lắng nghe được.
#tcpdump -D
  • Lọc các gói tin trên card mạng eth0, có địa chỉ đích là 192.168.1.0 hoặc địa chỉ nguồn là 192.168.1.0
#tcpdump –i eth0 host 192.168.1.0
#tcpdump –i eth0 src 192.168.1.0 or host 192.168.1.0
  • Lọc các gói tin ARP chạy trên card mạng eth0, xuất phát từ dãy mạng 192.168.1.0/24
#tcpdump –i eth0 arp src net 192.168.1.0/24
  • Lọc các gói tin ICMP chạy trên mạng eth0,  đi đến máy đích có địa chỉ MAC là 00-23-14-43-E8-08. Khi xuất ra màn hình không cho phân giải tên miền, cũng như không sử dụng số relative sequence. Lưu output vào file test.cap. Khi đọc file đó lên: không hiển thị số sequence number, không phân giải hostname.
#tcpdump –i eth0 –w test.cap ether dst host 00:23:14:42:E8:08
#tcpdump –Snnr test.cap
  • Lọc gói tin ICMP request and reply: sử dụng option icmp[icmptype]
#tcpdump icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
  • Lọc một số cờ TCP bằng tcpdump: sử dụng option tcp[tcpflags] && tcp-syn!=0. (Giá trị của các cờ TCP lần lượt là U (32) – A (16) – P (8) – R (4) – S (2) – F (1)).
    • Lọc các gói tin TCP có cờ URG được bật:
#tcpdump tcp[13] & 2 != 0  hay #tcpdump tcp[tcpflags] & tcp-urg != 0
  • Lọc các gói tin TCP có cờ ACK được bật:
#tcpdump tcp[13] & 16 != 0 hay #tcpdump tcp[tcpflags] & tcp-ack != 0
  • Lọc các gói tin TCP có cờ PSH  được bật:
#tcpdump tcp[13] & 8 != 0 hay #tcpdump tcp[tcpflags] & tcp-push != 0
  • Lọc các gói tin TCP có cờ SYN/ACK được bật:
#tcpdump tcp[13]=18
http://k3nshjnz.wordpress.com/2013/05/31/lenh-tcpdump-tren-linux/

Các giao thức định tuyến

Các giao thức định tuyến

Phần này mình sẽ đề cập chủ yếu đến các giao thức định tuyến trong chương trình CCNA của Cisco
Routing: nôm na là quá trình lựa chọn đường đi cho gói tin, giúp gói tin có thể di chuyển từ mạng nguồn đến mạng đích.Kĩ thuật Routing chia làm 2 loại lớn đó là dynamic route và static route.
1. Static Route: đây là kĩ thuật mà người quản trị phải tự cấu hình đường đi đến mạng đích trên router. Kĩ thuật này ít chiếm tài nguyên mạng và Router, đơn giản, tốc độ xử lý nhanh.Tuy nhiên nó lại có một điểm yếu là không hội tụ với những thay đổi trên mạng, đồng thời nếu như số lượng đường route quá lớn thì lại không thể cấu hình bằng tay.
2. Dynamic Route: các route thường xuyên trao đổi thông tin định tuyến cho nhau. Từ những thông tin này, các route sẽ sử dụng các thuật toán tìm đường đi khác nhau, để tìm ra đường đi đến đích tối ưu nhất theo tính toán của mình, từ đó tạo ra bảng định tuyến, lưu trữ thông tin về các đường đi này. Trong Dynamic Route thì lại chia làm 2 loại lớn đó là IGP (Interior Gateway Protocol) và EGP (Exterior Gateway Protocol).
a. Các giao thức định tuyến ngoài (EGP): đại diện tiêu biểu cho loại này là giao thức BGP(Border Gateway Protocol) là loại giao thức dùng để chạy giữa những Router thuộc các AS khác nhau. AS- Autonomous System: tạm dịch là hệ thống tự trị tập hợp các router thuộc cùng sự quản lý về kỹ thuật, sỡ hữu của một doanh nghiệp, chịu chung một chính sách định tuyến. Thường thì các AS là ISP. Như vậy định tuyến ngoài thường dùng cho các mạng Internet toàn cầu, trao đổi thông tin định tuyến lớn và thường mang nhiều policy.
b. Các giao thức định tuyến trong (IGP): gồm các giao thức tiêu biểu như RIP, OSPF, IGRP, EIGRP. Trong đó RIP và OSPF là các giao thức chuẩn quốc tế, còn EIGRP và IGRP là giao thức định tuyến riêng được phát triển trên các thiết bị Cisco. Với IGP nó lại chia theo các nhánh khác nhau. Các giao thức IGP được chia thành 3 loại: Distance-Vector, Link-state, Hybrid.
Distance -Vector: tiêu biểu cho hình thức này là giao thức RIP. Hoạt động dựa trên nguyên tắc neighbor, nghĩa là mỗi router sẽ gửi nguyên cả bảng định tuyến(routing table) của mình cho các router kết nối với nó. Các router sẽ so sánh các tuyến đường với các tuyến đường trong bảng định tuyến của mình. Tuyến đường nào tối ưu hơn sẽ được giữ lại.
-         Ưu điểm của giao thức này là: dễ cấu hình, router không xử lý nhiều nên tốc độ sẽ nhanh hơn.
-         Nhược điểm:
+        Hệ thống metric quá đơn giản(như Hop count) nên tuyến đường được chọn chưa phải là tối ưu nhất.
+        Vì các gói tin được gửi theo định kỳ nên một lượng lớn bandwith sẽ bị chiếm, dù cho mạng không có gì thay đổi đi nữa.
+        Do Router hội tụ chậm, dẫn đến việc sai lệch trong bảng định tuyến, gây ra tình trạng loop
Link –state: đại diện cho loại này là OSPF với loại giao thức này, các router sẽ không gửi bảng routing table mà gửi bảng cơ sở dữ liệu trạng thái đường link (LSDB-Link State Database) cho mọi router cùng vùng (area). Việc tính toán định tuyến được thực hiện dựa theo giải thuật Dijkstra. Một khi mạng đã hội tụ, thì các router sẽ không gửi update định kỳ mà chỉ gởi khi nào có sự thay đổi trong hệ thống mạng(link up or link down)
-         Ưu điểm: thích nghi được nhiều hệ thống, cho phép người thiết kế mạng linh hoạt, phản ứng nhanh. Và do không gửi interval-update nên đảm bảo được bandwith của mạng
-         Nhược điểm: Router phải xử lý nhiều hơn, tốc độ CPU chậm hơn nên có delay. Ngoài ra cấu hình OSPF phức tạp hơn so với RIP
Hybrid( Advanced Distance Vertor): tiêu biểu là giao thức IGRP(hiện nay đã ngừng sử dụng) và EIGRP. Đây là họ giao thức đặc trưng trên các thiết bị Cisco. Là sự kết hợp giữa distance-vector link-state.
Ngoài ra còn có thể chia thành 2 loại classless và classful
-         Classful: không gửi kèm subnet-mask trong bảng định tuyến, nên không hỗ trợ VLSM và mạng gián đoạn
-         Classless: gửi kèm subnet-mask trong bảng định tuyến. Hỗ trợ VLSM và mạng gián đoạn(discontiguos network)
http://k3nshjnz.wordpress.com/2013/05/06/cac-giao-thuc-dinh-tuyen/