AnycastIP - tips and tricks

ZeroTier client  - adding and removing anycast configuration


Configuration only for systemd based operation systems.

1. Create empty file and paste following content
#!/bin/bash

ip4=("185.187.152.x/32") #replace with your anycast IPv4 address
ip6=("2a05:b0c4:1::x/128") #replace with your anycast IPv6 address
gw4="172.31.255.y" #replace with AnycastIP gateway IPv4 address
gw6="fd00:dead:c0de:cafe:172:31:255:y" #replace with AnycastIP gateway IPv6 address dn="dummy0"

modprobe dummy

ip link set $dn down &> /dev/null
ip link del dev $dn type dummy &> /dev/null

ip link add $dn type dummy
ip link set $dn up

if [ "" == "`cat /etc/iproute2/rt_tables | grep anycast`" ]; then
echo '666     anycast' >> /etc/iproute2/rt_tables
fi

for ip in ${ip4[@]}; do
ip -4 addr add dev $dn $ip
ip -4 rule add from $ip table anycast
done

ip -4 route add default via $gw4 table anycast

for ip in ${ip6[@]}; do
ip -6 addr add dev $dn $ip
ip -6 rule add from $ip table anycast
done

ip -6 route add default via $gw6 table anycast
Save the file as
/opt/zerotier-post-start.sh  

2. Create empty file and paste following content
#!/bin/bash

gw4=`ip -4 route show table anycast | awk '{ print $3 }'`
gw6=`ip -6 route show table anycast | awk '{ print $3 }'`
dn="dummy0"

if [ "" != "$gw4" ]; then
ip -4 route del default via $gw4 table anycast
fi

if [ "" != "$gw6" ]; then
ip -6 route del default via $gw6 table anycast
fi

ip link set $dn down
ip link del dev $dn type dummy
Save the file as
 /opt/zerotier-post-stop.sh  

3. Edit the ZeroTier service file
nano /lib/systemd/system/zerotier-one.service
Add following lines
[Service]
...
ExecStartPost=/bin/bash /opt/zerotier-post-start.sh
ExecStopPost=/bin/bash /opt/zerotier-post-stop.sh
Save the changes and reload the service
systemctl daemon-reload

Example Quagga BGP configuration

hostname your-hostname
log file /var/log/quagga/bgpd.log
!
router bgp <AnycastIP AS number>
bgp router-id <ZeroTier IPv6 address>
network <anycast IPv4 address>/32
neighbor <AnycastIP router IPv4 address> remote-as 198412
neighbor <AnycastIP router IPv4 address> password <AnycastIP network password>
neighbor <AnycastIP router IPv4 address> ebgp-multihop 25
neighbor <AnycastIP router IPv4 address> soft-reconfiguration inbound
neighbor <AnycastIP router IPv4 address> route-map rm-out out
neighbor <AnycastIP router IPv6 address> remote-as 198412
neighbor <AnycastIP router IPv6 address> password <AnycastIP network password>
neighbor <AnycastIP router IPv6 address> ebgp-multihop 25
no neighbor <AnycastIP router IPv6 address> activate
!
address-family ipv6
network <anycast IPv6 address>/128
neighbor <AnycastIP router IPv6 address> activate
neighbor <AnycastIP router IPv6 address> soft-reconfiguration inbound
neighbor <AnycastIP router IPv6 address> route-map rm-out out
exit-address-family
!
ip prefix-list pl-v4 seq 10 permit <anycast IPv4 address>/32
ipv6 prefix-list pl-v6 seq 10 permit <anycast IPv6 address>/128
!
route-map rm-out permit 20
match ip address prefix-list pl-v4
!
route-map rm-out permit 30
match ipv6 address prefix-list pl-v6
set ipv6 next-hop global <ZeroTier IPv6 address>
!
line vty
!



Feedback and Knowledge Base