IP基础
1.跨网段通信:
路由器配置:
R1
#
interface GigabitEthernet0/0/0
ip address 192.168.1.1 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 192.168.2.1 255.255.255.0
#
两台pc机配置地址和网关,记得点应用
当pc1访问pc2时:
pc1会判断是否跨网段通信,如果是跨网段则会发出arp包给网关,获知网关的mac地址,然后把数据包发给网关。(否之,发出目的地址的arp报文,获知mac地址。)R1收到数据包,然后查询路由器条目,根据路由器条目转发数据包,但因为没有目的地址mac地址,所以发出arp报文去获知目的mac地址,然后发出数据包,然后pc2发出数据包按原路返回。
路由器g0/0/0的抓包
2.单臂路由
R1
#
interface GigabitEthernet0/0/0.10 #进入子接口<子接口数量为0-4096>
dot1q termination vid 10 #将子接口划分为vlan10
ip address 192.168.1.1 255.255.255.0 #配置ip
arp broadcast enable #配置允许发送arp广播
#
interface GigabitEthernet0/0/0.20
dot1q termination vid 20
ip address 192.168.2.1 255.255.255.0
arp broadcast enable
#
SW1
#
vlan batch 10 20
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094
#
interface GigabitEthernet0/0/2
port link-type access
port default vlan 10
#
interface GigabitEthernet0/0/3
port link-type access
port default vlan 20
#
路由器g0/0/0的抓包
这个是pc1发向路由器g0/0/0.10子接口的数据包,带上vlan 10 tag。因为路由器子接口,可以读取带tag的数据包,而且sw1的g0/0/1是trunk,允许通过vlan 10 和20。
第二个数据包是路由器g0/0/0.20子接口发向pc2的数据包,带上vlan 20 tag,因为路由器子接口,可以发送带tag的数据包,而且sw1的g0/0/1是trunk,允许通过vlan 10 和20。
3.rip路由协议
R1(左边为R1,右边为R2,忘记改了)
#
interface GigabitEthernet0/0/0
ip address 192.168.1.1 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 192.168.3.1 255.255.255.0
#
rip 1 #进入rip进程
version 2 #使用版本2
network 192.168.1.0 #宣告网段,记得把连接其它运行rip协议的设备的连接链路宣告。
network 192.168.3.0 #记得按A,B,C类来宣告。
#
R2
#
interface GigabitEthernet0/0/0
ip address 192.168.3.2 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 192.168.2.1 255.255.255.0
#
rip 1
version 2
network 192.168.2.0
network 192.168.3.0
查看R1 的路由表,注:直连链路优先值为0,ospf为10,isis为15,bgp为255,rip为100,静态路由为60(越小越优)|(思科有所不同)
连通性测试:
4.浮动路由
R1(左边为R1,右边为R2,忘记改了)
#
interface GigabitEthernet0/0/0
ip address 192.168.1.1 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 192.168.3.1 255.255.255.0
#
interface GigabitEthernet0/0/2
ip address 192.168.4.1 255.255.255.0
#
ip route-static 192.168.2.0 255.255.255.0 192.168.3.2 #使用默认优先值(越小越优)
ip route-static 192.168.2.0 255.255.255.0 192.168.4.2 preference 70 #使用比默认优先值大的数值,从而被第一条路由顶替。
#
R2(左边为R1,右边为R2,忘记改了)
#
interface GigabitEthernet0/0/0
ip address 192.168.3.2 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 192.168.2.1 255.255.255.0
#
interface GigabitEthernet0/0/2
ip address 192.168.4.2 255.255.255.0
#
ip route-static 192.168.1.0 255.255.255.0 192.168.3.1
ip route-static 192.168.1.0 255.255.255.0 192.168.4.1 preference 70
#
模拟R1的g0/0/1down,然后备用路由顶替,实现较高的网络冗余(实际应用中会带有链路检测,从而降低丢包率)。