Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

BÀI SỐ 2: CÁC TIỆN ÍCH TCP/IP

Mục tiêu: Sau khi hoàn thành bài thực hành này, sinh viên có thể
- Biết được một số tiện ích về TCP/IP trên môi trường Windows.
- Sử dụng các tiện ích về TCP/IP một cách thành thạo.
- Vận dụng các tiện ích này vào việc tìm và khắc phục các lỗi về TCP/IP.

2.1. Ipconfig (Internet protocol configuration)

Mục đích: Người quản trị sử dụng lệnh này để xem thông tin TCP/IP trên các giao tiếp
mạng và tất nhiên cũng có thể dùng để cấu hình TCP/IP cho các giao tiếp mạng.
Cú pháp:
C:\Windows\System32\ipconfig.exe
ipconfig [/? | /all | /release [adapter] | /renew [adapter] | /flushdns | /displaydns |
/registerdns | /showclassid adapter | /setclassid adapter [classid] ]
STT LỆNH MÔ TẢ
1 > ipconfig /? Hiển thị sự trợ giúp
2 > ipconfig /all Hiển thị tất cả thông tin cấu hình TCP/IP
3 > ipconfig /release Hủy bỏ cấu hình IP hiện tại
 Dùng lệnh này khi thông tin TCP/IP trên
DHCP server đã bị thay đổi nhưng thời gian
Lease Duration cấp cho host vẫn chưa hết hạn.
4 > ipconfig /renew Thay địa chỉ IP mới cho card mạng
 Dùng lệnh này yêu cầu mới thông tin TCP/IP
khi host chưa nhân IP hay trước đó đã release
Ví dụ: Sử dụng lệnh ipconfig /all
C:\Users\Sori>ipconfig /all

Windows IP Configuration

Host Name . . . . . . . . . . . . : DESKTOP-P8U28BS


Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Trang 13
DNS Suffix Search List. . . . . . : dtu.vn

Ethernet adapter Ethernet:

Connection-specific DNS Suffix . : dtu.vn


Description . . . . . . . . . . . : Qualcomm Atheros AR8162/8166/8168 PCI-E
Fast Ethernet Controller (NDIS 6.30)
Physical Address. . . . . . . . . : 3C-97-0E-2C-BB-10
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . .: fe80::b97c:51cd:7158:ef5e%24(Preferred)
IPv4 Address. . . . . . . . . . . : 10.7.3.26(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Wednesday, October 14, 2020 7:05:44 AM
Lease Expires . . . . . . . . . . : Wednesday, October 14, 2020 10:36:22 AM
Default Gateway . . . . . . . . . : 10.7.3.254
DHCP Server . . . . . . . . . . . : 10.0.1.126
DHCPv6 IAID . . . . . . . . . . . : 289183502
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-23-89-3B-CA-3C-97-0E-2C-BB-10
DNS Servers . . . . . . . . . . . : 8.8.8.8
203.113.131.1
NetBIOS over Tcpip. . . . . . . . : Enabled

C:\Users\Sori>

2.2. Ping

Mục đích: Lệnh PING dùng kiểm tra kết nối mạng đến các host khác sử dụng giao thức
ICMP.
Cú pháp: PING [options] destination_host
C:\Windows\System32\PING.EXE
Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
[-r count] [-s count] [[-j host-list] | [-k host-list]]
[-w timeout] target_name

Options:

-t Ping the specified host until stopped.


To see statistics and continue - type Control-Break;
To stop - type Control-C.
-a Resolve addresses to hostnames.
-n count Number of echo requests to send.
-l size Send buffer size.
-f Set Don't Fragment flag in packet.
-i TTL Time To Live.
-v TOS Type Of Service.
-r count Record route for count hops.
-s count Timestamp for count hops.
-j host-list Loose source route along host-list.
-k host-list Strict source route along host-list.
-w timeout Timeout in milliseconds to wait for each reply.

Trang 14
Ví dụ 1:
ping 203.113.131.1 -t // Kiểm tra kết nối đến host “dns1.viettel.com.vn” lặp
vô hạn kết nối (mặc định chỉ gởi 4 ICMP packets)
Pinging 203.113.131.1 with 32 bytes of data:

Reply from 203.113.131.1: bytes=32 time=22ms TTL=50


Reply from 203.113.131.1: bytes=32 time=19ms TTL=50
Reply from 203.113.131.1: bytes=32 time=16ms TTL=50
Ping statistics for 203.113.131.1:

Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),


Approximate round trip times in milli-seconds:
Minimum = 16ms, Maximum = 22ms, Average = 19ms

 Kết nối thành công


Pinging 203.113.131.1 with 32 bytes of data:

Hardware error.
Hardware error.
 Card mạng ở trạng thái Disable hoặc chưa lắp Card.
Pinging 203.113.131.1 with 32 bytes of data:

Destination host unreachable.


 Chưa cấu hình IP hoặc chưa nối dây.
Pinging 203.113.131.1 with 32 bytes of data:
Request timed out.
 Không tồn tại đường đi nào đến đích hoặc host đích không gởi gói Echo Reply
