
一、基础网络配置实现设备间可达性1.1 PC配置PC1: ip 192.168.1.1 255.255.255.0 192.168.1.254 PC2: ip 192.168.3.1 255.255.255.0 192.168.3.2541.2 R16配置分支机构路由器interface GigabitEthernet 0/0 ip address 10.10.10.1 255.255.255.0 ! interface GigabitEthernet 0/1 ip address 192.168.1.254 255.255.255.0 ! 添加默认路由指向公网路由器R17 ip route 0.0.0.0 0.0.0.0 10.10.10.21.3 R17配置公网路由器interface GigabitEthernet 0/0 ip address 10.10.10.2 255.255.255.0 ! interface GigabitEthernet 0/1 shutdown ! interface GigabitEthernet 0/2 ip address 202.100.1.254 255.255.255.0 ! 添加路由指向两个分支机构网络 ip route 192.168.1.0 255.255.255.0 10.10.10.1 ip route 192.168.3.0 255.255.255.0 202.100.1.11.4 R23配置总部路由器interface GigabitEthernet 0/0 ip address 202.100.1.1 255.255.255.0 ! interface GigabitEthernet 0/1 ip address 192.168.3.254 255.255.255.0 ! 添加默认路由指向公网路由器R17 ip route 0.0.0.0 0.0.0.0 202.100.1.2542.1 R23配置总部端固定公网IP! 创建IKE策略 crypto isakmp policy 1 encryption aes 256 ! 使用AES-256加密 authentication pre-share ! 预共享密钥认证 hash sha256 ! 使用SHA-256进行完整性校验 group 14 ! 使用2048位的DH组更安全 lifetime 86400 ! SA生存时间秒 ! 配置预共享密钥 ! 此处使用 0.0.0.0 表示接受来自任意对端IP的连接请求用于动态IP场景 crypto isakmp key MySecureKey123 address 0.0.0.0 0.0.0.0! 定义IPsec转换集指定加密和认证算法 crypto ipsec transform-set MY-TRANSFORM esp-aes 256 esp-sha256-hmac ! 创建动态加密图模板 ! 序列号5用于动态模板 crypto dynamic-map DYN-MAP 5 set transform-set MY-TRANSFORM ! 关联转换集 match address 100 ! 关联ACL 100定义感兴趣流 ! 创建静态加密图并引用动态模板 ! 静态加密图序列号10需大于动态模板序列号5 crypto map MY-MAP 10 ipsec-isakmp dynamic DYN-MAPinterface GigabitEthernet 0/0 ip address 202.100.1.1 255.255.255.0 crypto map MY-MAP2.2 R16配置分支机构端动态或固定IPcrypto isakmp policy 1 encryption aes 256 authentication pre-share hash sha256 group 14 lifetime 86400 ! 配置预共享密钥指定对端R23的公网IP地址 crypto isakmp key MySecureKey123 address 202.100.1.1! 定义IPsec转换集必须与对端相同 crypto ipsec transform-set MY-TRANSFORM esp-aes 256 esp-sha256-hmac ! 创建静态加密图明确指定对端IP crypto map MY-MAP 5 ipsec-isakmp set peer 202.100.1.1 ! 指定对端公网IP set transform-set MY-TRANSFORM ! 关联转换集 match address 101 ! 关联ACL 101定义本端感兴趣流 acl配置 ip access-list extended 101 10 permit ip 192.168.1.0 0.0.0.255 192.168.3.0 0.0.0.255interface GigabitEthernet 0/0 ip address 10.10.10.1 255.255.255.0 crypto map MY-MAP3.1 R16配置! 创建Tunnel接口 interface Tunnel 0 ip address 172.16.1.1 255.255.255.252 ! 配置隧道接口IP tunnel source 10.10.10.1 ! 隧道源地址本端公网接口IP tunnel destination 202.100.1.1 ! 隧道目的地址对端公网IP tunnel mode gre ip ! 隧道模式为GRE over IP ! 配置OSPF进程 router ospf 100 router-id 16.16.16.16 ! 手动指定Router ID network 172.16.1.1 0.0.0.0 area 0 ! 宣告隧道接口到骨干区域3.2 R23配置interface Tunnel 0 ip address 172.16.1.2 255.255.255.252 tunnel source 202.100.1.1 tunnel destination 10.10.10.1 tunnel mode gre ip router ospf 100 router-id 23.23.23.23 network 172.16.1.2 0.0.0.0 area 0说明本文为学习与实验环境下的网络配置示例旨在帮助理解动态IPsec VPN与OSPF over GRE的工作原理。实际生产环境请根据安全要求和设备型号使用更强的加密算法与认证方式。配置验证完成上述配置后在R16和R23上使用show crypto session查看IPsec SA状态使用show ip ospf neighbor查看OSPF邻居关系使用ping命令测试两端私网192.168.1.0/24 与 192.168.3.0/24的连通性。