Skip to content

Commit 555563b

Browse files
committed
fix: properly setup outbound network connectivity in getting started
the getting started guide was hardcoding eth0 as the network interface on the host to route outbound microvm network traffic to. However, on EC2 instances (and my laptop), that's wrong, because its not called eth0. So instead dynamically determine the hopefully correct network interface on the host. Fixes: firecracker-microvm#4930 Suggested-by: Pablo Barbáchano <[email protected]> Signed-off-by: Patrick Roy <[email protected]>
1 parent 4c33853 commit 555563b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/getting-started.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,16 @@ sudo ip link set dev "$TAP_DEV" up
197197

198198
# Enable ip forwarding
199199
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
200+
sudo iptables -P FORWARD ACCEPT
200201

201-
HOST_IFACE="eth0"
202+
# This tries to determine the name of the host network interface to forward
203+
# VM's outbound network traffic through. If outbound traffic doesn't work,
204+
# double check this returns the correct interface!
205+
HOST_IFACE=$(ip -j route list default |jq -r '.[0].dev')
202206

203207
# Set up microVM internet access
204208
sudo iptables -t nat -D POSTROUTING -o "$HOST_IFACE" -j MASQUERADE || true
205-
sudo iptables -D FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT \
206-
|| true
207-
sudo iptables -D FORWARD -i "$TAP_DEV" -o "$HOST_IFACE" -j ACCEPT || true
208209
sudo iptables -t nat -A POSTROUTING -o "$HOST_IFACE" -j MASQUERADE
209-
sudo iptables -I FORWARD 1 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
210-
sudo iptables -I FORWARD 1 -i "$TAP_DEV" -o "$HOST_IFACE" -j ACCEPT
211210

212211
API_SOCKET="/tmp/firecracker.socket"
213212
LOGFILE="./firecracker.log"

0 commit comments

Comments
 (0)