Ví dụ 2:
ping dtu.edu.vn -n 5 // Gửi 5 ICMP packets để kiểm tra
Pinging dtu.edu.vn [222.255.128.204] with 32 bytes of data:

Reply from 222.255.128.204: bytes=32 time=29ms TTL=119


Reply from 222.255.128.204: bytes=32 time=29ms TTL=119
Reply from 222.255.128.204: bytes=32 time=25ms TTL=119
Reply from 222.255.128.204: bytes=32 time=25ms TTL=119
Reply from 222.255.128.204: bytes=32 time=27ms TTL=119

Ping statistics for 222.255.128.204:


Packets: Sent = 5, Received = 5, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 25ms, Maximum = 29ms, Average = 27ms

2.3. Tracert

Mục đích: Người quản trị sử dụng lệnh này để dò tìm đường đi đến một hệ thống khác,
dùng xác định được lỗi xảy ra khi không thực hiện được kết nối.

Trang 15
Cú pháp:
C:\Windows\System32\TRACERT.EXE
Usage: tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout]
target_name

Options:
-d Do not resolve addresses to hostnames.
-h maximum_hops Maximum number of hops to search for target.
-j host-list Loose source route along host-list.
-w timeout Wait timeout milliseconds for each reply.
Ví dụ:
tracert www.dtu.edu.vn // Dò đường đi đến máy chủ web dtu.edu.vn
Tracing route to www.dtu.edu.vn [10.0.0.13]

over a maximum of 30 hops:

1 39 ms 43 ms <1 ms DD-WRT [192.168.100.17]

2 82 ms 3 ms 4 ms 172.16.0.1

3 82 ms 34 ms * 192.168.2.1

4 35 ms 2 ms 4 ms localhost [10.0.0.13]

Trace complete.

2.4. Netstat

Mục đích: Người quản trị sử dụng lệnh này để xem xét toàn diện thông tin về hệ thống
cục bộ và bộ giao thức TCP/IP.
Cú pháp:
C:\Windows\System32\NETSTAT.EXE
Usage:
NETSTAT [options] [-p protocol] [interval]

Options:
-a Display All connections and listening ports.
-e Display Ethernet statistics. (may be combined with -s)
-n Display addresses and port numbers in Numerical form.
-r Display the Routing table.
-o Display the Owning process ID associated with each connection.
-b Display the exe involved in creating each connection or listening port.*
-v Verbose - use in conjunction with -b, to display the sequence of
components involved for all executables.
-p protocol
Show only connections for the protocol specified;
may be any of: TCP, UDP, TCPv6 or UDPv6.
If used with the -s option then the following protocols
may also be specified: IP, IPv6, ICMP,or ICMPv6.

Trang 16
-s Display per-protocol statistics. By default, statistics are
shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6;
(The v6 protocols are not available under 2k and NT4)
The -p option may be used to display just a subset of these.

interval Redisplay statistics, pausing interval seconds between


each display. (default=once only) Press CTRL+C to stop.

Ví dụ:
netstat –a // Xem tất cả các kết nối
Active Connections

Proto Local Address Foreign Address State


TCP y400:epmap y400:0 LISTENING
TCP y400:microsoft-ds y400:0 LISTENING
TCP y400:1110 y400:0 LISTENING
TCP y400:2628 y400:0 LISTENING
TCP y400:3389 y400:0 LISTENING
TCP y400:4464 y400:0 LISTENING
TCP y400:19780 y400:0 LISTENING
TCP y400:1110 localhost:1805 TIME_WAIT
TCP y400:1110 localhost:1811 ESTABLISHED
TCP y400:1110 localhost:1820 TIME_WAIT
TCP y400:1110 localhost:1823 ESTABLISHED
TCP y400:1110 localhost:1826 ESTABLISHED
TCP y400:1110 localhost:1832 ESTABLISHED
TCP y400:1110 localhost:1838 TIME_WAIT
TCP y400:1358 localhost:2628 ESTABLISHED
TCP y400:1801 localhost:1802 ESTABLISHED
TCP y400:1802 localhost:1801 ESTABLISHED
TCP y400:1803 localhost:1804 ESTABLISHED
TCP y400:1804 localhost:1803 ESTABLISHED
TCP y400:1811 localhost:1110 ESTABLISHED
TCP y400:1823 localhost:1110 ESTABLISHED
TCP y400:1826 localhost:1110 ESTABLISHED
TCP y400:1832 localhost:1110 ESTABLISHED
TCP y400:2628 localhost:1358 ESTABLISHED
TCP y400:netbios-ssn y400:0 LISTENING
TCP y400:1813 hk-in-f104.google.com:https ESTABLISHED
TCP y400:1825 hk-in-f18.google.com:https ESTABLISHED
TCP y400:1828 hk-in-f18.google.com:https ESTABLISHED
TCP y400:1834 hk-in-f189.google.com:https ESTABLISHED
UDP y400:microsoft-ds *:*
UDP y400:isakmp *:*
UDP y400:1036 *:*
UDP y400:1368 *:*
UDP y400:4500 *:*
UDP y400:ntp *:*
UDP y400:1900 *:*

