Forked from venkataanil/gist:358bdee6ed89d1f68fbf19eb8bb7d3e5
Created
September 23, 2026 11:45
-
-
Save mvandermeulen/925b0843dea611a75d525b38af01c3a5 to your computer and use it in GitHub Desktop.
setup external VRFs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Configuration Constants | |
| LOCAL_IP="198.18.0.155" # Host VTEP IP | |
| ANYCAST_SVC_IP="172.27.187.82" # The Shared Service IP | |
| BGP_AS=64512 # Your BGP AS | |
| # 1. Global Kernel Tuning for VRF/Anycast | |
| echo "Tuning kernel for Anycast VRF performance..." | |
| sysctl -w net.ipv4.tcp_l3mdev_accept=1 | |
| sysctl -w net.ipv4.udp_l3mdev_accept=1 | |
| sysctl -w net.ipv4.ip_forward=1 | |
| sysctl -w net.ipv4.conf.all.forwarding=1 | |
| sysctl -w net.ipv4.conf.all.rp_filter=2 | |
| # 2. Base Bridge and VXLAN Setup | |
| echo "Initializing Bridge (br0) and VXLAN (vxlan0)..." | |
| ip link add br0 type bridge vlan_filtering 1 vlan_default_pvid 0 | |
| ip link set br0 addrgenmode none | |
| ip link add vxlan0 type vxlan dstport 4789 local $LOCAL_IP nolearning external vnifilter | |
| ip link set vxlan0 addrgenmode none master br0 | |
| bridge link set dev vxlan0 vlan_tunnel on neigh_suppress on learning off | |
| ip link set br0 up | |
| ip link set vxlan0 up | |
| # Loop to create 72 VRFs with Anycast IPs | |
| for i in $(seq 1 72); do | |
| VRF_NAME="vrf$i" | |
| VLAN_ID=$((1099 + i)) # 1100-1171 | |
| VNI_ID=$((99 + i)) # 100-171 | |
| TABLE_ID=$VLAN_ID | |
| echo "Configuring $VRF_NAME (VNI $VNI_ID) with Anycast IP..." | |
| # Create VRF | |
| ip link add $VRF_NAME type vrf table $TABLE_ID | |
| ip link set $VRF_NAME up | |
| # Bridge/VLAN Mapping | |
| bridge vlan add dev br0 vid $VLAN_ID self | |
| bridge vlan add dev vxlan0 vid $VLAN_ID | |
| bridge vni add dev vxlan0 vni $VNI_ID | |
| bridge vlan add dev vxlan0 vid $VLAN_ID tunnel_info id $VNI_ID | |
| # Create SVI and Assign Anycast IP | |
| SVI_NAME="${VRF_NAME}br" | |
| ip link add $SVI_NAME link br0 type vlan id $VLAN_ID | |
| ip link set $SVI_NAME master $VRF_NAME | |
| # Assign the IP - Linux allows the same IP on different VRF SVIs | |
| ip addr add ${ANYCAST_SVC_IP}/32 dev $SVI_NAME | |
| # ARP Suppression (Prevents IP conflicts on the bridge) | |
| sysctl -w net.ipv4.conf.${SVI_NAME}.arp_ignore=1 | |
| sysctl -w net.ipv4.conf.${SVI_NAME}.arp_announce=2 | |
| ip link set $SVI_NAME up | |
| # Build FRR Config string | |
| FRR_CMDS+=" | |
| configure terminal | |
| vrf $VRF_NAME | |
| vni $VNI_ID | |
| exit-vrf | |
| router bgp $BGP_AS vrf $VRF_NAME | |
| address-family ipv4 unicast | |
| network $ANYCAST_SVC_IP/32 | |
| exit-address-family | |
| address-family l2vpn evpn | |
| advertise ipv4 unicast | |
| exit-address-family | |
| end" | |
| done | |
| # 3. Apply FRR Config | |
| echo "Applying FRR/BGP configurations..." | |
| podman exec frr vtysh -c "$FRR_CMDS" | |
| podman exec frr vtysh -c "write memory" | |
| # 4. Start Nginx on Host Network | |
| echo "Starting Nginx in Host Network mode..." | |
| podman stop shared-webserver 2>/dev/null || true | |
| podman rm shared-webserver 2>/dev/null || true | |
| podman run -d --name shared-webserver \ | |
| --net=host \ | |
| docker.io/library/nginx:latest | |
| echo "Setup Complete. Service $ANYCAST_SVC_IP is now active in 72 VRFs." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment