Skip to content

Enable internet access for microVM #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
restuhaqza opened this issue Apr 21, 2025 · 2 comments
Open

Enable internet access for microVM #3

restuhaqza opened this issue Apr 21, 2025 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@restuhaqza
Copy link

Hi maintainers,

First of all, thanks for the great work on the firecracker-python project! It really simplifies managing Firecracker microVMs programmatically.

I would like to request a new feature:
the ability to configure and grant internet access (NAT/bridged networking) to a specific microVM instance directly through the firecracker-python API or CLI.

Background

Currently, setting up internet access for Firecracker microVMs typically involves manual configuration of tap devices, bridges, and iptables rules outside of Firecracker. It would be very helpful if firecracker-python could provide higher-level abstractions or helper methods to:

  • Create and attach virtual network interfaces (tap devices) to microVMs.
  • Automatically configure NAT or bridged networking to enable internet connectivity.
  • Manage firewall or forwarding rules required for internet access.

Benefits

  • Easier and more automated microVM networking setup for users.
  • Reduce manual networking configuration errors.
  • Enable more use cases where microVMs need outbound internet access, such as downloading packages or calling external APIs.

Possible Approaches

  • Add network configuration options in the VM configuration objects.
  • Provide helper functions to create tap devices and set up NAT via iptables commands.
  • Integrate basic DHCP or IP assignment helpers.

I would be happy to contribute or discuss design ideas if there's interest.

Thank you!

@restuhaqza
Copy link
Author

Steps to Give Internet Access on Linux

1. Enable IP Forwarding

This allows the Linux system to forward network packets from one interface to another (e.g., from a local network to the internet):

sudo sysctl -w net.ipv4.ip_forward=1

To make this setting permanent (persist after reboot), edit /etc/sysctl.conf and ensure the following line exists:

net.ipv4.ip_forward = 1

Then reload the settings:

sudo sysctl -p

2. Set Up NAT with iptables

Assuming:

  • Your public internet-connected interface is eth0
  • Your local network subnet is 172.16.0.0/24

Run this command to enable masquerading (NAT):

sudo iptables -t nat -A POSTROUTING -s 172.16.0.0/24 -o eth0 -j MASQUERADE

3. Allow Packet Forwarding

Add iptables rules to allow forwarding of packets between your local and public interfaces:

sudo iptables -A FORWARD -i eth0 -o <local_interface> -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i <local_interface> -o eth0 -j ACCEPT

Replace <local_interface> with your local network interface name, for example, tap0, eth1, or br0.


4. Configure Gateway and DNS on Local Devices

  • Set the default gateway on your local devices to the Linux machine’s IP address on the local interface (e.g., 172.16.0.1).
  • Make sure devices use valid DNS servers (e.g., Google DNS 8.8.8.8 or your ISP’s DNS).

5. Verify Connectivity

From a device on the local network, test connectivity by pinging an external IP:

ping 8.8.8.8

You can also try accessing websites to confirm internet access.


Additional Notes

  • If you use firewall management tools like firewalld or ufw, make sure forwarding and NAT rules are properly configured there as well.
  • This setup applies to Linux systems using iptables. For newer systems using nftables, configurations differ.
  • To make your iptables rules permanent, consider saving them with iptables-save or using firewall management utilities.

@myugan myugan changed the title Request Feature: Add Support to Grant Internet Access to Specific MicroVM Instance Enable internet access for microVM Apr 22, 2025
@myugan
Copy link
Owner

myugan commented Apr 22, 2025

@restuhaqza, the feature you requested is already available in the latest version, and it uses nftables instead of iptables. If you prefer to use iptables, I might need to add an option for managing packet filtering based on user choice.

As for configuring DNS, I plan to add a new feature similar to cloud userdata, which will make it easier to configure any settings or applications before the microVM starts. Thank you for raising this concern

@myugan myugan self-assigned this Apr 22, 2025
@myugan myugan added the question Further information is requested label Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants