ShareYourGroupShareYourGroupIP and Internet

How to find your IP address on Mac and Linux

On a Mac the address is two clicks into System Settings. On Linux one short command shows it.

Public or private?

These steps find the private address of the computer inside your home or office network. The public address, the one websites see, is at the top of our home page.

Mac: in System Settings (macOS Ventura 13 and later)

  1. Open the Apple menu and choose System Settings.
  2. Click Network in the side bar.
  3. Click Wi-Fi (or Ethernet for a cable).
  4. Click Details... beside the network you are connected to. The IP address and Router are shown. The TCP/IP tab in the same window lists the subnet mask and the IPv6 address, and the Hardware tab shows the MAC address.

On older versions of macOS the place is System Preferences › Network: select the connection on the left and the address is shown on the right.

Mac: in Terminal

Open Terminal (press Command and Space, type Terminal, press Enter) and type:

ipconfig getifaddr en0

It prints the address of the first network port, which is Wi-Fi on most Mac laptops. If it prints nothing, try en1. To see the router's address:

route -n get default

Read the line that begins gateway:.

Linux: the ip command

Open a terminal and type:

ip addr

Each network port is listed with a name such as wlan0, wlp2s0 (Wi-Fi) or eth0, enp3s0 (cable). Under the one in use, the line beginning inet holds the IPv4 address, for example inet 192.168.1.23/24. The /24 after it is the size of the network; our subnet calculator turns it into a mask and a range. Lines beginning inet6 are the IPv6 addresses. The line beginning link/ether is the MAC address. The port named lo with 127.0.0.1 is the computer talking to itself and can be ignored.

A shorter answer:

hostname -I

This prints only the addresses, with nothing else. For the router's address:

ip route

The line beginning default via gives the router (gateway) address.

On desktop Linux you can also use the mouse: open Settings, choose Wi-Fi or Network, and click the gear icon beside the connection. The details tab lists the IPv4 address, IPv6 address, hardware address, default route and DNS.

Reading the result

You seeIt means
192.168.x.x, 10.x.x.x, 172.16 to 172.31.x.xA normal private address
169.254.x.xNo address was given by the router. Reconnect or restart the router
127.0.0.1 onlyNo network connection at all, only the loopback
An address that matches our home pageThe computer is directly on the internet, with no router in between. Make sure its firewall is on

Renewing the address

On a Mac: in the TCP/IP tab mentioned above, click Renew DHCP Lease. On most Linux desktops: switch the connection off and on again from the network menu. Both ask the router for a fresh address and are safe to do.

Why does the old ifconfig command not work on my Linux computer?

Many modern Linux systems no longer install it by default. The ip command replaced it: ip addr shows addresses and ip route shows the route.

What is the difference between en0 and en1 on a Mac?

They are the names of network ports. On laptops en0 is normally Wi-Fi. On desktops with a network socket, en0 is often the cable port and en1 the Wi-Fi.

Can a computer have several IP addresses?

Yes. Each network port has its own, and one port can have an IPv4 address and several IPv6 addresses at once.