📡 Lab 6 & 7 — Internetworking I & II · Cheat Sheet
ITS352/DES352 · SIIT · Thammasat University
1 · Connecting Devices — Layer & Role Summary
| Device | Physical | Data-Link (MAC) | Network (IP) | Role in networking |
|---|---|---|---|---|
| Hub | ✅ | ❌ | ❌ | Broadcasts signal to all ports — same collision domain |
| Switch | ✅ | ✅ | ❌ | Aggregates devices within the same subnet — reads MAC, delivers to correct port only |
| Router | ✅ | ✅ | ✅ | Connects different networks — reads IP, forwards between subnets |
Key rule: Switch = same network (same subnet). Router = different networks (different subnets).
e.g.192.168.1.xdevices connect through a switch. To reach192.168.2.xyou need a router.
2 · IPv4 Addressing & CIDR
Format: a.b.c.d/n — address is 32 bits = Network prefix (n bits) + Host part (32−n bits)
| /n | Subnet Mask | Total Addresses | Usable Hosts |
|---|---|---|---|
| /16 | 255.255.0.0 | 65536 | 65534 |
| /19 | 255.255.224.0 | 8192 | 8190 |
| /20 | 255.255.240.0 | 4096 | 4094 |
| /21 | 255.255.248.0 | 2048 | 2046 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 ← point-to-point links |
Formula: Usable Hosts = 2^(32−n) − 2
Special Addresses
| Address | Binary pattern | Example (/24) |
|---|---|---|
| Network address | prefix + 00…00 | 192.168.10.0 |
| First host | prefix + 00…01 | 192.168.10.1 |
| Last host | prefix + 11…10 | 192.168.10.254 |
| Broadcast | prefix + 11…11 | 192.168.10.255 |
3 · How to Calculate Network Address (AND method)
Network Address = IP AND Subnet Mask (bitwise AND operation)
Example: 192.168.10.100/26 → subnet mask 255.255.255.192
IP: 192.168.10.100 = 11000000.10101000.00001010.01100100
Mask: 255.255.255.192 = 11111111.11111111.11111111.11000000
AND: = 11000000.10101000.00001010.01000000
= 192.168.10.64 ← Network Address
So for 192.168.10.100/26:
- Network:
192.168.10.64 - First host:
192.168.10.65✅ (quiz answer) - Last host:
192.168.10.126 - Broadcast:
192.168.10.127
Example: 112.1.1.194 mask 255.255.255.224 → CIDR?
255.255.255.224 = 11111111.11111111.11111111.11100000
Count the 1s → 27 ones → /27
So: 112.1.1.194/27
Example: 203.159.10.15/19 → Broadcast?
/19 → mask = 255.255.224.0
IP: 203.159.10.15 = 11001011.10011111.00001010.00001111
Mask: 255.255.224.0 = 11111111.11111111.11100000.00000000
AND: = 11001011.10011111.00000000.00000000
= 203.159.0.0 ← Network Address
Broadcast = Network + flip all host bits to 1:
= 11001011.10011111.00011111.11111111
= 203.159.31.255 ✅
4 · Linux Commands (Complete Reference)
Interface Setup
sudo ifconfig eth1 192.168.10.1/24 # Set IP + subnet mask on eth1
sudo ifconfig eth0 down # Disable interface eth0
ifconfig # View all interfaces & IPsRouting Table
route -n # View routing table (numeric, no DNS lookup)
sudo route add default gw 192.168.10.1 # Add default gateway (for PCs/hosts)
sudo route del default # Delete default gateway
sudo route add -net 192.168.30.0/24 gw 192.168.20.2 # Add static route (for routers)
sudo route del -net 192.168.30.0/24 # Delete static routeIP Forwarding (Real Linux PC router only!)
sudo sysctl -a | grep ip_forward # Check current status → 0=disabled, 1=enabled
sudo sysctl -w net.ipv4.ip_forward=1 # Enable IP forwarding
sudo iptables -P FORWARD ACCEPT # Allow firewall to forward packets⚠️ Real Linux PC (physical lab): both commands required on every router PC.
✅ IMUNES: IP forwarding is already enabled by default on router nodes — you do NOT need to run these commands in IMUNES.
Connectivity
ping 192.168.30.8 # Continuous ping
ping -c 5 192.168.30.8 # Send exactly 5 packets → expect "0% packet loss"5 · Why ip_forward? (The Big Picture)
By default, a Linux PC = end host: it only processes packets addressed to itself — any packet for another IP is silently dropped.
When we use a real Linux PC as a router, we must flip the forwarding flag:
ip_forward = 0 → "I only care about packets for ME" (normal PC)
ip_forward = 1 → "I will also forward packets for OTHER IPs" (router behaviour)
| Environment | ip_forward needed? |
|---|---|
| Physical lab / real Linux PC | ✅ Yes — must run sysctl -w net.ipv4.ip_forward=1 + iptables -P FORWARD ACCEPT |
| IMUNES emulator | ❌ No — router nodes already have forwarding enabled by default |
Why does the lab use PCs instead of real routers?
To teach you that routing tables aren't magic — you must manually add every route yourself. Real routers run protocols (OSPF, BGP) that do this automatically. Here, you learn the manual process.
6 · Routing Table Logic
PC / End Host — only needs default gateway
Destination Gateway Genmask Flags Iface
0.0.0.0 192.168.10.1 0.0.0.0 UG eth1 ← default (catch-all)
192.168.10.0 0.0.0.0 255.255.255.0 U eth1 ← local (auto-added)
- Local network entry (
U) → added automatically when you runifconfig eth1 IP/mask - Default gateway (
UG) → must be added manually withroute add default gw
Router — needs a route for every network
Destination Gateway Genmask Flags Iface
192.168.10.0 0.0.0.0 255.255.255.0 U eth1 ← direct (auto)
192.168.20.0 0.0.0.0 255.255.255.0 U eth2 ← direct (auto)
192.168.30.0 192.168.20.2 255.255.255.0 UG eth2 ← static (manual!)
- Directly connected networks → auto-added when you set the IP
- Remote networks → must add manually:
route add -net <network> gw <next-hop-router>
Routing Table Flags
| Flag | Meaning |
|---|---|
U | Route is Up (active) |
G | Goes through a Gateway |
UG | Up + Gateway (most static routes) |
H | Route to a specific Host |
7 · IMUNES — How to Set Up Networks
IMUNES is a network emulator where you drag-drop virtual nodes and configure them.
Basic Workflow
- Add nodes: drag Router / PC / Hub / Switch from the toolbar
- Connect nodes: use the Link tool — click source node, then destination node
- Start experiment: click the green ▶ Play button — nodes become live
- Open terminal: right-click a node → Shell (or Terminal)
- Configure using the same Linux commands as real machines
Key IMUNES Tips
| Task | How to do it |
|---|---|
| Add a PC | Toolbar → drag host icon onto canvas |
| Add a router (PC acting as router) | Drag host icon — then manually enable ip_forward |
| Add a switch | Toolbar → drag switch icon |
| Add a hub | Toolbar → drag hub icon |
| Connect two nodes | Select Link tool → click node A → click node B |
| Open terminal on a node | Right-click node → Shell |
| Check what interfaces a node has | Run ifconfig in its shell |
| Interfaces in IMUNES | Named eth0, eth1, eth2 — one per link connected |
| Stop/restart experiment | Red ■ Stop → make changes → ▶ Start again |
IMUNES Setup Order (always follow this)
1. Draw logical diagram (on paper) — identify all IPs first
2. Build topology in IMUNES (add nodes + links)
3. Start experiment (▶)
4. On each node: sudo ifconfig eth0 down (if unused)
5. Set IPs: sudo ifconfig eth1 <IP>/<prefix>
6. Add routes: default gw (PCs) or static routes (routers)
[ip_forward NOT needed — IMUNES routers forward by default]
7. Verify: ping -c 5 <destination>
In IMUNES,
eth0is often the management interface — always disable it (ifconfig eth0 down) before setting up lab interfaces, or it may interfere with routing.
8 · Assignment Topologies
Lab 6 — Assignment 3: Two Networks, One Router
[PC A]──eth1──[R1 eth1]──[R1 eth2]──eth1──[PC C]
172.16.101.201/29 .202/29 .13/30 192.168.216.14/30
| Device | NIC | IP | /n | Subnet Mask |
|---|---|---|---|---|
| PC A | eth1 | 172.16.101.201 | /29 | 255.255.255.248 |
| R1 | eth1 | 172.16.101.202 | /29 | |
| R1 | eth2 | 192.168.216.13 | /30 | 255.255.255.252 |
| PC C | eth1 | 192.168.216.14 | /30 |
# PC A
sudo ifconfig eth0 down && sudo ifconfig eth1 172.16.101.201/29
sudo route add default gw 172.16.101.202
# PC C
sudo ifconfig eth0 down && sudo ifconfig eth1 192.168.216.14/30
sudo route add default gw 192.168.216.13
# Router R1
sudo ifconfig eth0 down
sudo ifconfig eth1 172.16.101.202/29
sudo ifconfig eth2 192.168.216.13/30
# ip_forward NOT needed in IMUNES (already enabled)
# (no static routes needed — R1 is directly connected to both networks)Lab 7 — Assignment 1: Three Networks, Two Routers
[PC A]──[R1]──[R2]──[PC B]
Network B (transit)
| Device | NIC | IP |
|---|---|---|
| PC A | eth1 | 192.168.10.8/24 |
| R1 | eth1 | 192.168.10.1/24 |
| R1 | eth2 | 192.168.20.1/24 |
| R2 | eth2 | 192.168.20.2/24 |
| R2 | eth1 | 192.168.30.1/24 |
| PC B | eth1 | 192.168.30.8/24 |
# PC A
sudo ifconfig eth0 down && sudo ifconfig eth1 192.168.10.8/24
sudo route add default gw 192.168.10.1
# PC B
sudo ifconfig eth0 down && sudo ifconfig eth1 192.168.30.8/24
sudo route add default gw 192.168.30.1
# Router R1
sudo ifconfig eth0 down
sudo ifconfig eth1 192.168.10.1/24 && sudo ifconfig eth2 192.168.20.1/24
# ip_forward NOT needed in IMUNES (already enabled)
sudo route add -net 192.168.30.0/24 gw 192.168.20.2 # ← manual: R1 can't see Net C directly
# Router R2
sudo ifconfig eth0 down
sudo ifconfig eth1 192.168.30.1/24 && sudo ifconfig eth2 192.168.20.2/24
# ip_forward NOT needed in IMUNES (already enabled)
sudo route add -net 192.168.10.0/24 gw 192.168.20.1 # ← manual: R2 can't see Net A directlyRouting table logic for R1:
| Destination | Gateway | How added |
|---|---|---|
192.168.10.0/24 | 0.0.0.0 | Auto (eth1 connected) |
192.168.20.0/24 | 0.0.0.0 | Auto (eth2 connected) |
192.168.30.0/24 | 192.168.20.2 | Manual — R1 not connected to Net C |
Lab 7 — Assignment 2: Seven Networks, Four Routers
A(172.16.101.200/29)──R1──C(192.168.66.0/24)──R2──D(192.168.88.0/24)──R3──E(68.66.11.80/29)──R4──G(16.18.11.64/29)
B(192.168.216.12/30)─┘ └──F(211.60.36.16/28)
Key routing rule: Each router needs static routes for every network it cannot directly reach, forwarding toward the next router in that direction.
| Router | Direct networks | Static routes needed for |
|---|---|---|
| R1 | A, B, C | D, E, F, G → all via R2 (192.168.66.2) |
| R2 | C, D | A, B → via R1; E, F, G → via R3 |
| R3 | D, E | A, B, C → via R2; F, G → via R4 |
| R4 | E, F, G | A, B, C, D → all via R3 (68.66.11.81) |
At R2 — which networks need static routes? → A, B, E, F, G (quiz answer)
9 · Quiz Question Patterns (Labs 6 & 7)
| Question type | Key answer |
|---|---|
First host of 192.168.10.100/26? | Network = 192.168.10.64 → first host = 192.168.10.65 |
| Enable IP forwarding command? | sudo sysctl -w net.ipv4.ip_forward=1 |
112.1.1.194 mask 255.255.255.224 in CIDR? | Count mask bits: 27 ones → 112.1.1.194/27 |
| Delete default gateway command? | sudo route del default |
| Gateway for PC A in 3-network topology? | R1's IP on PC A's side (e.g. 192.168.10.1/24) |
Delete static route to 192.168.30.0/24? | sudo route del -net 192.168.30.0/24 |
Broadcast of 203.159.10.15/19? | Network 203.159.0.0 → broadcast 203.159.31.255 |
| Which networks need static routes at R2 (7-network)? | A, B, E, F, G (not C, D — directly connected) |
| How many subnets in a diagram? | Count network segments separated by routers |
| Device checking MAC at OSI Layer 2? | Switch |
route -n flag for "goes via gateway"? | G (so UG = up + via gateway) |
Routing Table Explanation (2-point answer template)
a) The routing table tells a router/PC where to forward each packet based on destination IP.
b) Longest-prefix match: if192.168.1.50matches both/24and/16, the/24entry wins (more specific).
c) Default route0.0.0.0/0(flagUG) matches any destination with no more-specific entry — last resort gateway.
d) Linux command:route -n(the-nflag shows numeric IPs, no DNS lookup — faster and clearer).
10 · Common Mistakes to Avoid
| Mistake | Fix |
|---|---|
| Forgot to disable eth0 | Always run sudo ifconfig eth0 down first |
| PC can ping router but not far PC | Far router missing static route back |
| Router not forwarding | Missing ip_forward=1 or iptables -P FORWARD ACCEPT |
| Wrong gateway on PC | Gateway must be the router's IP on the same subnet as the PC |
| Static route wrong direction | Route to Net X must go via the router toward Net X |
route -n shows no default | Forgot sudo route add default gw <IP> on the PC |