网络安全学习--网络模型学习

分层思想

将复杂的流程分解为几个功能相对单一的子过程

  • 整个流程更加清晰,复杂问题简单化
  • 更容易发现问题并针对性的解决问题

OSI(Open System interconnection)开放通信系统互联参考模型

在这里插入图片描述

数据的封装与解封装

应用层-----------------PDU/数据
传输层-----------------数据段/Fragment
网络层-----------------报文/包/Packet
数据链路层-----------帧/Frame
物理层-----------------比特/bit

物理层

  • 网线/光纤/空气
  • 比特
  • 信号
    • 模拟信号
    • 数字信号
  • 光纤类型
    • 单模光纤(一般黄色)
    • 多模光纤(一般橙色/蓝色)
  • 网线/双绞线:
    • 5类双绞线
    • 超5类双绞线
    • 6类、7类
    • T568A:白绿、绿、白橙、蓝、白蓝、橙、白棕、棕
    • T568B:白橙、橙、白绿、蓝、白蓝、绿、白棕、棕
  • 网线用途分类
    • 交叉线:一端A,一端B同种设备间使用
    • 直通线:两端都为A或都为B(目前市面上),异种设备间使用
    • 全反线:一端为A,另一端为反A,称为console线

数据链路层(Data Link Layer)

处于2层
传输单元:帧
帧结构
MAC地址:物理地址,全球唯一,长度:48位,6个字节

#16进制MAC地址
   物理地址. . . . . . . . . . . . . : 04-D9-F5-AD-54-CD

在这里插入图片描述
MAC地址表
MAC地址表中出现的都是与自己有关的端口
交换机是通过学习帧中的源MAC地址和接口来形成MAC地址表
交换机通过向除传输的端口外的所有端口广播来查找目标MAC,收到广播主机先判断是否是自己的MAC,如不是自己,则进行弃包,
交换时间默认300秒老化时间

交换机工作原理
  1. 交换机收到数据帧后,首先学习帧中的源MAC地址来形成MAC地址表
  2. 检查帧中的目标MAC地址,并匹配MAC地址表,如表中有匹配项,则单播转发,如表中无匹配项,则除接收端口外广播转发
  3. MAC地址表的老化时间默认为300秒(可修改)
交换机端口

Ethernet 10Mb/s
FastEthernet 100Mb/s
GigabitEthernet 1000Mb/s
TenGigabitEthernet 10000Mb/s
F0/1:0为模块号,1为接口号
接口速率自适应:10/100/1000M自适应-----速度工作模式可以为10,100,1000任何一种状态
端口状态:up/down
down

  • 人工down
  • 速率不匹配
  • 双工(duplex)模式不匹配
    • 单工–单向通信
    • 半双工–一边发一边听
    • 全双工–双边通信
      交换机基本工作模式及命令
      第一次配置网络设备,需要使用console线
      在PC需要使用“超级终端”或其它软件

配置交换机

Cisco Packet Tracer软件下载路径如下:
链接:https://pan.baidu.com/s/1F-b_t9o-a526yi8lDqLOrw
提取码:k2cs
在这里插入图片描述

  1. 用户模式:
    switch>
    可以查看交换机的基本信息,且不能做任何修改配置!
    在这里插入图片描述

  2. 特权模式
    在特权模式可以查看所有配置,且不能修改配置,但可以做测试,保存,初始化等操作

#enable进入特权模式
Switch>enable
Switch#
  1. 全局配置模式
    默认不能查看配置,可以修改配置,且全局生效
#使用configure terminal进入配置模式
Switch#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#
  1. 接口配置模式
    必须通过全局配置模式进入,默认不能查看配置,可以修改配置,且对该端口生效
Switch(config)#interface f0/1
Switch(config-if)#
  1. console口配置模式
    必须通过全局配置模式进入,默认不能查看配置,可以修改配置,且对console口生效
Switch(config)#line console 0
Switch(config-line)#
  1. 命令学习
#退出配置,一级一级退出
Switch(config-if)#exit
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#
#end直接退到特殊提示符
Switch(config-if)#end
Switch#
#查看命令
Switch#e?
enable  erase  exit  
#修改交换机名称
Switch(config-if)#hostname sw1
sw1(config)#

#设置用户密码,密码输入错误无法进入用户模式
sw1(config)#line console 0
sw1(config-line)#password 123456
#密码设置完成后,再次进入交换机配置,需要输入密码
User Access Verification

Password: 
#交换机重启
sw1#reload
System configuration has been modified. Save? [yes/no]:yes
Building configuration...
[OK]
Proceed with reload? [confirm]
#ctrl+u删除鼠标至行首的信息
#ctrl+a切换至行首
#ctrl+e切换到行尾
  1. 支持命令缩写
  2. tab补全键
  3. 在内存中存在一个文件:running-config,第一次开机,系统会在内存中自动创建一个新的干净的running-config文件
  4. 保存配置
sw1#copy running-config startup-config
Destination filename [startup-config]? 
Building configuration...
[OK]
  1. 交换机开机动作
    先去硬盘查看startup-config是否存在,如果不存在,在内存中创建新的running-config文件;如存在,则复制到内存中并更名为running-config
  2. 查看running-config配置
#查看配置文件
sw1#show startup-config
sw1#show running-config
Building configuration...
#配置特殊密码
sw1(config)#enable password 123456
#进入特殊模式需要输入密码
sw1>enable
Password: 
#MD5加密密码
sw1(config)#enable secret 12345678
#查看running-config
sw1#show running-config
Building configuration...

Current configuration : 1173 bytes
!
version 15.0
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname sw1
!
enable secret 5 $1$mERr$SI6kKbhlkuiS3Lv8zc1kp1
#清除配置文件
sw1#erase startup-config
Erasing the nvram filesystem will remove all configuration files! Continue? [confirm]
[OK]
Erase of nvram: complete
%SYS-7-NV_BLOCK_INIT: Initialized the geometry of nvram
  1. 查看 MAC地址表
    先新建两台主机与交换机连接
    在这里插入图片描述
    给两台虚拟的电脑配置IP,一台为10.1.1.2,一台10.1.1.3,子网掩码:255.255.255.0
    在这里插入图片描述
sw1#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

%LINK-5-CHANGED: Interface FastEthernet0/2, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up
sw1#show mac-address-table
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
#查看MAC地址表,需要执行一下ping
sw1#show mac-address-table
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----

   1    0040.0b4e.489b    DYNAMIC     Fa0/2
   1    00d0.d3eb.2567    DYNAMIC     Fa0/1
