Connect VMs with virtual networking
Explore virtual switches, NAT, bridge modes, and security groups.
- Choose network modes for VM connectivity and exposure.
VMs connect through virtual NICs to virtual switches. In bridge mode, a VM appears directly on the local network. In NAT mode, VMs use private addresses and share host egress. Security groups or firewall rules control inbound and outbound traffic per VM or subnet.
1rules = [
2 {"port": 22, "action": "allow"},
3 {"port": 80, "action": "allow"},
4 {"port": 3306, "action": "deny"}
5]
6open_ports = [str(rule["port"]) for rule in rules if rule["action"] == "allow"]
7print(",".join(open_ports))22,80
Good VM networking design applies least privilege: open only required ports, segment workloads by function, and monitor east-west traffic. For public services, pair network policy with host hardening and patch discipline.
Key takeaways
Choose network modes for VM connectivity and exposure.
VMs are powerful when automation and guardrails stay strong.
Observe before scaling; recover before incidents become outages.
Lesson quiz
5 questions · pass with 4 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: write Python
Write Python in the editor and run it against sample inputs. Python runs locally in your browser using a WebAssembly runtime.
Evaluate a simple firewall rule
Read an integer port. Allow only 22, 80, or 443. Print allow for those ports; otherwise print deny.
- https
- database
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…