A Guide to ipconfig on Mac

A Guide to ipconfig on Mac

What is ipconfig

The ipconfig command-line utility in MacOS helps users administer and control the Bootstrap Protocol and DHCP client from the comand line.

This command can be used to configure the network interface settings of an Ethernet or Wi-Fi connection. It can also be used to display the IP address, subnet mask, and router address of the current connection.

Note that if you are looking for more direct control over network interfaces, such as configuring static IP addresses, consider using the ifconfig utiliy.

According to the System Manager’s Manual:

ipconfig is a utility that communicates with the IPConfiguration agent to retrieve and set IP configuration parameters. It should only be used in a test and debug context. Using it for any other purpose is strongly discouraged.

The ipconfig command first appeared in Mac OS X Version 10.0 Public Beta.

What is the IPConfiguration agent

The System Managers manual also helps with defining what the IPConfiguration agent is:

The IPConfiguration agent is responsible for configuring and managing the IPv4 and IPv6 addresses on direct, connectionless interfaces such as ethernet and Wi-Fi. The IPConfiguration agent is a program bundle that is loaded and executed by the configd(8) process.

The IPConfiguration agent implements the client side of the DHCP and BOOTP protocols described in RFC951, RFC1542, RFC2131, and RFC2132. It also assigns and maintains static IP addresses. It may also allocate and assign a link-local IP address if DHCP fails to acquire an IP address.

The IPConfiguration agent also enables and controls the IPv6 SLAAC (RFC 4862) state in the kernel, and also handles statically configured IPv6 addresses. The agent implements the client side of the DHCPv6 protocol (RFC 3315) and supports both stateless and stateful operation.

In all cases, the IPConfiguration agent performs IP address conflict detection before assigning an IP address to an interface.

Sub-commands

The ipconfig utility is a very powerful command. It’s abilities are broken down into these subcommands:

  • waitall - Blocks until all network services have completed configuring, or have timed out in the process of configuring. This is only useful for initial system start-up time synchronization for legacy network services that are incapable of dealing with dynamic network configuration changes.
  • getifaddr interface-name - Prints to standard output the IP address for the first network service associated with the given interface. The output will be empty if no service is currently configured or active on the interface.
  • ifcount - Prints the number of interfaces that IPConfiguration is capable of configuring. The value that’s printed will not change unless relevant network interfaces are either added to or removed from the system.
  • getoption interface-name (option-name | option-code) - Prints the BOOTP/DHCP option with the given name or option code integer value. See bootpd(8) for option code names. If an option has multiple values e.g. domain_name_server, only the first value is printed.
  • getpacket interface-name - Prints to standard output the DHCP/BOOTP packet that the client accepted from the DHCP/BOOTP server. This command is useful to check what the server provided, and whether the values are sensible. This command outputs nothing if DHCP/BOOTP is not active on the interface, or the attempt to acquire an IP address was unsuccessful.
  • getv6packet interface-name - Prints to standard output the latest DHCPv6 packet that the client accepted from the DHCPv6 server. In the case of stateful DHCPv6, it corresponds to the last packet from the server that contained addressing information. This command is useful to check what the server provided, and whether the values are sensible. This command outputs nothing if DHCPv6 is not active on the interface.
  • set interface-name (NONE | DHCP | BOOTP | MANUAL | INFORM | NONE-V6 | AUTOMATIC-V6 | MANUAL-V6 | 6TO4) - Sets the interface to have a new temporary network service of the given type. Any existing services on the interface for the particular protocol (IPv4 or IPv6) are first de-configured before the new service is instantiated. Read more about the possible options in the manual here
  • setverbose level - Sets verbose mode logging in the IPConfiguration agent. Specify a level value of 0 to disable verbose logging, the default. Specify a value of 1 to enable verbose logging.

Useful Examples

How to find your ip address on Mac using ipconfig

ipconfig can easily retrieve your ip address on Mac, much faster than navigating through your system preferences. To print your ip address, enter in your terminal:

$ ipconfig getifaddr en0

if you remember from earlier, getifaddr is an option to print the IP address for the first network service associated with the given interface. In this case, the interface is en0, the physical network interface that refers to your wifi. You can replace en0 with any interface you would like.

How to display the DNS Server

A DNS server is a network server that stores and provides information about domain names and their corresponding IP addresses. It acts as a translator between the domain name and its associated IP address, allowing users to access websites and other network services by simply typing the domain name into a web browser. The DNS server facilitates the resolution of domain names to IP addresses, allowing web browsers and other applications to connect to the correct server.

ipconfig can show your current Domain Name System (DNS) server. Enter in your terminal:

$ ipconfig getoption en0 domain_name_server

Note that this might return 192.168.1.1, the address of your router. In many cases, your router acts as a DNS forwarder, you ask your router and your router asks a DNS server for you.

How to renew DHCP Lease

Dynamic Host Configuration Protocol (DHCP) is a network protocol that is used to assign IP addresses and other network settings to computers and other devices on a network. It is used to automate the process of setting up a network, which would otherwise need to be done manually.

ipconfig can help you renew your DHCP lease, to have your device assigned a new ip address:

$ sudo ipconfig set en0 DHCP

Be careful when using this command, when this process is not done correctly, it can lead to IP address mismatches that can cause further problems within your network

Conclusion

The ipconfig command in MacOS is a command-line utility used to configure and display the IP address, subnet mask, and router address of a computer. It is used to configure the network interface settings of a Mac computer connected to the internet.

The ipconfig command is an important tool for configuring and troubleshooting network connections in MacOS. It can be used to configure the network interface settings, view the current IP address, set a static IP address, configure DHCP settings, and also release and renew the IP address of the Mac computer.