/*auto readmore*/ /*auto readmore*/ /* an hien script*/ // an hien password /*an hien ma chuong trinh cong tru */ /*Scrollbox thanh cuon*/ /***Nhung CODE***/ /* dòng xanh dòng trắng */ /* https://cdnjs.com/libraries/prism lay thu vien, can vao ten file ma goi 1. copy link vao vi du:prism-python.min.js 2. ten ngon nua la python */ /*=== New posts ===*/ /*header slider*/ /*=== bai viet lien quan===*/ /*===tabcode===*/

Network Automation #000 - Netmiko Basic SSH To Router With Command Show

SƠ ĐỒ LAB:
YÊU CẦU: 

Dùng thư viện netmiko trên python SSH vào thiết bị và thực hiện những lệnh show căn bản


THỰC HIỆN:
1. Chuẩn bị cấu hình trên Router

conf t
hostname R_1
ip domain name NETMIKO.lab
no ip domain-lookup
banner motd #===R_1 NETMIKO LAB===#

username admin privilege 15 password admin1234
service password-encryption
 
line con 0
logging synchronous
login local
exit
line vty 0 4
login local
transport input all
crypto key generate rsa general-keys modulus 1024
ip ssh version 2
 
interface Et0/0
no shutdown
ip address 192.168.0.1 255.255.255.0
description ===Connect to PC===
exit
!
end
wri   
Tham khảo cấu hình mẫu/cấu hình cơ bản tại đây


2. Python script Netmiko SSH connection

#!/usr/bin/env python3
import netmiko

# Định nghĩa thông tin thiết bị trong dictionary (thông tin cấu hình trong phần chuẩn bị cấu hình)
device_info = {
    "host": "192.168.0.1",
    "port": 22,
    "username": "admin",
    "password": "admin1234",
    "device_type": "cisco_ios"
}

print("Connecting to {}...".format(device_info["host"])) # print ra dong Connecting to + IP được định nghĩa ở trong dictionnary

net_connect = netmiko.ConnectHandler(**device_info) # Dùng hàm ConnectHandler trong thư viện netmiko để kế nối đến thiết bị

print("Connected successfully") # in ra dòng kết nối thành công
net_connect.enable() # vào mode enable
#net_connect.config_mode() # vào mode config terminal 

 
while True: 
    hostname = net_connect.find_prompt() # Trả về dấu nhắc hiện tại
    command = input(hostname) # in ra những gì trước dấu nhắc (trường hợp này là hostname)
    if command != "exit" and command != "quit": # nếu không không phải là exit hay quit thì thực hiện lệnh show
        output = net_connect.send_command(command) # thực hiện lệnh show vừa gõ
        print(output) # in qa kết quả thực hiện lênh show
    else:   
        break   # kết thúc vòng lặp while (khi chúng ta gõ exit hay quit)

net_connect.disconnect()
P/s: copy nội dung trên lưu thành file Demo.py lưu vào C:\Python\Demo.py

3. Kiểm tra kết nối và thực hiện lệnh show

  • Thực hiện ở Command Prompt
c:\Python>python Demo.py
Connecting to 192.168.0.1...
Connected successfully
R_1#

  • Tiếp tục thực hiện lênh show ip int bri 
R_1#show ip int bri
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                192.168.0.1     YES NVRAM  up                    up
Ethernet0/1                unassigned      YES NVRAM  administratively down down
Ethernet0/2                unassigned      YES NVRAM  administratively down down
Ethernet0/3                unassigned      YES NVRAM  administratively down down
R_1#

  • Hoặc thực hiện bất cứ lệnh show nào bạn thích
Nói chung các bạn có thể dùng netmiko thay thế cho các công cụ remote khác nếu bạn thích.
  • Chụp hình kết quả thực hiện


Xong!

Mô Hình Mạng Cho Doanh Nghiệp Vừa & Nhỏ - Bài 7

Nên xem bài cấu hình căn bản trước xem bài này

Sơ đồ LAB:


Bảng thông tin địa chi IP:
STT Tên Thiết Bị Interface IP Address Subnet Mask Gateway/Default Route
1 Internet Lookback 8 8.8.8 255.0.0.0
Et0/0 200.1.1.1 255.255.255.252
2 ISP-Router Et0/0 200.1.1.2 255.255.255.0 200.1.1.1
Et0/1 125.234.102.241 255.255.255.248
3 Firewall Et0/1 125.234.102.243 255.255.255.248 125.234.102.241
Et0/1 192.168.200.1 255.255.255.0
4 Core Et0/1 192.168.200.2 255.255.255.0 192.168.200.1
Vlan100 192.168.100.254 255.255.255.0
Vlan101 192.168.101.254 255.255.255.0
Vlan102 192.168.102.254 255.255.255.0
Vlan103 192.168.103.254 255.255.255.0
5 DHCP Server Vlan100 192.168.100.100 255.255.255.0 192.168.100.254
6 PC1 Eth0 192.168.101.101 255.255.255.0 192.168.101.254
7 PC2 Eth0 192.168.102.102 255.255.255.0 192.168.102.254
8 PC3 Eth0 DHCP
9 PC3 Eth0 DHCP


Các kiến thức: VLAN, SVI, Trunking, NAT, Access-List, DHCP, IP SLA Tracking, Static Route, Floating Static Route


YÊU CẦU:

1. Đặt IP theo sơ đồ

2. Trên switch Core thực hiện:
  • Tạo các vlan 101, 102,103 và thực hiện đặt IP theo sơ đồ
  • Tạo vlan 500 và gán port Et0/2, Et0/3 vào vlan 500
3. Cấu hình port trunk trên port Et1/1 của switch core và Et0/0 của Acc01

4. Trên Acc01 tạo vlan 101,102 và gán các port  Et0/1 vào vlan 101, port Et0/2 vào vlan 102 đảm bảo PC1 & PC2 phải ping thấy nhau

5. Tương tự cấu hình trunk trên cổng đấu nối giữa Core switch và Acc02; trên Acc02 tạo vlan 102, 103; gán port Et0/2 vào vlan 102 và port Et0/3 vào vlan 103.

6. Cấu hình trên DHCP server:
  • Đặt IP Address và Default Route như sơ đồ
  • Cấu hình các pool DHCP cho vlan 101, 102, 103
  • Vlan 103 chỉ cấp DHCP trong khoảng từ 192.168.103.104 đến 192.168.103.253
7. Thực hiện trên switch core:
  • Tạo vlan 100, đặt ip cho vlan 100 theo sơ đồ, gán port Et0/0 vào vlan 100
  • Cấu hình dhcp relay agent cho vlan 101,102,103 đảm bảo các PC trong các vlan có thể lấy được địa chỉ IP do DHCP_Server 192.168.100.100 cấp
8. Trên Internet ạo Static route 125.234.102.240/29 trỏ về IP 200.1.1.2 của ISP-Router

