Lab 6-7

Updated 4 Oct 2026

📡 Lab 6 & 7 — Internetworking I & II · Cheat Sheet

ITS352/DES352 · SIIT · Thammasat University


1 · Connecting Devices — Layer & Role Summary

DevicePhysicalData-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.x devices connect through a switch. To reach 192.168.2.x you 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)

/nSubnet MaskTotal AddressesUsable Hosts
/16255.255.0.06553665534
/19255.255.224.081928190
/20255.255.240.040964094
/21255.255.248.020482046
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242 ← point-to-point links

Formula: Usable Hosts = 2^(32−n) − 2

Special Addresses

AddressBinary patternExample (/24)
Network addressprefix + 00…00192.168.10.0
First hostprefix + 00…01192.168.10.1
Last hostprefix + 11…10192.168.10.254
Broadcastprefix + 11…11192.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 & IPs

Routing 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 route

IP 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)
Environmentip_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 run ifconfig eth1 IP/mask
  • Default gateway (UG) → must be added manually with route 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

FlagMeaning
URoute is Up (active)
GGoes through a Gateway
UGUp + Gateway (most static routes)
HRoute 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

  1. Add nodes: drag Router / PC / Hub / Switch from the toolbar
  2. Connect nodes: use the Link tool — click source node, then destination node
  3. Start experiment: click the green ▶ Play button — nodes become live
  4. Open terminal: right-click a node → Shell (or Terminal)
  5. Configure using the same Linux commands as real machines

Key IMUNES Tips

TaskHow to do it
Add a PCToolbar → drag host icon onto canvas
Add a router (PC acting as router)Drag host icon — then manually enable ip_forward
Add a switchToolbar → drag switch icon
Add a hubToolbar → drag hub icon
Connect two nodesSelect Link tool → click node A → click node B
Open terminal on a nodeRight-click node → Shell
Check what interfaces a node hasRun ifconfig in its shell
Interfaces in IMUNESNamed eth0, eth1, eth2 — one per link connected
Stop/restart experimentRed ■ 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, eth0 is 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
DeviceNICIP/nSubnet Mask
PC Aeth1172.16.101.201/29255.255.255.248
R1eth1172.16.101.202/29
R1eth2192.168.216.13/30255.255.255.252
PC Ceth1192.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)
DeviceNICIP
PC Aeth1192.168.10.8/24
R1eth1192.168.10.1/24
R1eth2192.168.20.1/24
R2eth2192.168.20.2/24
R2eth1192.168.30.1/24
PC Beth1192.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 directly

Routing table logic for R1:

DestinationGatewayHow added
192.168.10.0/240.0.0.0Auto (eth1 connected)
192.168.20.0/240.0.0.0Auto (eth2 connected)
192.168.30.0/24192.168.20.2Manual — 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.

RouterDirect networksStatic routes needed for
R1A, B, CD, E, F, G → all via R2 (192.168.66.2)
R2C, DA, B → via R1; E, F, G → via R3
R3D, EA, B, C → via R2; F, G → via R4
R4E, F, GA, 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 typeKey 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: if 192.168.1.50 matches both /24 and /16, the /24 entry wins (more specific).
c) Default route 0.0.0.0/0 (flag UG) matches any destination with no more-specific entry — last resort gateway.
d) Linux command: route -n (the -n flag shows numeric IPs, no DNS lookup — faster and clearer).


10 · Common Mistakes to Avoid

MistakeFix
Forgot to disable eth0Always run sudo ifconfig eth0 down first
PC can ping router but not far PCFar router missing static route back
Router not forwardingMissing ip_forward=1 or iptables -P FORWARD ACCEPT
Wrong gateway on PCGateway must be the router's IP on the same subnet as the PC
Static route wrong directionRoute to Net X must go via the router toward Net X
route -n shows no defaultForgot sudo route add default gw <IP> on the PC