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
-
Linux/macOS:
Open your terminal application (press
Ctrl+Alt+Ton Linux orCmd+Spaceand type "Terminal" on macOS). Run:ip a(orifconfigon older systems, butip ais more modern and preferred). PressEnter.Look for lines starting with
inetunder 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). -
Windows:
Press
Win+R, typecmd, and hitEnter. No admin rights needed. Run:ipconfigand pressEnter. Look under theEthernet adapter(wired) orWireless LAN adapter(Wi-Fi) for the IPv4 address next toIPv4 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.
-
Troubleshooting Empty Output:
If the command returns no results:
- Restart your network connection by running
sudo systemctl restart NetworkManager(Linux) or restarting your router (hard reset if needed). - Check if you’re on a virtual machine (VM) or container. VMs often use bridged networking; ask your admin for the host’s IP.
- If using a VPN, disable it temporarily to isolate the issue.
- Restart your network connection by running
Common Mistakes
-
Misinterpreting Output:
On Linux/macOS,
ip ashows multiple interfaces (Wi-Fi, Ethernet, etc.). Focus on the one matching your active connection (e.g.,wlp3s0for Wi-Fi). Windows’ipconfigclearly labels each adapter.Example of correct reading: In Linux, look for
192.168.1.100underwlp3s0if you’re on Wi-Fi. In Windows,192.168.0.5underWireless LANis 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,wlp3s0is often Wi-Fi;eth0is Ethernet. -
Running as Root on Linux:
To avoid permission errors, run
ip awithout sudo. If you must, usesudo 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 IPv4in 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) orarp -ain CMD (Windows) to list active connections. Look forxxx.xxx.xxx.xxxin 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
-
Command Returns Nothing:
Try restarting your network stack:
sudo systemctl restart systemd-networkd(Linux)netsh int ip reset(Windows)
-
IP Conflicts with Router:
Your device might be assigned the same IP as the router (e.g., 192.168.1.1). To fix:
- 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). - Set a range like 192.168.1.100–200, excluding the router’s default.
- Change your device’s IP manually in network settings (Windows:
- 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.
- 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:
- On Linux: Edit
/etc/network/interfacesor usenmcli(NetworkManager). Example for Wi-Fi:allow-hotplug wlan0 iface wlan0 inet static address 192.168.1.100 netmask 255.255.255.0 - On macOS: Go to
System Preferences > Network > Wi-Fi > Advanced > TCP/IP > Configure IPv4 > Manual.
What if my terminal doesn’t show any active IP?
Your network interface may be down. Try:
- Restarting your router.
- Reconnecting your device to Wi-Fi/Ethernet.
- Running
sudo ifdown wlan0 && sudo ifup wlan0(Linux) to refresh the interface.
How do I check if my terminal’s IP is reachable?
Test connectivity with:
ping 8.8.8.8(Google DNS) in the terminal. If you get replies, your IP is reachable.- On Linux/macOS, use
ping -c 4 8.8.8.8for 4 test packets. - On Windows, use
ping -t 8.8.8.8to test continuously.
Can I use this IP for local server hosting?
Yes, but ensure:
- Your server’s IP matches the one in
ip a(oripconfig). - The firewall allows traffic on the port you’re using (e.g.,
sudo ufw allow 80on Linux). - No network segmentation blocks your device from accessing the server (e.g., VLANs or subnets).
0.0.0.0 (all interfaces) if it should listen externally.