9. Tạo các default route và thực hiện NAT trên overload trên Firewall đảm bảo tất cả các PC có thể ping được 8.8.8.8
    10. Cấu hinh trên Core switch phải đảm bảo các PC trong LAN truy cập 8.8.8.8 phải đi đúng thứ tự Core -> Firewall -> ISP-Router -> Internet; tuy nhiên khi Firewall down các PC có thể truy cập được 8.8.8.8 theo thứ tự Core -> ISP-Router -> Internet

    11. IP SLA Tracking


    THỰC HIỆN:

    1. Đặt IP theo sơ đồ
    • Internet:
    conf t
    hostname Internet

    interface Loopback8
    no shutdown
    ip address 8.8.8.8 255.0.0.0
    exit
    interface et0/0
    ip address 200.1.1.1 255.255.255.252
    no sh
    end
    wri

    • ISP-Router:
    conf t
    hostname ISP-Router

    interface et0/0
    ip address 200.1.1.2 255.255.255.252
    no sh
    exit
    interface et0/1
    ip address 125.234.102.241 255.255.255.248
    no sh
    end
    wri

    • Firewall:
    conf t
    hostname Firewall

    interface et0/2
    ip address 125.234.102.243 255.255.255.248
    no sh
    exit
    interface et0/1
    ip address 192.168.200.1 255.255.255.248
    no sh
    end
    wri

    Noted: Dùng router để giả lập Firewall, trong LAB này FW chỉ dùng NAT overload đảm bảo các PC trong LAN có thể truy cập được internet. Bạn nào muốn tham chuyên đề về Firewall thì tham khảo tại link

    • Switch Core/Layer3:
    conf t
    hostname Core

    interface et0/1
    no switchport
    ip address 192.168.200.2 255.255.255.248
    no sh
    end
    wri

    2. Trên switch Core thực hiện:
    • Tạo các vlan 101, 102,103 và thực hiện đặt IP theo sơ đồ
    Core:
    conf t

    vlan 101
    int vlan 101
    ip address 192.168.101.254 255.255.255.0
    no sh
    exit

    vlan 102
    int vlan 102
    ip address 192.168.102.254 255.255.255.0
    no sh
    exit

    vlan 103
    int vlan 103
    ip address 192.168.103.254 255.255.255.0
    no sh
    end
    wri

    • Tạo vlan 500 và gán port Et0/2, Et0/3 vào vlan 500
    Core:
    conf t

    vlan 500
    exit
    int et0/2
    sw mode access
    sw acc vlan 500
    exit
    int et0/3
    sw mode access
    sw acc vlan 500
    end 
    wri

    Noted: Vlan 500 cũng có thể gọi là DMZ switch, ở đây chúng ta có thể các thiết bị sử dụng IP public và không cần thông qua firewall như: Voice IP, Tổng Đài IP, Video Conferrence,... Chúng ta cũng có thể sử dụng 1 switch hardware thay cho VLAN, tuy nhiên mục đích tạo ra vlan 500 sẽ được giải thích trong mục 10 và 11 của bài này.

    3. Cấu hình port trunk trên port Et1/1 của switch core và Et0/0 của Acc01

    • Cấu hình
    Core:
    conf t
    int et1/1
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    end 
    wri

    Acc01:
    conf t
    hostname Acc01
    in et0/0
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    end
    wri

    Tùy theo từng dòng sản phẩm mà khi cấu hình trunk CÓ THỂ CÓ hoặc KHÔNG CÓ dòng "switchport trunk encapsulation dot1q

    • Kiểm tra:
    Core#show interfaces trunk

    Port        Mode             Encapsulation  Status        Native vlan
    Et1/1       on                     802.1q         trunking      1

    Port        Vlans allowed on trunk
    Et1/1       1-4094

    Port        Vlans allowed and active in management domain
    Et1/1       1,100-103,500

    Port        Vlans in spanning tree forwarding state and not pruned
    Et1/1       1,100-103,500
    Core#

    Acc01#show  interfaces trunk

    Port        Mode             Encapsulation  Status        Native vlan
    Et0/0       on                    802.1q         trunking      1

    Port        Vlans allowed on trunk
    Et0/0       1-4094

    Port        Vlans allowed and active in management domain
    Et0/0       1,101-102

    Port        Vlans in spanning tree forwarding state and not pruned
    Et0/0       1,101-102
    Acc01#


    4. Trên Acc01 tạo vlan 101,102 và gán các port  Et0/1 vào vlan 101, port Et0/2 vào vlan 102 đảm bảo PC1 & PC2 phải ping thấy nhau

    • Cấu hình:
    Acc01:
    conf t

    vlan 101
    vlan 102
    exit

    int et0/1
    sw mode access
    sw acc vlan 101
    exit
    int et0/2
    sw mode access
    sw acc vlan 102
    end
    wri

    • Kiểm tra:
    Acc01#show vlan

    VLAN Name                             Status    Ports
    ---- -------------------------------- --------- -------------------------------
    1    default                          active    Et0/3
    101  VLAN0101                         active    Et0/1
    102  VLAN0102                         active    Et0/2
    1002 fddi-default                     act/unsup
    1003 token-ring-default               act/unsup
    1004 fddinet-default                  act/unsup
    1005 trnet-default                    act/unsup

    PC1> ping 192.168.102.102

    84 bytes from 192.168.102.102 icmp_seq=1 ttl=63 time=1.830 ms
    84 bytes from 192.168.102.102 icmp_seq=2 ttl=63 time=1.349 ms
    84 bytes from 192.168.102.102 icmp_seq=3 ttl=63 time=2.090 ms
    84 bytes from 192.168.102.102 icmp_seq=4 ttl=63 time=1.659 ms
    84 bytes from 192.168.102.102 icmp_seq=5 ttl=63 time=1.987 ms

    PC1>
    PC2> ping 192.168.101.101

    84 bytes from 192.168.101.101 icmp_seq=1 ttl=63 time=2.088 ms
    84 bytes from 192.168.101.101 icmp_seq=2 ttl=63 time=1.770 ms
    84 bytes from 192.168.101.101 icmp_seq=3 ttl=63 time=1.893 ms
    84 bytes from 192.168.101.101 icmp_seq=4 ttl=63 time=1.721 ms
    84 bytes from 192.168.101.101 icmp_seq=5 ttl=63 time=1.349 ms

    PC2>

    Kết quả đã đáp ứng yêu cầu đặt ra

    5. Tương tự cấu hình trunk trên cổng đấu nối giữa Core switch và Acc02; trên Acc02 tạo vlan 102, 103; gán port Et0/2 vào vlan 102 và port Et0/3 vào vlan 103.

    • Cấu hình trunk
    Core:
    conf t
    int et1/2
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    end 
    wri

    Acc02
    conf t
    hostname Acc02
    in et0/0
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    end
    wri

    • Gán port vào vlan
    Acc02:
    conf t
    vlan 102
    vlan 103
    exit
    int et0/2
    sw mode access
    sw acc vlan 102
    exit
    int et0/3
    sw mode access
    sw acc vlan 103
    end
    wri

    • Kiểm tra trên Acc02:
    Acc02#show interfaces trunk

    Port        Mode             Encapsulation  Status        Native vlan
    Et0/0       on               802.1q         trunking      1

    Port        Vlans allowed on trunk
    Et0/0       1-4094

    Port        Vlans allowed and active in management domain
    Et0/0       1,102-103

    Port        Vlans in spanning tree forwarding state and not pruned
    Et0/0       1,102-103
    Acc02#
    Acc02#show vlan

    VLAN Name                             Status    Ports
    ---- -------------------------------- --------- -------------------------------
    1    default                          active    Et0/1
    102  VLAN0102                         active    Et0/2
    103  VLAN0103                         active    Et0/3
    1002 fddi-default                     act/unsup
    1003 token-ring-default               act/unsup
    1004 fddinet-default                  act/unsup
    1005 trnet-default                    act/unsup
    {...}

    Acc02#

    6. Cấu hình trên DHCP server:
    • Đặt IP Address và Default Route như sơ đồ
    conf t
    hostname DHCP_Server
    int et0/0
    ip address 192.168.100.100 255.255.255.0
    no sh
    exit
    ip route 0.0.0.0 0.0.0.0 192.168.100.254
    end
    wri

    • Cấu hình các pool DHCP cho vlan 101, 102, 103
    conf t

    ip dhcp pool vlan_101
    network 192.168.101.0 255.255.255.0
    dns-server 8.8.8.8
    default-router 192.168.101.254
    lease 0 0 10
    exit
    ip dhcp pool vlan_102
    network 192.168.102.0 255.255.255.0
    dns-server 8.8.8.8
    default-router 192.168.102.254
    lease 0 0 10
    exit
    ip dhcp pool vlan_103
    network 192.168.103.0 255.255.255.0
    dns-server 8.8.8.8
    default-router 192.168.103.254
    lease 0 0 10
    end 
    wri

    Giải thích
    : lease 0 0 10: Thời gian cấp lại IP mới cho DHCP client ngày giờ phút

    Noted: Ở đây chúng tôi lấy router của cisco làm DHCP server, các bạn cũng có thể thay thế bằng Windows, Linux, ...

    • Vlan 103 chỉ cấp DHCP trong khoảng từ 192.168.103.104 đến 192.168.103.253

    conf t
    ip dhcp excluded-address 192.168.103.1 192.168.103.103
    ip dhcp excluded-address 192.168.103.254
    end
    wri
    Noted: Mặt định khi tạo pool DHCP thì cisco sẽ cấp từ 1 đến 254, trong trường hợp này chúng ta tạo danh sách ngoại trừ từ 192.168.103.1 đến 192.168.103.103 và 192.168.103.254

    7. Thực hiện trên switch core:
    • Tạo vlan 100, đặt ip cho vlan 100 theo sơ đồ, gán port Et0/0 vào vlan 100

    conf t
    vlan 100
    int vlan 100
    ip address 192.168.100.254 255.255.255.0
    no sh
    exit
    int et0/0
    sw mode access
    sw acc vlan 100
    end
    wri

    • Cấu hình dhcp relay agent cho vlan 101,102,103 đảm bảo các PC trong các vlan có thể lấy được địa chỉ IP do DHCP_Server 192.168.100.100 cấp
    conf t
    int vlan 101
    ip helper-address 192.168.100.100
    int vlan 102
    ip helper-address 192.168.100.100
    int vlan 103
    ip helper-address 192.168.100.100
    end
    wri

    Kiểm tra:

    PC3> ip dhcp
    DDORA IP 192.168.102.1/24 GW 192.168.102.254

    PC3>
    PC4> ip dhcp
    DDORA IP 192.168.103.104/24 GW 192.168.103.254

    PC4>
    PC3, PC4 đã lấy được IP từ DHCP server

    DHCP_Server#show ip dhcp binding
    Bindings from all pools not associated with VRF:
    IP address          Client-ID/              Lease expiration        Type
                        Hardware address/
                        User name
    192.168.102.1       0100.5079.6668.03       Jun 07 2021 06:19 AM    Automatic
    192.168.103.104     0100.5079.6668.04       Jun 07 2021 06:16 AM    Automatic
    DHCP_Server#
    Các IP đã cấp cho DHCP client

    8. Trên Internet ạo Static route 125.234.102.240/29 trỏ về IP 200.1.1.2 của ISP-Router

    • Cấu hình:
    conf t
    ip route 125.234.102.240 255.255.255.248 200.1.1.2
    end
    wri

    • Kiểm tra:
    Internet#show ip route static
    Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
           D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
           N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
           E1 - OSPF external type 1, E2 - OSPF external type 2
           i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
           ia - IS-IS inter area, * - candidate default, U - per-user static route
           o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
           a - application route
           + - replicated route, % - next hop override

    Gateway of last resort is not set

          125.0.0.0/29 is subnetted, 1 subnets
    S        125.234.102.240 [1/0] via 200.1.1.2
    Internet#

    Khi chúng ta mua thêm các địa chỉ IP tĩnh thì ISP phải tạo route để trỏ về router bên của chúng ta


    9. Tạo các default route và thực hiện NAT trên overload trên Firewall đảm bảo tất cả các PC có thể ping được 8.8.8.8

    • Tạo default route:
    ISP-Router:
    conf t
    ip route 0.0.0.0 0.0.0.0 200.1.1.1
    end
    wri

    Firewall:
    conf t
    ip route 0.0.0.0 0.0.0.0 125.234.102.241
    end
    wri

    Core:
    conf t
    ip route 0.0.0.0 0.0.0.0 192.168.200.1
    end
    wri

    • NAT overload trên Firewall:
    conf t
    interface Ethernet0/1
    ip nat inside
    exit
    interface Ethernet0/2
    ip nat outside
    exit
    ip nat inside source list 1 interface Ethernet0/2 overload

    access-list 1 permit any
    access-list 1 deny   any

    end
    wri

    Đến đây các PC chưa thể ping đến được 8.8.8.8 vì: trên môi trường internet một gói tin được cho là thành công thì phải đảm bảo có 2 chiều đi và về. Nếu chúng ta chỉ có NAT không thì mới chỉ có chiều đi còn thiếu chiều về, nên trên Firewall chúng ta phải tạo route ngược (có thể dùng bất kỳ kỹ thuật route nào cũng được) về các IP trong LAN.

    conf t

    ip  route  192.168.100.0  255.255.255.0  192.168.200.2
    ip  route  192.168.101.0  255.255.255.0  192.168.200.2
    ip  route  192.168.102.0  255.255.255.0  192.168.200.2
    ip  route  192.168.103.0  255.255.255.0  192.168.200.2
    end
    wri

    • Kiểm tra:

    PC3> ping 8.8.8.8

    84 bytes from 8.8.8.8 icmp_seq=1 ttl=252 time=2.684 ms
    84 bytes from 8.8.8.8 icmp_seq=2 ttl=252 time=3.233 ms
    84 bytes from 8.8.8.8 icmp_seq=3 ttl=252 time=2.536 ms
    84 bytes from 8.8.8.8 icmp_seq=4 ttl=252 time=2.128 ms
    84 bytes from 8.8.8.8 icmp_seq=5 ttl=252 time=2.252 ms

    PC3>
    PC4> ping 8.8.8.8

    84 bytes from 8.8.8.8 icmp_seq=1 ttl=252 time=3.107 ms
    84 bytes from 8.8.8.8 icmp_seq=2 ttl=252 time=3.087 ms
    84 bytes from 8.8.8.8 icmp_seq=3 ttl=252 time=2.000 ms
    84 bytes from 8.8.8.8 icmp_seq=4 ttl=252 time=2.140 ms
    84 bytes from 8.8.8.8 icmp_seq=5 ttl=252 time=2.865 ms

    PC4>
    Các PC đã ra được internet

    • Kiểm tra bảng NAT trên Firewall:
    Firewall#show  ip nat translations
    Pro Inside global      Inside local       Outside local      Outside global
    icmp 125.234.102.243:13030 192.168.102.1:13030 8.8.8.8:13030 8.8.8.8:13030
    icmp 125.234.102.243:13286 192.168.102.1:13286 8.8.8.8:13286 8.8.8.8:13286
    icmp 125.234.102.243:13542 192.168.102.1:13542 8.8.8.8:13542 8.8.8.8:13542
    icmp 125.234.102.243:13798 192.168.102.1:13798 8.8.8.8:13798 8.8.8.8:13798
    icmp 125.234.102.243:14054 192.168.102.1:14054 8.8.8.8:14054 8.8.8.8:14054
    icmp 125.234.102.243:10470 192.168.103.104:10470 8.8.8.8:10470 8.8.8.8:10470
    icmp 125.234.102.243:10726 192.168.103.104:10726 8.8.8.8:10726 8.8.8.8:10726
    icmp 125.234.102.243:10982 192.168.103.104:10982 8.8.8.8:10982 8.8.8.8:10982
    icmp 125.234.102.243:11238 192.168.103.104:11238 8.8.8.8:11238 8.8.8.8:11238
    icmp 125.234.102.243:11494 192.168.103.104:11494 8.8.8.8:11494 8.8.8.8:11494
    Firewall#

    Vì các IP private (192.168.102.x và 192.168.103.x) không được định nghĩa trên môi trường internet nên chúng ta phải NAT để dịch từ IP private sang ip public (định nghĩa IP private và public ở rfc 1918)

    Quit Configuration
    Internet
    conf t
    hostname Internet
    
    interface Loopback8
    no shutdown
    ip address 8.8.8.8 255.0.0.0
    exit
    interface et0/0
    ip address 200.1.1.1 255.255.255.252
    no sh
    exit
    
    ip route 125.234.102.240 255.255.255.248 200.1.1.2
    end
    wri
    
    ISP-Router
    conf t
    hostname ISP-Router
    
    interface et0/0
    ip address 200.1.1.2 255.255.255.252
    no sh
    exit
    interface et0/1
    ip address 125.234.102.241 255.255.255.248
    exit
    
    ip route 0.0.0.0 0.0.0.0 200.1.1.1
    no sh
    end
    wri
    
    
    Firewall
    conf t
    hostname Firewall
    
    interface et0/2
    ip address 125.234.102.243 255.255.255.248
    no sh
    exit
    interface et0/1
    ip address 192.168.200.1 255.255.255.248
    no sh
    exit
    
    interface Ethernet0/1
    ip nat inside
    interface Ethernet0/2
    ip nat outside
    ip nat inside source list 1 interface Ethernet0/2 overload
    
    ip route 0.0.0.0 0.0.0.0 125.234.102.241
    
    ip route 192.168.100.0 255.255.255.0 192.168.200.2
    ip route 192.168.101.0 255.255.255.0 192.168.200.2
    ip route 192.168.102.0 255.255.255.0 192.168.200.2
    ip route 192.168.103.0 255.255.255.0 192.168.200.2
    
    access-list 1 permit any
    access-list 1 deny   any
    end
    wri
    
    
    Core
    conf t
    hostname Core
    
    interface Ethernet0/1
    no switchport
    ip address 192.168.200.2 255.255.255.248
    no sh
    exit
    
    vlan 100
    vlan 101
    vlan 102
    vlan 103
    vlan 500
    exit
    
    interface Ethernet0/0
    switchport mode access
    switchport access vlan 100
    exit
    
    interface Ethernet0/2
    switchport mode access
    switchport access vlan 500
    exit
    interface Ethernet0/3
    switchport mode access
    switchport access vlan 500
    exit
    
    interface Vlan100
    ip address 192.168.100.254 255.255.255.0
    exit
    interface Vlan101
    ip address 192.168.101.254 255.255.255.0
    ip helper-address 192.168.100.100
    exit
    interface Vlan102
    ip address 192.168.102.254 255.255.255.0
    ip helper-address 192.168.100.100
    exit
    interface Vlan103
    ip address 192.168.103.254 255.255.255.0
    ip helper-address 192.168.100.100
    exit
    
    interface Ethernet1/1
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    exit
    interface Ethernet1/2
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    exit
    
    ip route 0.0.0.0 0.0.0.0 192.168.200.1
    end
    wri
    
    DHCP-Server
    conf t
    hostname DHCP_Server
    int et0/0
    ip address 192.168.100.100 255.255.255.0
    no sh
    exit
    ip route 0.0.0.0 0.0.0.0 192.168.100.254
    
    ip dhcp pool vlan_101
    network 192.168.101.0 255.255.255.0
    dns-server 8.8.8.8
    default-router 192.168.101.254
    lease 0 0 10
    exit
    ip dhcp pool vlan_102
    network 192.168.102.0 255.255.255.0
    dns-server 8.8.8.8
    default-router 192.168.102.254
    lease 0 0 10
    exit
    ip dhcp pool vlan_103
    network 192.168.103.0 255.255.255.0
    dns-server 8.8.8.8
    default-router 192.168.103.254
    lease 0 0 10
    exit
    
    ip dhcp excluded-address 192.168.103.1 192.168.103.103
    ip dhcp excluded-address 192.168.103.254
    end 
    wri
    
    
    Acc01
    conf t
    hostname Acc01
    interface Ethernet0/0
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    exit
    interface Ethernet0/1
    switchport mode access
    switchport access vlan 101
    exit
    interface Ethernet0/2
    switchport mode access
    switchport access vlan 101
    end
    wri
    
    Acc02
    conf t
    hostname Acc02
    interface Ethernet0/0
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    exit
    interface Ethernet0/2
    switchport mode access
    switchport access vlan 102
    exit
    interface Ethernet0/3
    switchport mode access
    switchport access vlan 103
    end
    wri
    

    10. Cấu hinh trên Core switch phải đảm bảo các PC trong LAN truy cập 8.8.8.8 phải đi đúng thứ tự Core -> Firewall -> ISP-Router -> Internet; tuy nhiên khi Firewall down các PC có thể truy cập được 8.8.8.8 theo thứ tự Core -> ISP-Router -> Internet

    • Kiểm tra trước khi cấu hình:
    PC1> tracer 8.8.8.8
    trace to 8.8.8.8, 8 hops max, press Ctrl+C to stop
     1   192.168.101.254   1.291 ms  1.047 ms  0.968 ms
     2   192.168.200.1   1.814 ms  1.523 ms  1.661 ms
     3   125.234.102.241   2.160 ms  2.112 ms  1.928 ms
     4   *200.1.1.1   2.586 ms (ICMP type:3, code:3, Destination port unreachable)  *

    PC1>
    Chúng ta thấy các gói tin đã đi đúng yêu cầu ban đầu: Core -> Firewall -> ISP-Router -> Internet

    • Cấu hình:
    Core:
    interface Vlan500
    ip address 125.234.102.242 255.255.255.248
    no shut
    exit

    ip route 0.0.0.0 0.0.0.0 125.234.102.241 10
    end
    wri

    ISP-Router:
    interface Ethernet0/0
    ip nat outside
    exit
    interface Ethernet0/1
    ip nat inside
    exit

    ip nat inside source list LAN-to-INTERNET interface Ethernet0/0 overload
    ip access-list extended LAN-to-INTERNET
    deny ip 125.234.102.240 0.0.0.7 any
    permit ip any any
    exit

    ip route 192.168.100.0 255.255.255.0 125.234.102.242
    ip route 192.168.101.0 255.255.255.0 125.234.102.242
    ip route 192.168.102.0 255.255.255.0 125.234.102.242
    ip route 192.168.103.0 255.255.255.0 125.234.102.242
    end
    wri

    • Giải thích access-list:
    deny ip 125.234.102.240 0.0.0.7 any: dãy IP 125.234.102.240/29 là IP public đã được định nghĩa trên internet nên không cần phải NAT
    - permit ip any any: tất cả các ip còn lại (trường hợp này là các IP trong LAN) là phải NAT

    • Kiểm tra sau khi cấu hình
    Trên switch core:
    shutdown port Et0/1 và ping test
    Core#ping 8.8.8.8
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds:
    !!!!!
    Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
    Core#ping 8.8.8.8 source vlan 101
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds:
    Packet sent with a source address of 192.168.101.254
    !!!!!
    Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/2 ms
    Core#

    Trên PC1
    PC1> tracer 8.8.8.8
    trace to 8.8.8.8, 8 hops max, press Ctrl+C to stop
     1   192.168.101.254   1.016 ms  0.841 ms  0.948 ms
     2   125.234.102.241   1.687 ms  1.561 ms  1.470 ms
     3   *200.1.1.1   2.417 ms (ICMP type:3, code:3, Destination port unreachable)  *

    PC1>
    Đúng yêu cầu đặt ra Core -> ISP-Router -> Internet

    P/s: Đã đúng yêu cầu tuy nhiên chúng ta có thể làm thêm IP SLA Tracking để kiểm tra IP đầu xa, nếu ping đến không được thì sẽ tư động điều chỉnh bản route cho phù hợp


    11. IP SLA Tracking

    • Cấu hình:
    Core:
    ip sla 2001
    icmp-echo 192.168.200.1
    threshold 5
    frequency 10
    exit
    !
    ip sla schedule 2001 life forever start-time now
    !
    track 1 ip sla 2001 reachability
    exit
    !
    no ip route 0.0.0.0 0.0.0.0 192.168.200.1
    ip route 0.0.0.0 0.0.0.0 192.168.200.1 track 1
    end
    wri
    Xoá default route cũ và thêm vào default route với track

    • Kiểm tra:
    Kiểm tra sla đã cấu hình:
    Core:
    Core#show ip sla configuration 2001
    IP SLAs Infrastructure Engine-III
    Entry number: 2001
    Owner:
    Tag:
    Operation timeout (milliseconds): 5000
    Type of operation to perform: icmp-echo
    Target address/Source address: 192.168.200.1/0.0.0.0
    Type Of Service parameter: 0x0
    Request size (ARR data portion): 28
    Verify data: No
    Vrf Name:
    Schedule:
       Operation frequency (seconds): 10  (not considered if randomly scheduled)
       Next Scheduled Start Time: Start Time already passed
       Group Scheduled : FALSE
       Randomly Scheduled : FALSE
       Life (seconds): Forever
       Entry Ageout (seconds): never
       Recurring (Starting Everyday): FALSE
       Status of entry (SNMP RowStatus): Active
    Threshold (milliseconds): 5
    Distribution Statistics:
       Number of statistic hours kept: 2
       Number of statistic distribution buckets kept: 1
       Statistic distribution interval (milliseconds): 20
    Enhanced History:
    History Statistics:
       Number of history Lives kept: 0
       Number of history Buckets kept: 15
       History Filter Type: None


    Core#
    Core#show ip sla statistics
    IPSLAs Latest Operation Statistics

    IPSLA operation id: 2001
            Latest RTT: 1 milliseconds
    Latest operation start time: 08:18:23 EET Wed Jun 9 2021
    Latest operation return code: OK
    Number of successes: 31
    Number of failures: 6
    Operation time to live: Forever


    Core#

    Bật debug ip routing: để thấy sự thay đổi bảng route trong lúc test sla

    Core#debug ip routing
    IP routing debugging is on
    Core#
    Shutdown interface Et0/1
    Core:
    Core#conf t
    int et0/1
    shut
    Core(config-if)#
    *Jun  9 06:24:31.200: is_up: Ethernet0/1 0 state: 6 sub state: 1 line: 0
    *Jun  9 06:24:31.200: RT: interface Ethernet0/1 removed from routing table
    *Jun  9 06:24:31.200: RT: del 192.168.200.0 via 0.0.0.0, connected metric [0/0]
    *Jun  9 06:24:31.200: RT: delete subnet route to 192.168.200.0/29
    *Jun  9 06:24:31.200: RT: del 192.168.200.2 via 0.0.0.0, connected metric [0/0]
    *Jun  9 06:24:31.200: RT: delete subnet route to 192.168.200.2/32
    *Jun  9 06:24:31.200: RT: del 0.0.0.0 via 192.168.200.1, static metric [1/0]
    *Jun  9 06:24:31.200: RT: delete network route to 0.0.0.0/0
    *Jun  9 06:24:31.200: RT: default path has been cleared
    *Jun  9 06:24:31.200: RT:
    Core(config-if)#updating static 0.0.0.0/0 (0x0):
        via 125.234.102.241

    *Jun  9 06:24:31.200: RT: add 0.0.0.0/0 via 125.234.102.241, static metric [10/0]
    *Jun  9 06:24:31.200: RT: default path is now 0.0.0.0 via 125.234.102.241
    Core(config-if)#
    *Jun  9 06:24:33.194: %LINK-5-CHANGED: Interface Ethernet0/1, changed state to administratively down
    Core(config-if)#
    *Jun  9 06:24:33.194: is_up: Ethernet0/1 0 state: 6 sub state: 1 line: 0
    *Jun  9 06:24:34.199: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/1, changed state to down
    *Jun  9 06:24:34.199: is_up: Ethernet0/1 0 state: 6 sub state: 1 line: 0
    Core(config-if)#
    *Jun  9 06:24:36.256: %TRACKING-5-STATE: 1 ip sla 2001 reachability Up->Down
    Core(config-if)#

    Noted: Chúng ta thấy khi interface Et0/1 down thì sla 1 cũng down theo và chúng sẽ thực hiện xóa default route hiện tại và cập nhật default route mới sẽ trỏ về gateway 125.234.102.241

    Cấu hình căn bản

    Bài Lab nâng cao

    Xong!

    Cisco - Cấu Hình Căn Bản/Basic Configuration - Quit Configuration - Templates

    NỘI DUNG:

    1. Cấu hình căn bản

    2. Basic System Management Configuration

    3. Quit Configuration - Template

    4. VLAN Trunking Protocol  - VTP

    5. NAT Overload/PAT - Allow Internal Users Access To The Internet

    6. Trouble shooting - show commands


    THỰC HIỆN:

    1. Cấu hình căn bản

    đang cập nhật...

    STT Yêu Cầu Cấu Hình Commands Giải Thích
    1 Privileged mode enable Tìm hiểu các mode tại đây
    2 Global Configuration conf t Vào mode cấu hình, 
    3 exit Quay ra một bật
    4 End Quay ra Privileged mode
    5 Đặt tên cho thiết bị hostname TenThietBi Đặt tên cho thiết bị có tên là:  TenThietBi
    6 Đặt tên cho domain ip domain name khanhvc.lab Đặt trên cho domain có tên: khanhvc.lab (nhằm mục đích mã hóa dữ liệu)
    7 no ip domain-lookup Tắt chế độ phân giải domain sang ip (khi chúng ta gõ sai thiết bị không đị đơ khi chờ phân giải, rất khó chịu khi cấu hình nên tắt đi)
    8 Đặt tên login/banner banner motd #===Core Switch IT Room===# Khi chúng ta kết nối vào thiết bị sẽ hiển thị "===Core Switch IT Room==="
    9 Cài đặt user và pass username admin privilege 15 password itadmin Username admin có password là itadmin và quyền là 15 (cao nhất) và bỏ qua enable password
    10 Mã hóa password service password-encryption Kích hoạt mã hóa password trong file cấu hình
    11 Remote Access line con 0 Vào mode console thứ 0 (tham khảo các kỹ thuật kết nối tại đây)
    logging synchronous Đồng bộ thông báo console, Giữ nguyên những gì chúng ta đang gõ trên màn hình (thông báo sẽ không xen vào khi chúng ta đang gõ lệnh)
    login local Sử dụng username và password trên thiết bị
    exit Quay ra một bật
    line vty 0 4 Vào mode vty-telnet. Tham khảo mục 2 - telnet
    login local Sử dụng username và password trên thiết bị
    transport input all Cho phép/chuyển qua tất cả các dịch vụ (telnet, ssh)
    crypto key generate rsa general-keys modulus 1024 Tạo key khi mã hóa ssh
    ip ssh version 2 Chuyển sang ssh version 2
    12 Tạo Vlan vlan100 Tạo vlan 100
    name HR-Dept Option - Tên của vlan 100 là HR-Dept
    13 Đặt IP cho interface vlan interface Vlan100 Vào mode interface của vlan 100
    no shutdown Kích hoạt interface
    description ===Gateway cho vlan 100=== Option - Chú thích cho interface
    ip address 192.168.100.254 255.255.255.0 Đặt IP cho vlan 100
    14 Đặt IP trên interface interface Ethernet0/0 Vào mode interface của port Ethernet0/0
    no switchport Enable port layer3/Routed port (Trên switch mặt định là port layer 2)
    description ===Linked to Firewall=== Option - Chú thích cho interface
    ip address 192.168.200.2 255.255.255.248 Đặt IP tĩnh cho port Ethernet0/0
    ip address dhcp Interface Et0/0 sẽ xin IP động từ DHCP server
    ip address 192.168.0.1 255.255.255.0 secondary Đặt IP thứ 2 trên 1 interface
    15 Access Mode interface Ethernet0/1 Vào mode interface của port Ethernet0/1
    switchport mode access Chuyển interface Ethernet0/1 về mode access
    switchport access vlan 100 Gán interface Ethernet0/1 vào vlan 100
    16 Trunking interface Ethernet0/2 Vào mode interface của port Ethernet0/2
    switchport trunk encapsulation dot1q Đóng gói chuẩn dot1q. (Có 1 số dòng sản phẩm không cần gõ dòng lệnh này)
    switchport mode trunk Mode trunk
    switchport trunk allowed vlan all Cho phép tất cả các vlan đi qua đường trunk
    17 Routing ip routing Cho phép các IP của các vlan khác nhau có thể giao tiếp được với nhau
    18 Default Route ip route 0.0.0.0 0.0.0.0 200.2.2.1 Trỏ default route về IP 200.2.2.1
    19 DHCP Server ip dhcp pool vlan_101 Tạo pool dhcp có tên pool vlan_101
    network 192.168.101.0 255.255.255.0 Lớp mạng cần cấp cho pool vlan_101 là: 192.168.101.0/24
    dns-server 8.8.8.8 DNS sẽ cấp cho pool là 8.8.8.8
    default-router 192.168.101.254 Default Gateway
    lease 0 0 10 Thời gian clien xin cấp lại ip GIỜ PHÚT GIÂY
    20 DHCP Exclude Address ip dhcp excluded-address 192.168.101.254 DHCP server sẽ không cấp phát địa chỉ 192.168.101.254 cho dhcp client
    ip dhcp excluded-address 192.168.101.1 192.168.101.50 Các IP trong dãy từ 192.168.101.1 -> 50 sẽ không được cấp cho DHCP client
    21 DHCP Relay Agent interface Vlan101 Vào mode interface của vlan 101
    ip helper-address 192.168.100.100 IP 192.168.100.100 sẽ chịu trách nhiệm cấp phát IP cho vlan 101
    22 VLAN Trunking Protocol - VTP vtp domain khanhvc.lab Đặt tên cho vtp domain
    vtp password vtpadmin Đặt password cho vtp
    vtp version 2 Chuyển vtp dùng version 2
    vtp mode server Cài đặt mode cho vtp. VTP có 3 mode là: Server, client và tranperrent
    vtp pruning Tính năng này chỉ bật trên mode server
    23 NAT Overload + ACL interface Ethernet0/1 Vào mode interface (Inside local - interface đấu nối hướng vào mạng LAN )
    ip nat inside Cấu hình NAT inside
    interface Ethernet0/2 Interface Inside global (Cổng đấu nối hướng ra ISP)
    ip nat outside Cấu hình NAT outside
    ip nat inside source list 1 interface Ethernet0/2 overload Thực hiện việc dịch tất cả các địa chỉ IP nằm trong access-list 1 sang địa chỉ IP trên cổng Et0/2
    access-list 1 permit any Định nghĩa access-list 1 và cho phép tất cả các ip
    24 Xóa cấu hình erase startup-config Xóa cấu trên Router/Switch
    delete vlan.dat Nếu là switch chúng ta thực hiện thêm phần xóa các vlan (Tham khảo mục 2 xóa cấu hình)
    reload Khởi động thiết bị
    25 Lưu cấu hình write memory Thực hiện lưu cấu hình
    HOẶC
    copy running-config startup-config

    Lưu cấu hình đang chạy vào file khởi động
    26 no service config Tắt %Error opening tftp://255.255.255.255/xxxx (Timed out)


    2. Basic System Management Configuration

    Router-Cấu Hình Căn Bản
    conf t
    hostname Router-KHANHVC
    ip domain name khanhvc.lab
    no ip domain-lookup
    banner motd #===Router KHANHVC===#
    
    username admin privilege 15 password itadmin
    service password-encryption
     
    line con 0
    logging synchronous
    login local
    exit
    line vty 0 4
    login local
    transport input all
    crypto key generate rsa general-keys modulus 1024
    ip ssh version 2
     
    interface Gi0/0
    no shutdown
    ip address 192.168.1.254 255.255.255.0
    description ===Connect to somewhere===
    exit
    !
    end
    wri   

    Với cấu hình trên chúng ta có thể dùng máy tính đặt IP trong lớp 192.168.1.0/24 -> nối vào port Gi0/1 của router và có thể telnet/ssh vào thiết bị với user: admin; password: itadmin

    Switch-Cấu Hinh Căn Bản
    conf t
    hostname Switch-KHANHVC
    ip domain name khanhvc.lab
    no ip domain-lookup
    banner motd #===Switch KHANHVC===#
    
    username admin privilege 15 password itadmin
    service password-encryption
     
    line con 0
    logging synchronous
    login local
    exit
    line vty 0 4
    login local
    transport input all
    crypto key generate rsa general-keys modulus 1024
    ip ssh version 2
    !
    interface Vlan1
    no shutdown
    description ===MGMT===
    ip address 192.168.1.254 255.255.255.0
    exit
    end
    wri   

    Với cấu hình trên chúng ta có thể dùng máy tính đặt IP trong lớp 192.168.1.0/24 -> nối vào switch và có thể telnet/ssh vào thiết bị với user: admin; password: itadmin

    3. Quit Configuration - Template

    Router-CE-ISP Leased-Line
    conf t
    hostname Router-CE-LL
    ip domain name khanhvc.lab
    no ip domain-lookup
    banner motd #===Router CE Leased-Line===#
    
    username admin privilege 15 password itadmin
    service password-encryption
     
    line con 0
    logging synchronous
    login local
    exit
    line vty 0 4
    login local
    transport input all
    crypto key generate rsa general-keys modulus 1024
    ip ssh version 2
     
    interface et0/0
    no shutdown
    ip address 200.2.2.2 255.255.255.252
    description ===Linked to ISP===
    ip nat outside
    exit
    !
    interface et0/1
    no shutdown
    ip address 100.1.1.1 255.255.255.248
    description ===Linked to Firewall===
    ip nat inside
    exit
    !
    ip route 0.0.0.0 0.0.0.0 200.2.2.1
    ip nat inside source list LAN-to-INTERNET interface Ethernet0/0 overload
    !
    ip access-list extended LAN-to-INTERNET
    deny   ip 100.1.1.0 0.0.0.7 any
    permit ip any any
    exit
    !
    end
    wri    
        
    Core Switch/Layer3 Switch
    conf t
    hostname CoreSwitch
    ip domain name khanhvc.lab
    no ip domain-lookup
    banner motd #===Core Switch IT Room===#
    
    username admin privilege 15 password itadmin
    service password-encryption
     
    line con 0
    logging synchronous
    login local
    exit
    line vty 0 4
    login local
    transport input all
    crypto key generate rsa general-keys modulus 1024
    ip ssh version 2
    !
    interface Vlan1
    no shutdown
    description ===MGMT===
    ip address 192.168.1.254 255.255.255.0
    exit
    vlan 100
    interface Vlan100
    no shutdown
    description ===Server===
    ip address 192.168.100.254 255.255.255.0
    exit
    vlan 101
    interface Vlan101
    no shutdown
    description ===HR Dept.===
    ip address 192.168.101.254 255.255.255.0
    exit
    !
    ip routing
    !
    interface Ethernet0/0
    no switchport
    description ===Linked to Firewall===
    ip address 192.168.200.2 255.255.255.248
    no shutdown
    exit
    interface Ethernet0/1
    description ===Linked to AD Server IP_100.100===
    switchport mode access
    switchport access vlan 100
    no shutdown
    exit
    interface Ethernet0/2
    description ===Linked to Access Switch===
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    exit
    !
    ip route 0.0.0.0 0.0.0.0 200.2.2.1
    !
    end
    wri   

    • Nếu tạo thêm vlan thì chúng ta nhân bản vlan lên ví dụ vlan 102
    conf t
    vlan 102
    interface Vlan102
    no shutdown
    description ===Accc Dept.===
    ip address 192.168.102.254 255.255.255.0
    end
    wri

    • Nếu kết nối nhiều switch Access/Layer2 nhân bản
    conf t
    interface Ethernet0/2
    description ===Linked to Access Switch===
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    end
    wri
    Tùy theo từng dòng sản phầm mà khi cấu hình port trunk CÓ THỂ CÓ hoặc KHÔNG có dòng "switchport trunk encapsulation dot1q"
    Access Switch/Layer2 Switch
    conf t
    hostname Acc-01
    ip domain name khanhvc.lab
    no ip domain-lookup
    banner motd #===Acc-01 HR Dept.===#
    
    username admin privilege 15 password itadmin
    service password-encryption
     
    line con 0
    logging synchronous
    login local
    exit
    line vty 0 4
    login local
    transport input all
    crypto key generate rsa general-keys modulus 1024
    ip ssh version 2
    !
    interface Vlan1
    no shutdown
    description ===MGMT===
    ip address 192.168.1.11 255.255.255.0
    exit
    !
    vlan 101
    interface Vlan101
    no shutdown
    description ===HR Dept.===
    exit
    !
    interface Ethernet0/0
    description ===Linked to Core Switch===
    switchport trunk encapsulation dot1q
    switchport mode trunk
    switchport trunk allowed vlan all
    exit
    !
    interface Ethernet0/1
    description ===Linked to PC===
    switchport mode access
    switchport access vlan 101
    no shutdown
    exit
    !
    end
    wri
    

    Tùy theo từng dòng sản phầm mà khi cấu hình port trunk CÓ THỂ CÓ hoặc KHÔNG có dòng "switchport trunk encapsulation dot1q"

    • Nếu tạo thêm vlan thì chúng ta nhân bản vlan lên ví dụ vlan 102 (vì là layer 2 nên khi tao vlan chúng ta KHÔNG đặt ip trên interface vlan này)
    conf t
    vlan 102
    interface Vlan102
    description ===Accc Dept.===
    end
    wri

    • Nếu có nhiều thiết bị đầu cuối muốn gán vào vlan 101 chúng ta nhân bản lên
    conf t
    interface Ethernet0/2
    description ===Linked to PC===
    switchport mode access
    switchport access vlan 101
    no shutdown
    end
    wri

    • HOẶC chúng ta cũng có thể cấu hình theo range interface vào vlan 101 cũng được ví dụ từ port 3-9 (tùy từng dòng sản phẩm mà phần range có thể là khác nhau tí tí)
    conf t
    interface range Ethernet0/3-9
    description ===Linked to PC===
    switchport mode access
    switchport access vlan 101
    no shutdown
    end
    wri
    DHCP Server: Trường hợp này dùng chính switch Core làm DHCP server
    conf t
    ip dhcp excluded-address 192.168.101.254
    ip dhcp excluded-address 192.168.101.1 192.168.101.50
    !
    ip dhcp pool vlan_101
    network 192.168.101.0 255.255.255.0
    dns-server 8.8.8.8
    default-router 192.168.101.254
    lease 0 0 10
    end
    wri
    

    • Nếu muốn nhân bản cho vlan khác thì copy và chỉnh lại chổ vàng vàng (nếu muốn Core làm DHCP server cho vlan đó) 
    conf t
    ip dhcp excluded-address 192.168.102.254
    ip dhcp excluded-address 192.168.102.1 192.168.102.50
    !
    ip dhcp pool vlan_102
    network 192.168.102.0 255.255.255.0
    dns-server 8.8.8.8
    default-router 192.168.102.254
    lease 0 0 10
    end
    wri

    DHCP Relay Agent:
    Nếu KHÔNG dùng switch Core để cấp DHCP cho client thì chúng ta phải trỏ đến địa chỉ IP của DHCP bên ngoài (phải đảm bảo routing đến được server này thì việc xin IP mới thành công)
    conf t
    interface Vlan101
    ip helper-address 192.168.100.100
    end
    wri
    

    • Nhân bản cho vlan khác: Ví dụ như vlan 102 muốn DHCP server có địa chỉ IP 192.168.100.100 cấp DHCP client cho vlan này 
    conf t
    interface Vlan102
    ip helper-address 192.168.100.100
    end
    wri

    Voice Data:
    Nhằm mục đích ưu tiên tín hiệu voice trước (data ưu tiên sau) để đảm bảo tín hiệu ít trễ nhất có thể. Áp dụng trong trường hợp máy tính cắm vào port PC trên IP Phone (hay PC sau điện thoại)


    conf t
    interface Ethernet1/3
    switchport access vlan 103
    switchport voice vlan 99
    end
    wri
    

    Với cấu hình trên PC sẽ nhận ip của vlan 103, IP phone sẽ nhận ip của vlan 99

    4. VLAN Trunking Protocol  - VTP
    VTP Server Mode Thêm, sửa, xóa sau đó gửi đi để các switch khác học, và chính mode này cũng có thể học/đồng bộ từ các switch khác (trong trường hợp revision của switch khác cao hơn), và cũng có thể forward để các switch khác cùng học.

    Điều kiện:
    - Các đường đấu nối giữa các switch phải là trunk
    - Thông tin vtp giữa các switch khớp nhau: tên domain, password, version, ...

    conf t
    vtp domain khanhvc.lab
    vtp password vtpadmin
    vtp version 2
    vtp mode server
    vtp pruning
    end
    wri
    
    VTP Client Mode Ở mode này các vtp client sẽ học các vlan từ switch khác nếu revision của switch khác cao hơn revision của nó (bản thân nó không được phép tạo, xóa vlan) và forward thông tin cho các switch khác học.

    Với việc triển khai VTP Server-Client thì thông tin vlan sẽ được nhất quán một cách tự động trên toàn hệ thống. Chúng thường được áp dụng triển khai cho hệ thống mới
      conf t
    vtp domain khanhvc.lab
    vtp password vtpadmin
    vtp version 2
    vtp mode client
    end
    wri
    VTP Transparent Mode Được phép tạo, xóa nhưng chỉ tác dụng trên local switch mà không ảnh hưởng đến các switch khác, không gửi thông tin của mình cho các switch khác. Tuy nhiên nó vẫn forward thông tin của người ta (switch khác) cho các switch sau nó học.

    Thông thường khi triển khai xong chúng ta thường chuyển về mode transparent này nếu như các bạn chưa có kiến thức tốt để quản lý VTP
    conf t
    vtp domain khanhvc.lab
    vtp password vtpadmin
    vtp version 2
    vtp mode transparent
    end
    wri

    5. NAT Overload/PAT - Allow Internal Users Access To The Internet

    Cho phép toàn các ip nằm trong Access-List 1 được phép truy cập internet và sử dụng IP trên cổng  Et0/2 là 125.234.102.243 làm IP đại diện
    conf t
    interface Ethernet0/1
    description ===Connect to LAN/CoreSwitch===
    ip address 192.168.200.1 255.255.255.248
    no shut
    ip nat inside
    exit
    interface Ethernet0/2
    description ===Connect to ISP-Router===
    ip address 125.234.102.243 255.255.255.248
    no shut
    ip nat outside
    exit
    !
    ip nat inside source list 1 interface Ethernet0/2 overload
    !
    access-list 1 permit any
    !
    end
    wri
    
    

    6. Trouble shooting - show commands
    đang cập nhật...
    STT Nhóm Commands Giải Thích
    1 show running-config Hiển thị cấu hình hiện tại đang chạy
    2 show vlan Hiển thị các vlan đang tồn tại trên switch
    3 Interface show ip interface brief Hiển thị trạng thái up/down và thông tin IP của các interface
    show interface Hiển thị trạng thái up/down, trạng thái giao thức trên interface, MTU, Lỗi,...
    show interface trunk Hiển thị thông tin về port trunk trên switch
    show run interface Et0/1 Hiển thị cấu hình hiện tại của interface Et0/1
    4 Routing show ip route Hiển thị thông tin bảng định tuyến của thiết bị
    5 show version Hiển thị thông tin register thiết bị, firmware, tên IOS, flash, RAM, ...
    6 VLAN show vlan summary Hiển thị trên switch hiện tại có tất cả bao nhiêu vlan
    show vlan brief Hiển thị thông tin vlan và các interface nào gắng vào vlan nào
    7 DHCP show ip dhcp binding Hiển thị tất cả các IP đã được cấp cho DHCP client
    show ip dhcp conflict Hiển thị các IP đã cấp phát nhưng bị trùng
    show ip dhcp server statistics Hiển thị thông tin chi tiết về dhcp server
    show ip dhcp pool Hiển thị thông tin chi tiết và các pool dhcp
    show run | section ip dhcp Hiển thị tất cả các cấu hình có liên quan đến cấu hình dhcp server
    8 VTP show vtp status Hiển thị thông tin cấu hình vtp
    show vtp password Hiển thị thông tin password của vtp
    9 NAT Overload show ip nat translation Kiểm tra bảng NAT
    clear ip nat statistics Xóa thông tin bảng NAT
    show ip nat statistics Hiển thị thông tin bộ đếm và các thông tin liên quan đến NAT
    9 Access-List show access-lists Hiển thị thông tin Access-List


    Áp dụng vào mô hình thực tế
    Xong!
    /*header slide*/