|
[VPN] 双动态IP; IPSEC; Site to Site VPN
需求描述:
site a: 内部192.168.11.0/24 外部电信FTTB线路, PPPoE获取动态公网IP
site b: 内部172.16.10.0/24 外部电信xDSL线路, PPPoE获取动态公网IP
site a, b 能够相互访问, 采用自带的Cloud DNS Name 标识双方; 采用IPSEC加密通信, 任意一边断线后重新自动建立IPSEC恢复通信.
配置过程:
site a:- /ip ipsec peer
- add address=200.200.200.200/32 enc-algorithm=aes-128 nat-traversal=no secret=111111
複製代碼 这里地址填写site b的公网地址; enc-algorithm与site b设定一致; secret随意且与site b设定一致.- /ip ipsec policy
- add dst-address=172.16.10.0/24 sa-dst-address=200.200.200.200 sa-src-address=100.100.100.100 src-address=192.168.11.0/24 tunnel=yes
複製代碼 这里src-address填写site a内网地址段; dst-address填写site b内网地址段; sa-src-address填写site a公网ip; sa-dst-address填写site b公网ip; tunnel设定为yes- /ip firewall nat
- add chain=srcnat dst-address=172.16.10.0/24 src-address=192.168.11.0/24
複製代碼 这里dst-address填写site b内网地址段; src-address填写site a内网地址段; 将此条放置在第一条.- #-----------
- #site to site ipsec tunel vpn, no actual interface, no OSPF!
- #script by moses
- #-----------
- #-----------
- #setting
- :global localsite "aaaaaaaaaaaa.sn.mynetname.net"
- #这里引号内为site a的Cloud DNS Name
- :global remotesite "bbbbbbbbbbbb.sn.mynetname.net"
- #这里引号内为site b的Cloud DNS Name
- :global vpninterface "pppoe-out1"
- #这里引号内为site a拨号接口
- #-----------
- #-----------
- #:global localcurrentip [:resolve $localsite]
- :global localcurrentip [:pick [/ip address get [find interface=$vpninterface] address] 0 [:find [/ip address get [find interface=$vpninterface] address] "/"]]
- :global localpreviousip
- :global remotecurrentip [:resolve $remotesite]
- :global remotepreviousip
- #-----------
- #-----------
- :if (($localcurrentip != $localpreviousip) || ($remotecurrentip != $remotepreviousip)) do= {
- /ip ipsec peer set 0 address=$remotecurrentip
- /ip ipsec policy set 1 sa-src-address=$localcurrentip sa-dst-address=$remotecurrentip
- /ip ipsec remote-peers kill-connections
- :set localpreviousip $localcurrentip
- :set remotepreviousip $remotecurrentip
- :log warning "IPSEC RESET! L:$localcurrentip R:$remotecurrentip"
- } else= {
- #:log info "no change"
- }
- #-----------
複製代碼 这个脚本命名为chkipsec, 在scheduler中每分钟调用一次就好.
site b:- /ip ipsec peer
- add address=100.100.100.100/32 enc-algorithm=aes-128 nat-traversal=no secret=111111
複製代碼 这里地址填写site a的公网地址; enc-algorithm与site a设定一致; secret随意且与site a设定一致.- /ip ipsec policy
- add dst-address=192.168.11.0/24 sa-dst-address=100.100.100.100 sa-src-address=200.200.200.200 src-address=172.16.10.0/24 tunnel=yes
複製代碼 这里src-address填写site b内网地址段; dst-address填写site a内网地址段; sa-src-address填写site b公网ip; sa-dst-address填写site a公网ip; tunnel设定为yes- /ip firewall nat
- add chain=srcnat dst-address=192.168.11.0/24 src-address=172.16.10.0/24
複製代碼 这里dst-address填写site a内网地址段; src-address填写site b内网地址段; 将此条放置在第一条.- #-----------
- #site to site ipsec tunel vpn, no actual interface, no OSPF!
- #script by moses
- #-----------
- #-----------
- #setting
- :global localsite "bbbbbbbbbbbb.sn.mynetname.net"
- #这里引号内为site b的Cloud DNS Name
- :global remotesite "aaaaaaaaaaaa.sn.mynetname.net"
- #这里引号内为site a的Cloud DNS Name
- :global vpninterface "pppoe-out1"
- #这里引号内为site b拨号接口
- #-----------
- #-----------
- #:global localcurrentip [:resolve $localsite]
- :global localcurrentip [:pick [/ip address get [find interface=$vpninterface] address] 0 [:find [/ip address get [find interface=$vpninterface] address] "/"]]
- :global localpreviousip
- :global remotecurrentip [:resolve $remotesite]
- :global remotepreviousip
- #-----------
- #-----------
- :if (($localcurrentip != $localpreviousip) || ($remotecurrentip != $remotepreviousip)) do= {
- /ip ipsec peer set 0 address=$remotecurrentip
- /ip ipsec policy set 1 sa-src-address=$localcurrentip sa-dst-address=$remotecurrentip
- /ip ipsec remote-peers kill-connections
- :set localpreviousip $localcurrentip
- :set remotepreviousip $remotecurrentip
- :log warning "IPSEC RESET! L:$localcurrentip R:$remotecurrentip"
- } else= {
- #:log info "no change"
- }
- #-----------
複製代碼 这个脚本命名为chkipsec, 在scheduler中每分钟调用一次就好. |
|