Last active
January 1, 2024 12:38
-
-
Save psolru/3e36f63cb34092402d8958b4d269c95a to your computer and use it in GitHub Desktop.
Add network bridge to Hetzner VSwitch public subnet (VLAN) via NetworkManager on CentOS 8
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
# Add your real IPv4 subnet settings here | |
IPV4=X.X.X.X | |
CIDR=X.X.X.X/28 | |
GATEWAY=X.X.X.X | |
DNS=1.1.1.1 | |
# Add your real Interface settings here | |
INTERFACE_NAME="enp2s0" | |
VLAN_ID=4000 | |
VLAN_INTERFACE_NAME="$INTERFACE_NAME.$VLAN_ID" | |
VLAN_BRIDGE_NAME="br$VLAN_ID" | |
# Add vswitch routing table | |
echo "1 vswitch" >> /etc/iproute2/rt_tables | |
# Add bridge | |
nmcli c a type bridge con-name "$VLAN_BRIDGE_NAME" ifname "$VLAN_BRIDGE_NAME" ip4 "$CIDR" | |
# Add VLAN interface | |
nmcli c a type vlan con-name "$VLAN_INTERFACE_NAME" ifname "$VLAN_INTERFACE_NAME" dev enp2s0 id $VLAN_ID master "$VLAN_BRIDGE_NAME" slave-type bridge | |
# Set MTU of VLAN interface | |
nmcli c m "$VLAN_INTERFACE_NAME" 802-3-ethernet.mtu 1400 | |
# Add IP/Gateway to bridge | |
nmcli c m "$VLAN_BRIDGE_NAME" ipv4.addresses "$CIDR" | |
# Add DNS to bridge | |
nmcli c m "$VLAN_BRIDGE_NAME" ipv4.dns "$DNS" | |
# Add default route to bridge in table "1" | |
nmcli c m "$VLAN_BRIDGE_NAME" ipv4.routes "0.0.0.0/0 $GATEWAY table=1" | |
# Add routing rules for $IPV4 | |
# ATTENTION: MAYBE YOU HAVE TO ADJUST THE PRIORITY. I HAD SOME PROBLEMS WHEN IT ALREADY EXISTS... | |
nmcli c m "$VLAN_BRIDGE_NAME" ipv4.routing-rules "priority 32765 from $IPV4 table 1" | |
nmcli c m "$VLAN_BRIDGE_NAME" +ipv4.routing-rules "priority 32764 from all to $IPV4 table 1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment