To find your device’s IP address in the terminal—whether for local network checks, troubleshooting, or remote access—just run a single command: ip a (Linux/macOS) or use ifconfig (older macOS/Linux). On Windows, type ipconfig in CMD. This reveals your local network address, subnet mask, and gateway, which you’ll need to connect to services like local servers or configure firewalls. Skip to the steps below for exact instructions by OS.

What You'll Need

  • Your operating system (Linux, macOS, or Windows)
  • A terminal window (preferably open)—macOS/Linux come with it by default; Windows requires opening Command Prompt (not PowerShell)
  • Basic familiarity with command-line syntax (optional but helpful for reading output)

Step-by-Step

  1. Linux/macOS: Open your terminal application (press Ctrl+Alt+T on Linux or Cmd+Space and type "Terminal" on macOS). Run: ip a (or ifconfig on older systems, but ip a is more modern and preferred). Press Enter.

    Look for lines starting with inet under the "eth0", "wlan0", or interface corresponding to your active network connection (check your Wi-Fi or Ethernet adapter name). This is your IPv4 address—write it down if needed.

    If you see inet6, that’s your IPv6 address (not needed for most tasks).

  2. Windows: Press Win+R, type cmd, and hit Enter. No admin rights needed. Run: ipconfig and press Enter. Look under the Ethernet adapter (wired) or Wireless LAN adapter (Wi-Fi) for the IPv4 address next to IPv4 Address.

    If you don’t see any IPv4 address, your system may be running DHCP, meaning your IP is assigned automatically by your router. No action is needed here.

  3. Troubleshooting Empty Output: If the command returns no results:
    1. Restart your network connection by running sudo systemctl restart NetworkManager (Linux) or restarting your router (hard reset if needed).
    2. Check if you’re on a virtual machine (VM) or container. VMs often use bridged networking; ask your admin for the host’s IP.
    3. If using a VPN, disable it temporarily to isolate the issue.

Common Mistakes

  • Misinterpreting Output: On Linux/macOS, ip a shows multiple interfaces (Wi-Fi, Ethernet, etc.). Focus on the one matching your active connection (e.g., wlp3s0 for Wi-Fi). Windows’ ipconfig clearly labels each adapter.

    Example of correct reading: In Linux, look for 192.168.1.100 under wlp3s0 if you’re on Wi-Fi. In Windows, 192.168.0.5 under Wireless LAN is your IP.

  • Forgetting to Check the Right Adapter: If you’re unsure which interface is active, run: ls /sys/class/net/ (Linux) or check all adapters in Windows. For example, wlp3s0 is often Wi-Fi; eth0 is Ethernet.
  • Running as Root on Linux: To avoid permission errors, run ip a without sudo. If you must, use sudo ip a—but avoid it unless necessary.

Tips

  • Shortcut for Multiple Interfaces: Use ip a | grep "inet " (Linux/macOS) to extract all IPv4 addresses in one go, then filter for your active connection.
  • Windows PowerShell Alternative: Run Get-NetIPAddress -AddressFamily IPv4 in PowerShell for a cleaner output (requires admin privileges).
  • Router-Specific IPs: If you suspect your device’s IP conflicts with a router or printer, use arp -a (Linux/macOS) or arp -a in CMD (Windows) to list active connections. Look for xxx.xxx.xxx.xxx in the MAC address column.
  • Static vs. Dynamic IPs: If your IP changes frequently (common in hotels or shared networks), your router assigns it via DHCP. No action is needed unless you’re building a local server that requires a static IP.

Troubleshooting

  1. Command Returns Nothing: Try restarting your network stack:
    1. sudo systemctl restart systemd-networkd (Linux)
    2. netsh int ip reset (Windows)
    If that fails, check your router’s DHCP server settings for IP conflicts or enable DHCP on your device’s adapter.
  2. IP Conflicts with Router: Your device might be assigned the same IP as the router (e.g., 192.168.1.1). To fix:
    1. Change your device’s IP manually in network settings (Windows: Control Panel > Network and Sharing Center > Change adapter settings > Right-click your adapter > Properties > IPv4 > Use static IP).
    2. Set a range like 192.168.1.100–200, excluding the router’s default.
  3. Using a VPN: VPNs often assign IPs like 10.x.x.x or 172.x.x.x. To bypass, disable the VPN temporarily and run the command again.
  4. No Internet Access After Finding IP: If you’re now unable to browse the web, your router may block access to your device’s IP. Try pinging the gateway (the last IP in your output, e.g., 192.168.1.1) from another device to verify connectivity.

Frequently Asked Questions

Why does my terminal show multiple IPs?

Linux/macOS list all network interfaces (Wi-Fi, Ethernet, loopback, etc.). The first inet line under your active adapter (e.g., wlp3s0) is your public-facing IP. IPv6 addresses appear as inet6—ignore them unless you’re using IPv6 specifically.

How do I find my default gateway (router IP)?

Look for the default via line in the output of ip a (Linux) or the Default Gateways section in ipconfig (Windows). This is your router’s IP—you’ll need it to configure local services.

Can I force a static IP in Linux/macOS?

Yes, edit your network configuration:

  1. On Linux: Edit /etc/network/interfaces or use nmcli (NetworkManager). Example for Wi-Fi: allow-hotplug wlan0 iface wlan0 inet static address 192.168.1.100 netmask 255.255.255.0
  2. On macOS: Go to System Preferences > Network > Wi-Fi > Advanced > TCP/IP > Configure IPv4 > Manual.
Restart your network service after changes.

What if my terminal doesn’t show any active IP?

Your network interface may be down. Try:

  1. Restarting your router.
  2. Reconnecting your device to Wi-Fi/Ethernet.
  3. Running sudo ifdown wlan0 && sudo ifup wlan0 (Linux) to refresh the interface.
If it’s a VM, ask your admin for the host’s network settings.

How do I check if my terminal’s IP is reachable?

Test connectivity with:

  1. ping 8.8.8.8 (Google DNS) in the terminal. If you get replies, your IP is reachable.
  2. On Linux/macOS, use ping -c 4 8.8.8.8 for 4 test packets.
  3. On Windows, use ping -t 8.8.8.8 to test continuously.
A response means your IP is active; no response means it’s offline or blocked.

Can I use this IP for local server hosting?

Yes, but ensure:

  1. Your server’s IP matches the one in ip a (or ipconfig).
  2. The firewall allows traffic on the port you’re using (e.g., sudo ufw allow 80 on Linux).
  3. No network segmentation blocks your device from accessing the server (e.g., VLANs or subnets).
For security, bind your server to 0.0.0.0 (all interfaces) if it should listen externally.