#查看接口的简要信息
sw1#show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/1        unassigned      YES manual up                    up 
FastEthernet0/2        unassigned      YES manual up                    up 
FastEthernet0/3        unassigned      YES manual down                  down 
FastEthernet0/4        unassigned      YES manual down                  down 
FastEthernet0/5        unassigned      YES manual down                  down 
FastEthernet0/6        unassigned      YES manual down                  down 
FastEthernet0/7        unassigned      YES manual down                  down 
FastEthernet0/8        unassigned      YES manual down                  down 
FastEthernet0/9        unassigned      YES manual down                  down 
FastEthernet0/10       unassigned      YES manual down                  down 
FastEthernet0/11       unassigned      YES manual down                  down 
FastEthernet0/12       unassigned      YES manual down                  down 
FastEthernet0/13       unassigned      YES manual down                  down 
FastEthernet0/14       unassigned      YES manual down                  down 
FastEthernet0/15       unassigned      YES manual down                  down 
FastEthernet0/16       unassigned      YES manual down                  down 
FastEthernet0/17       unassigned      YES manual down                  down 
FastEthernet0/18       unassigned      YES manual down                  down 
FastEthernet0/19       unassigned      YES manual down                  down 
FastEthernet0/20       unassigned      YES manual down                  down 
FastEthernet0/21       unassigned      YES manual down                  down 
FastEthernet0/22       unassigned      YES manual down                  down 
FastEthernet0/23       unassigned      YES manual down                  down 
FastEthernet0/24       unassigned      YES manual down                  down 
GigabitEthernet0/1     unassigned      YES manual down                  down 
GigabitEthernet0/2     unassigned      YES manual down                  down 
Vlan1                  unassigned      YES manual administratively down down
#Status,Protocol两个接口中状态含义
#Status表示物理层状态,Protocol表示数据链路层状态,表示协商速率,协商全双工,半双工模式
#1) up   up 		第一个up表示人工开启接通网线,第二个表示协商成功
#2) down down		第一个down表示人工开启没有接通网线,
#3) up   down		第一个up表示人工开启接通网线,第二个表示没有协商成功
#4) administratively down  down	第一个人工down
#2层接口默认开启,3层接口默认都是管理down(人工shutdown)
#关闭掉FastEthernet0/1接口
sw1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
sw1(config)#
sw1(config)#
sw1(config)#
sw1(config)#interface FastEthernet 0/1
sw1(config-if)#
sw1(config-if)#shutdown

