@@ -28,7 +28,7 @@ public_ip="10.0.2.1"
2828
2929# Install iptables.
3030if $( which dnf > /dev/null 2>&1 ) ; then
31- sudo dnf -y install iptables
31+ sudo dnf -y install nftables
3232fi
3333
3434if $( which apt > /dev/null 2>&1 ) ; then
@@ -51,22 +51,41 @@ if ! sudo ip l show dummy1 >/dev/null 2>&1; then
5151 sudo ip l set dummy1 master braio
5252fi
5353
54- # Configure IP routing and NAT to allow the seed VM and overcloud hosts to
55- # route via this route to the outside world.
56- sudo iptables -A POSTROUTING -t nat -o $iface -j MASQUERADE
5754sudo sysctl -w net.ipv4.conf.all.forwarding=1
5855
59- # Configure port forwarding from the hypervisor to the Horizon GUI on the
60- # controller.
61- sudo iptables -A FORWARD -i $iface -o braio -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
62- sudo iptables -A FORWARD -i braio -o $iface -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
56+ sudo nft add rule ip nat postrouting oif " $iface " masquerade
57+
58+ # Create tables if not existing
59+ sudo nft add table inet filter 2> /dev/null
60+ sudo nft add table ip nat 2> /dev/null
61+
62+ # Create chains if not existing
63+ sudo nft add chain inet filter forward ' { type filter hook forward priority 0; }' 2> /dev/null
64+ sudo nft add chain ip nat prerouting ' { type nat hook prerouting priority -100; }' 2> /dev/null
65+ sudo nft add chain ip nat postrouting ' { type nat hook postrouting priority 100; }' 2> /dev/null
66+
67+ # ----- FILTER RULES -----
68+
69+ # Allow established/related traffic: $iface → braio
70+ sudo nft add rule inet filter forward iif " $iface " oif " $braio " ct state established,related accept
71+
72+ # Allow established/related traffic: braio → $iface
73+ sudo nft add rule inet filter forward iif " $braio " oif " $iface " ct state established,related accept
74+
75+ # ----- PORT-SPECIFIC RULES -----
76+
6377for port in $forwarded_ports ; do
64- # Allow new connections.
65- sudo iptables -A FORWARD -i $iface -o braio -p tcp --syn --dport $port -m conntrack --ctstate NEW -j ACCEPT
66- # Destination NAT.
67- sudo iptables -t nat -A PREROUTING -i $iface -p tcp --dport $port -j DNAT --to-destination $controller_vip
68- # Source NAT.
69- sudo iptables -t nat -A POSTROUTING -o braio -p tcp --dport $port -d $controller_vip -j SNAT --to-source $seed_hv_private_ip
78+ # Allow NEW TCP connections from $iface → braio on this port
79+ sudo nft add rule inet filter forward \
80+ iif " $iface " oif " $braio " tcp dport " $port " ct state new accept
81+
82+ # DNAT: incoming traffic on $iface to controller VIP
83+ sudo nft add rule ip nat prerouting \
84+ iif " $iface " tcp dport " $port " dnat to " $controller_vip "
85+
86+ # SNAT: return traffic going to controller VIP on braio
87+ sudo nft add rule ip nat postrouting \
88+ oif " $braio " ip daddr " $controller_vip " tcp dport " $port " snat to " $seed_hv_private_ip "
7089done
7190
7291# Configure an IP on the 'public' network to allow access to/from the cloud.
0 commit comments