查看: 139|回复: 0

[Mikrotik Ros] ros routeros ikev2 ipsec传输模式配置

[复制链接]

124

主题

0

回帖

508

积分

管理员

积分
508
发表于 2026-8-30 23:55:53 | 显示全部楼层 |阅读模式
先介绍下环境拓扑图:
1.1.1.1并不是真实的公网IP,而是一个城域网IP,而2.2.2.2是真实的公网IP,所以在这里做ipsec的服务端
1.1.1.1被nat出去以后的IP是b.b.b.b
客户端配置:
  1. /interface bridge
  2. add name=bridge1-wan
  3. /interface ethernet
  4. set [ find default-name=ether1 ] name=ether1-wan
  5. set [ find default-name=ether2 ] name=ether2-wan
  6. set [ find default-name=ether3 ] name=ether3-wan
  7. set [ find default-name=ether4 ] name=ether4-wan
  8. set [ find default-name=ether5 ] name=ether5-lan
  9. /interface pppoe-client
  10. add disabled=no interface=bridge1-wan name=pppoe-out1 password=123456 user=\
  11. 02501017724
  12. /ip ipsec mode-config
  13. add name=cfg1 responder=no
  14. /ip ipsec profile
  15. add enc-algorithm=aes-256 hash-algorithm=sha256 name=ikev2-profile1
  16. /ip ipsec peer
  17. add address=2.2.2.2/32 exchange-mode=ike2 name=ikev2-peer1 profile=\
  18. ikev2-profile1
  19. /ip ipsec proposal
  20. add auth-algorithms=sha256 enc-algorithms=aes-256-cbc name=ikev2-proposal1 \
  21. pfs-group=none
  22. /interface bridge port
  23. add bridge=bridge1-wan interface=ether1-wan
  24. add bridge=bridge1-wan interface=ether2-wan
  25. add bridge=bridge1-wan interface=ether3-wan
  26. add bridge=bridge1-wan interface=ether4-wan
  27. /ip address
  28. add address=192.168.90.100/24 interface=ether5-lan network=192.168.90.0
  29. /ip dns
  30. set servers=114.114.114.114
  31. /ip firewall nat
  32. add action=accept chain=srcnat dst-address=10.10.2.0/24 src-address=\
  33. 192.168.77.0/24
  34. add action=accept chain=srcnat dst-address=10.10.2.0/24 src-address=\
  35. 192.168.90.0/24
  36. add action=masquerade chain=srcnat out-interface=pppoe-out1
  37. /ip ipsec identity
  38. add generate-policy=port-strict mode-config=cfg1 peer=ikev2-peer1 secret=\
  39. 12345678
  40. /ip ipsec policy(这里要斟酌下1.1.1.1这里的IP怎么写,因为这个IP是城域网IP,nat出去以后并不是这个ip,nat出去以后是b.b.b.b这个ip)
  41. add dst-address=10.10.2.0/24 level=unique proposal=ikev2-proposal1 \
  42. sa-dst-address=2.2.2.2 sa-src-address=1.1.1.1 src-address=\
  43. 192.168.90.0/24 tunnel=yes
  44. /ip route
  45. add distance=1 gateway=pppoe-out1
复制代码
服务端配置:
  1. /interface ethernet
  2. set [ find default-name=ether1 ] name=ether1-wan
  3. set [ find default-name=ether2 ] name=ether2-lan
  4. /ip ipsec profile
  5. add enc-algorithm=aes-256 hash-algorithm=sha256 name=ikev2-profile1
  6. /ip ipsec peer
  7. add exchange-mode=ike2 name=ikev2-peer1 passive=yes profile=ikev2-profile1 \
  8. send-initial-contact=no
  9. /ip ipsec proposal
  10. add auth-algorithms=sha256 enc-algorithms=aes-256-cbc name=ikev2-proposal1 \
  11. pfs-group=none
  12. /ip pool
  13. add name=ikev2-pool ranges=192.168.77.2-192.168.77.254
  14. /ip ipsec mode-config
  15. add address-pool=ikev2-pool address-prefix-length=32 name=cfg1 \
  16. split-include=10.10.2.0/24 system-dns=no
  17. /ip address
  18. add address=2.2.2.2/28 interface=ether1-wan network=2.2.2.0
  19. add address=10.10.2.100/24 interface=ether2-lan network=10.10.2.0
  20. /ip firewall nat
  21. add action=accept chain=srcnat dst-address=192.168.77.0/24 src-address=\
  22. 10.10.2.0/24
  23. add action=accept chain=srcnat dst-address=192.168.90.0/24 src-address=\
  24. 10.10.2.0/24
  25. add action=masquerade chain=srcnat out-interface=ether1-wan
  26. /ip ipsec identity
  27. add generate-policy=port-strict mode-config=cfg1 peer=ikev2-peer1 secret=\
  28. 12345678
  29. /ip ipsec policy(这里需要斟酌下,IP公网怎么写,b.b.b.b是客户端路由nat以后的公网IP)
  30. add dst-address=192.168.90.0/24 level=unique proposal=ikev2-proposal1 \
  31. sa-dst-address=b.b.b.b sa-src-address=2.2.2.2 \
  32. src-address=10.10.2.0/24 tunnel=yes
  33. /ip route
  34. add distance=1 gateway=2.2.2.1
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:admin@discuz.vip

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|蜀ICP备17024538号-6

在本版发帖
关注公众号
QQ客服返回顶部