sw1(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
#再次查看IP 接口信息
sw1#show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/1        unassigned      YES manual administratively down down 
#手工开启FastEthernet0/1端口
sw1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
sw1(config)#interface FastEthernet0/1
sw1(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
#查看IP接口信息
sw1#show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/1        unassigned      YES manual up                    up 
#在其它模式下使用特权模式命令,前面加do
sw1(config)#do show running-config
Building configuration...
  1. 删除配置
  • 在哪配置,在哪删除
  • 命令前加no空格
  • 原命令中有参数,并且参数具有唯一性,不需要加参数
#删除主机名
sw1(config)#no hostname sw1
#删除用户密码
Switch(config)#line console 0
Switch(config-line)#no enable password
路由器设置IP

在这里插入图片描述

Router>enable
Router#
Router#configure terminal
Enter configuration commands, one doper line.  End with CNTL/Z.
Router(config)#
Router(config-if)#do show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/0        unassigned      YES unset  administratively down down 
FastEthernet0/1        unassigned      YES unset  administratively down down 
Vlan1                  unassigned      YES unset  administratively down down
#给路由器设置IP地址和子网掩码,并开启路由器
Router(config-if)#ip address 10.1.1.254 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#do show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/0        10.1.1.254      YES manual up                    up 
FastEthernet0/1        unassigned      YES unset  administratively down down 
Vlan1                  unassigned      YES unset  administratively down down
路由器开启远程控制
Router(config)#line vty ?
  <0-15>  First Line number
 #开启远程连接并设置连接密码
Router(config-line)#line vty 0 4
Router(config-line)#password ?
  7     Specifies a HIDDEN password will follow
  LINE  The UNENCRYPTED (cleartext) line password
Router(config-line)#password 123456
Router(config-line)#login
Router(config-line)#exit



#通过远程客户端连接路由器
C:\>telnet 10.1.1.254
Trying 10.1.1.254 ...Open


User Access Verification

Password: 
Router>
#远程电脑连接必须设置特权密码
Router>enable
% No password set.
#到路由器设置特权密码
Router(config)#enable password 123456
#路由器设置完成后,在客户端电脑连接再次输入密码
Router>enable
Password: 
Router#
#在路由器设置客户端连接方式使用SSH连接
ru1(config)#line vty 0 4
ru1(config-line)#
ru1(config-line)#transport input ssh
#给路由器配置域名
ru1(config)#ip domain-name www.tye.com
#生成密钥对
ru1(config)#crypto key generate rsa
The name for the keys will be: ru1.www.tye.com
Choose the size of the key modulus in the range of 360 to 2048 for your
  General Purpose Keys. Choosing a key modulus greater than 512 may take
  a few minutes.

How many bits in the modulus [512]: 
% Generating 512 bit RSA keys, keys will be non-exportable...[OK]
#在客户端使用SSH连接路由器
C:\>ssh -l ru1 10.1.1.254
Password: 
ru1>
#启动本地身份认证
ru1(config-line)#login local
ru1(config-line)#exit
#设置用户名,密码
ru1(config)#username tye password 123456
ru1(config)#username edison password 654321

路由器配置事例

在这里插入图片描述

Would you like to enter the initial configuration dialog? [yes/no]: no


Press RETURN to get started!

Router>enable
Router#hostname R1
                ^
% Invalid input detected at '^' marker.
	
Router#
Router#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#hostname R1
R1(config)#interface FastEthernet 0/0
R1(config-if)#ip addr 10.1.1.254 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#interface FastEthernet 0/1
R1(config-if)#ip addr 20.1.1.254 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit

#设置完成后为两个网段内的主机配置网关,配置网关后,进行ping测试
#为PC开启路由器telnet功能
R1(config)#line vty 0 4
R1(config-line)#login local
R1(config-line)#exit
R1(config)#username tye password 123456
#通过客户机连接
C:\>telnet 10.1.1.254
Trying 10.1.1.254 ...Open
User Access Verification
Username: tye
Password: 
R1>
为交换机配置管理IP

Switch>
Switch>enable
Switch#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#
Switch(config)#
Switch(config)#
Switch(config)#
Switch(config)#interface vlan 1
Switch(config-if)#ip addr 10.1.1.253 255.255.255.0
Switch(config-if)#do show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/1        unassigned      YES manual up                    up 
FastEthernet0/2        unassigned      YES manual up                    up 
FastEthernet0/3        unassigned      YES manual up                    up 
FastEthernet0/4        unassigned      YES manual down                  down 
FastEthernet0/5        unassigned      YES manual down                  down 
FastEthernet0/6        unassigned      YES manual down                  down 
FastEthernet0/7        unassigned      YES manual down                  down 
FastEthernet0/8        unassigned      YES manual down                  down 
FastEthernet0/9        unassigned      YES manual down                  down 
FastEthernet0/10       unassigned      YES manual down                  down 
FastEthernet0/11       unassigned      YES manual down                  down 
FastEthernet0/12       unassigned      YES manual down                  down 
FastEthernet0/13       unassigned      YES manual down                  down 
FastEthernet0/14       unassigned      YES manual down                  down 
FastEthernet0/15       unassigned      YES manual down                  down 
FastEthernet0/16       unassigned      YES manual down                  down 
FastEthernet0/17       unassigned      YES manual down                  down 
FastEthernet0/18       unassigned      YES manual down                  down 
FastEthernet0/19       unassigned      YES manual down                  down 
FastEthernet0/20       unassigned      YES manual down                  down 
FastEthernet0/21       unassigned      YES manual down                  down 
FastEthernet0/22       unassigned      YES manual down                  down 
FastEthernet0/23       unassigned      YES manual down                  down 
FastEthernet0/24       unassigned      YES manual down                  down 
GigabitEthernet0/1     unassigned      YES manual down                  down 
GigabitEthernet0/2     unassigned      YES manual down                  down 
Vlan1                  10.1.1.253      YES manual administratively down down
#开启交换机虚拟端口
Switch(config-if)#no shutdown
#为交换机设置登录
Switch(config)#line vty 0 4
Switch(config-line)#login local
Switch(config-line)#exit
Switch(config)#username tye password 123456
#为20网段交换机配置网关,方便跨网段管理
Switch(config)#ip default-gateway 20.1.1.254
关闭路由器自动解析功能
R1>enable
R1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#no ip domain-lookup
R1(config)#ssss
            ^
% Invalid input detected at '^' marker.

猜你喜欢

转载自blog.csdn.net/xuwenpeng/article/details/121758152