Skip to content

Commit f27b382

Browse files
committed
[WIP] Replace iptables with nft
1 parent 53bfc41 commit f27b382

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

configure-local-networking.sh

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public_ip="10.0.2.1"
2828

2929
# Install iptables.
3030
if $(which dnf >/dev/null 2>&1); then
31-
sudo dnf -y install iptables
31+
sudo dnf -y install nftables
3232
fi
3333

3434
if $(which apt >/dev/null 2>&1); then
@@ -51,22 +51,39 @@ if ! sudo ip l show dummy1 >/dev/null 2>&1; then
5151
sudo ip l set dummy1 master braio
5252
fi
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
5754
sudo 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+
# Create tables if not existing
57+
sudo nft add table inet filter 2>/dev/null
58+
sudo nft add table ip nat 2>/dev/null
59+
60+
# Create chains if not existing
61+
sudo nft add chain inet filter forward '{ type filter hook forward priority 0; }' 2>/dev/null
62+
sudo nft add chain ip nat prerouting '{ type nat hook prerouting priority -100; }' 2>/dev/null
63+
sudo nft add chain ip nat postrouting '{ type nat hook postrouting priority 100; }' 2>/dev/null
64+
65+
# ----- FILTER RULES -----
66+
67+
# Allow established/related traffic: $iface → braio
68+
sudo nft add rule inet filter forward iif "$iface" oif "$braio" ct state established,related accept
69+
70+
# Allow established/related traffic: braio → $iface
71+
sudo nft add rule inet filter forward iif "$braio" oif "$iface" ct state established,related accept
72+
73+
# ----- PORT-SPECIFIC RULES -----
74+
6375
for 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
76+
# Allow NEW TCP connections from $iface → braio on this port
77+
sudo nft add rule inet filter forward \
78+
iif "$iface" oif "$braio" tcp dport "$port" ct state new accept
79+
80+
# DNAT: incoming traffic on $iface to controller VIP
81+
sudo nft add rule ip nat prerouting \
82+
iif "$iface" tcp dport "$port" dnat to "$controller_vip"
83+
84+
# SNAT: return traffic going to controller VIP on braio
85+
sudo nft add rule ip nat postrouting \
86+
oif "$braio" ip daddr "$controller_vip" tcp dport "$port" snat to "$seed_hv_private_ip"
7087
done
7188

7289
# Configure an IP on the 'public' network to allow access to/from the cloud.

0 commit comments

Comments
 (0)