🌐 Network Interfaces & Port Binding

May 17, 2026

💡 Network Interface ဆိုတာ computer ရဲ့ network card တွေပါ — physical (ethernet, wifi) နဲ့ virtual (loopback, docker, VPN) နှစ်မျိုးရှိတယ်။

Network Interface ဆိုတာဘာလဲ?

Network Interface က computer မှာ network ကို listen လုပ်နေတဲ့ connection point တစ်ခုပါ။ Hardware (physical card) ဖြစ်နိုင်တယ်၊ software (virtual) လဲ ဖြစ်နိုင်တယ်။ မင်း နားလည်ထားတာ မှန်ပါတယ်! Network card က တစ်ခုထက်ပိုနိုင်တယ် — cable သုံးတာ တစ်ခု၊ wifi သုံးတာ တစ်ခု၊ VM/container တွေမှာ virtual interface တွေ ထပ်ရှိတယ်။

Network Interface အမျိုးအစားများ

1️⃣ Physical Interfaces (Hardware)

Computer ရဲ့ တကယ့် network card တွေ:

2️⃣ Virtual Interfaces (Software)

Software က ဖန်တီးထားတဲ့ virtual network cards:


Network Interfaces ကြည့်နည်း

သင့် computer မှာ ဘာ network interface တွေ ရှိလဲ ကြည့်ရန်:

# Method 1: ip command (modern)
ip addr show
ip a  # short form

# Method 2: ifconfig (traditional)
ifconfig
ifconfig -a  # show all (including down)

# Method 3: nmcli (NetworkManager)
nmcli device status

ဥပမာ Output

1: lo: <LOOPBACK,UP>
    inet 127.0.0.1/8 scope host lo

2: eth0: <BROADCAST,MULTICAST,UP>
    inet 192.168.1.100/24

3: wlan0: <BROADCAST,MULTICAST,UP>
    inet 192.168.1.101/24

4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP>
    inet 172.17.0.1/16

Port Binding နဿ့ Interfaces

Port binding က "ဘယ် interface(s) ပေါ်မှာ listen လုပ်မလဲ" ဆိုတာကို ထိန်းချုပ်တယ်။

Scenario 1: Specific Interface (127.0.0.1)

nerdctl run -p 127.0.0.1:8080:80 nginx

Port 8080 ကို loopback interface (127.0.0.1) တစ်ခုတည်းမှာ bind လုပ်တယ်။ ✅ ခေါ်လို့ရတယ်:

Scenario 2: All Interfaces (0.0.0.0)

nerdctl run -p 8080:80 nginx
# Same as: -p 0.0.0.0:8080:80

Port 8080 ကို network interface အားလုံးမှာ bind လုပ်တယ်။ ✅ ခေါ်လို့ရတဲ့ နေရာအားလုံး:


localhost ဆိုတာဘာလဲ?

🔍 localhost သည် hostname တစ်ခုဖြစ်ပြီး 127.0.0.1 IP address ကို ညွှန်းတယ်။ /etc/hosts ဖိုင်မှာ define လုပ်ထားတယ်။

/etc/hosts ဖိုင်

# /etc/hosts
127.0.0.1    localhost
::1          localhost ip6-localhost ip6-loopback

ဒီကြောင့် browser/terminal မှာ "localhost" လို့ ရိုက်လိုက်ရင် automatically 127.0.0.1 ကို resolve လုပ်တယ်။

localhost က ဘာကြောင့် နှစ်ခုလုံးမှာ အလုပ်လုပ်လဲ?

  1. Browser က "localhost" ကို 127.0.0.1 အဖြစ် resolve လုပ်တယ်
  2. OS က 127.0.0.1:8080 ကို lo interface မှာ ရှာတယ်
  3. Case 1 (127.0.0.1:8080 bind): lo interface မှာ တိုက်ရိုက် bind လုပ်ထားလို့ အလုပ်လုပ်တယ်
  4. Case 2 (0.0.0.0:8080 bind): interface အားလုံးမှာ bind လုပ်ထားတယ် → lo လဲ ပါတယ် → အလုပ်လုပ်တယ်

⚡ 0.0.0.0 က special address ပါ — "interface အားလုံး" ကို ဆိုလိုတယ်။ lo (127.0.0.1) + eth0 (192.168.1.100) + wlan0 (192.168.1.101) + docker0 + အားလုံး!


လက်တွေ့ ဥပမာ

မင့် computer IP addresses:

Test 1: 127.0.0.1 Only Binding

# Run container
nerdctl run -d -p 127.0.0.1:8080:80 nginx

# Test from same machine
curl http://localhost:8080        # ✅ Works
curl http://127.0.0.1:8080        # ✅ Works
curl http://192.168.1.100:8080    # ❌ Connection refused

# Test from phone (same WiFi)
curl http://192.168.1.100:8080    # ❌ Connection refused

Test 2: All Interfaces Binding

# Run container
nerdctl run -d -p 8080:80 nginx

# Test from same machine
curl http://localhost:8080        # ✅ Works
curl http://127.0.0.1:8080        # ✅ Works
curl http://192.168.1.100:8080    # ✅ Works
curl http://192.168.1.101:8080    # ✅ Works

# Test from phone (same WiFi)
curl http://192.168.1.100:8080    # ✅ Works!

မှတ်ထားရမယ့် Key Points ⭐

✅ မင့် နားလည်မှု မှန်ပါတယ်! Network card က တစ်ခုထက်ပိုနိုင်တယ် — physical (cable, wifi) + virtual (docker, VM, VPN)။ Port binding က "ဘယ် interface(s) မှာ listen မလဲ" ဆုံးဖြတ်ပေးတာပါ။