Ashari Abidin's Developer Docs

Connect from Other Computer using Hostname

⚡ Ubuntu Remote Access · No Static IP

SSH · VS Code Remote · RDP · VNC · Browser Services
Only hostname.local — no router config, no IP chasing.
🎯 GOAL: Remotely access Ubuntu server from any laptop/PC via SSH, VSCode, RDP, VNC, browser services using only hostname.localstatic IP, DHCP reservations, router config → NOT REQUIRED. Works with dynamic IP, survives reboots.

🏗️ Architecture

✅ What will be used

  • normal DHCP (automatic)
  • hostname (machine identity)
  • mDNS / Avahi (Zero-configuration)
  • hostname.local resolution

🚫 What will NOT be used

  • static IP configuration
  • DHCP reservation (router)
  • any router port forwarding / config
  • remembering IP addresses

📋 Complete Setup Steps

All steps performed on your Ubuntu server (22.04 / 24.04+). Replace server-hp with your desired hostname.

1Restore network to normal DHCP

Remove any static IP leftovers. Identify your active connection and reset to DHCP.

# Show available connections & find active WiFi/Ethernet name (e.g., "MyWifi" or "MyLab")
nmcli connection show

# Modify your connection to use DHCP (auto)
nmcli connection modify "MyWifi" ipv4.method auto

# Clear any static addresses, gateway, DNS
nmcli connection modify "MyWifi" ipv4.addresses ""
nmcli connection modify "MyWifi" ipv4.gateway ""
nmcli connection modify "MyWifi" ipv4.dns ""

# Restart NetworkManager and reconnect
sudo systemctl restart NetworkManager
nmcli connection down "MyWifi" && nmcli connection up "MyWifi"
🔁 If you don't remember your connection name, use nmcli connection show and replace MyWifi accordingly.
2If DHCP still fails – fresh start

Delete the old WiFi profile completely and reconnect via GUI (clean DHCP).

nmcli connection delete "MyWifi"
sudo systemctl restart NetworkManager
# Now reconnect via Ubuntu GUI: click WiFi → select network → enter password
# DO NOT set static IP anywhere.
3Verify internet & dynamic IP
ip addr # Look for "inet 192.168.x.x" or 10.x.x.x
ip route # Should show default via gateway (e.g., 192.168.1.1)
ping google.com -c 4
✔️ DHCP works if you get an IP and internet. No static reservation required.
4Set custom hostname (e.g., server-hp)
# Check current
hostname

# Set new hostname
sudo hostnamectl set-hostname server-hp

# Verify
hostnamectl
5Update /etc/hosts for local resolution
sudo nano /etc/hosts
# Find line: 127.0.1.1 old-hostname
# Replace with: 127.0.1.1 server-hp

# Example /etc/hosts entry:
127.0.0.1 localhost
127.0.1.1 server-hp
6Install & enable Avahi (mDNS) – 🔥 critical for .local
sudo apt update
sudo apt install avahi-daemon -y
sudo systemctl enable avahi-daemon
sudo systemctl start avahi-daemon
systemctl status avahi-daemon # must show active (running)
✨ Avahi broadcasts your hostname as server-hp.local on the local network. No router changes needed.
7Test .local resolution on the server
ping server-hp.local -c 3
# Should resolve to your current DHCP IP (e.g., 192.168.1.112)
❗ If ping fails, restart avahi: sudo systemctl restart avahi-daemon and ensure hostname is correctly set.
8🌍 Remote access using hostname.local

From any laptop/computer on the same local network, reach your Ubuntu server using server-hp.local (replace with your actual hostname).

🔐 SSH (secure shell)
ssh username@server-hp.local
💡 Ensure openssh-server installed: sudo apt install openssh-server -y
🖥️ VS Code Remote - SSH
Add to your SSH config (~/.ssh/config on client):
Host myserver
 HostName server-hp.local
 User your_username
Then connect: Remote-SSH: Connect to Host → myserver
🌐 Browser / Local services
Access web apps: http://server-hp.local:8080 (or any port like 3000, 5000). Works with Jupyter, Flask, Node, etc.
🖼️ RDP (Remote Desktop) & VNC
RDP: Install xrdp on server (sudo apt install xrdp -y). Connect using Remmina or Windows Remote Desktop → server-hp.local.
VNC: Install TigerVNC server, then VNC Viewer → server-hp.local:5901.
🧠 No IP tracking – just use the .local address.
✅ All services (SSH, RDP, VNC) will work via mDNS. The server IP can change tomorrow — hostname.local always resolves.
9🪟 Windows clients: resolve .local addresses

Windows does not natively support mDNS. Install Bonjour Print Services (Apple) or iTunes (includes Bonjour).

👉 Download: Bonjour Print Services for Windows (official Apple)
After install, open cmd and test: ping server-hp.local
Alternatively, use Linux/macOS clients — .local works out of the box.
10🛡️ Allow mDNS through firewall (if UFW enabled)
sudo ufw allow 5353/udp comment 'mDNS Avahi'
sudo ufw reload

Also open services ports if needed (SSH:22, RDP:3389, VNC:5900+, etc).


🎉 FINAL RESULT

✅ Server stays on DHCP · No static IP · No router configuration
IP can change daily/hourly · Remote access remains flawless using

server-hp.local

📡 SSH → ssh user@server-hp.local 🖥️ RDP → server-hp.local:3389 🌍 Browser → http://server-hp.local:PORT

🧪 Verification & advanced notes

🔍 Verify mDNS from another Linux/macOS device

ping server-hp.local
avahi-resolve -n server-hp.local # if avahi tools installed

📌 Hostname convention:

Use lowercase, no underscores. Example: server-nuc, ubuntu-workstation. Access via server-nuc.local.

🔥 What if .local stops working after network changes?

Restart avahi: sudo systemctl restart avahi-daemon. Also ensure no firewall blocks UDP 5353 multicast.

🔄 Reboot resistance

After completing steps 1-6, everything persists. No matter how many times your router renews IP, .local name resolution works across the LAN.

📎 Quick command recap (server side)

# Set hostname & Avahi (core)
sudo hostnamectl set-hostname server-hp
echo "127.0.1.1 server-hp" | sudo tee -a /etc/hosts
sudo apt install avahi-daemon -y
sudo systemctl enable --now avahi-daemon

# Ensure DHCP mode
nmcli connection modify "YourWifi" ipv4.method auto
sudo systemctl restart NetworkManager
⭐ After setup, from any remote machine: ssh username@server-hp.local — magic!
🔥 Red-powered guide · No static IP, No router configuration · Only mDNS/Avahi & hostname.local
Allows SSH, VSCode Remote, RDP, VNC, HTTP services — pure zero-conf networking.
Back