Trang 17
2.5. Nslookup (Name server lookup)

Mục đích: Người quản trị sử dụng công cụ này để kiểm tra hoạt động của hệ thống hỏi
đáp tên miền (Domain Name System).
Cú pháp:
C:\Windows\System32\nslookup.EXE
Syntax
Lookup the ip address of MyHost:

NSLOOKUP [-option] MyHost

Lookup ip address of MyHost on MyNameServer:

NSLOOKUP [-option] MyHost MyNameServer

Enter "command mode":

NSLOOKUP

Command Mode options:

help or ? - print a list of Command Mode options


exit or ^C - exit "command mode"

set all - print options, current server and host


finger [USER] - finger the optional NAME at the current default host
MyHost - print ip address of MyHost
MyHost MyNameServer - print ip address of MyHost on MyNameServer
set [no]debug - print debugging info
set [no]d2 - print exhaustive debugging info

set domain=NAME - set default domain name to NAME


set root=NAME - set root server to NAME
root - set current default server to the root
server NAME - set default server to NAME, using current default server
lserver NAME - set default server to NAME, using initial server
set srchlist=N1[/N2/.../N6] - set domain to N1 and search list to N1, N2,...

set retry=X - set number of retries to X


set timeout=X - set initial time-out interval to X seconds
set [no]defname - append domain name to each query
set [no]recurse - ask for recursive answer to query
set [no]search - use domain search list
set [no]vc - always use a virtual circuit
set class=X - set query class (for example, IN (Internet), ANY)
set [no]msxfr - use MS fast zone transfer
set ixfrver=X - current version to use in IXFR transfer request
set type=X - set query type
set querytype=X - set query type
(e.g. A, ANY, CNAME, MX, NS, PTR, SOA, SRV)

ls [opt] DOMAIN [> FILE] - list addresses in DOMAIN


(and optionally output to FILE)

Trang 18
-d - list all records
-t TYPE - list records of the given Type (for example, A, CNAME,
MX, NS, PTR, and so on)
-a - list Aliases and canonical names.

view FILE - sort an 'ls' output file and view it with pg

Ví dụ 1:
nslookup google.com // Tra cứu địa chỉ IP của google.com
Server: DD-WRT
Address: 192.168.100.17

Name: google.com
Addresses: 74.125.127.100, 74.125.67.100, 74.125.45.100
Ví dụ 2:
nslookup –type=MX google.com // Tra cứu thông tin Mail Server của Google
Server: DD-WRT
Address: 192.168.100.17

google.com MX preference = 10, mail exchanger = smtp4.google.com


google.com MX preference = 10, mail exchanger = smtp1.google.com
google.com MX preference = 10, mail exchanger = smtp2.google.com
google.com MX preference = 10, mail exchanger = smtp3.google.com

2.6. ARP (Address Resolution Protocol)

Mục đích: Người quản trị sử dụng công cụ này để xem và chỉnh sửa bảng ARP.
Cú pháp:
Lệnh ARP trên máy Windows: “C:\Windows\System32\ARP.EXE”
C:\Users\Sori>arp /?
Displays and modifies the IP-to-Physical address translation
tables used by address resolution protocol (ARP).
ARP -s inet_addr eth_addr [if_addr]
ARP -d inet_addr [if_addr]
ARP -a [inet_addr] [-N if_addr] [-v]
-a Displays current ARP entries by interrogating the
current protocol data. If inet_addr is specified, the
IP and Physical addresses for only the specified
computer are displayed. If more than one network
interface uses ARP, entries for each ARP table are
displayed.
-g Same as -a.
-v Displays current ARP entries in verbose mode. All
invalid entries and entries on the loop-back interface
will be shown.
inet_addr Specifies an internet address.

Trang 19
-N if_addr Displays the ARP entries for the network interface
specified by if_addr.
-d Deletes the host specified by inet_addr. inet_addr may
be wildcarded with * to delete all hosts.
-s Adds the host and associates the Internet address
inet_addr with the Physical address eth_addr. The
Physical address is given as 6 hexadecimal bytes
separated by hyphens. The entry is permanent.
eth_addr Specifies a physical address.
if_addr If present, this specifies the Internet address of the
interface whose address translation table should be
modified. If not present, the first applicable
interface will be used.
Example:
> arp -s 157.55.85.212 00-aa-00-62-c6-09 //Adds a static entry.
> arp –a //Displays the arp table.
C:\Users\Sori>

Trang 20
Ví dụ:
Hiển thị bảng ARP của tất cả các interfaces:
C:\> arp -a
Hiển thị bảng ARP trên interface có địa chỉ IP là 10.7.3.36:
C:\> arp -a -N 10.7.3.26

Gán tĩnh 1 dòng vào bảng ARP, gắn IP 10.1.4.77 và MAC 00-AA-21-4A-2F-9A:
C:\> arp -s 10.1.4.77 00-AA-21-4A-2F-9A

Trang 21

You might also like