Quick Links
Key Takeaways
- The ip command has replaced the older ifconfig command in modern versions of Linux.
- The ip command allows you to configure IP addresses, network interfaces, and routing rules on the fly without rebooting.
- Run "ip addr" in the Terminal to get your PC's local IP address.
You can configure IP addresses, network interfaces, and routing rules on the fly with the Linux ip command. We'll show you how you can use this modern replacement of the classic (and now deprecated) ifconfig .
How the ip Command Works
With the ip command, you can adjust the way a Linux computer handles IP addresses, network interfaces controllers (NICs), and routing rules. The changes also take immediate effect — you don't have to reboot. The ip command can do a lot more than this, but we'll focus on the most common uses in this article.
The ip command has many subcommands, each of which works on a type of object, such as IP addresses and routes. There are, in turn, many options for each of these objects. It's this richness of functionality that gives the ip command the granularity you need to perform what can be delicate tasks. This isn't ax work — it calls for a set of scalpels.
We'll look at the following objects:
- Address: IP addresses and ranges.
- Link: Network interfaces, such as wired connections and Wi-Fi adapters.
- Route: The rules that manage the routing of traffic sent to
addressesvia interfaces (links).
Using ip with Addresses
Obviously, you first have to know the settings you're dealing with. To discover which IP addresses your computer has, you use the ip command with the object address. The default action is show, which lists the IP addresses. You can also omit show and abbreviate address as "addr" or even "a."
The following commands are all equivalent:
ip address show
ip addr show
ip addr
ip a
We see two IP addresses, along with a lot of other information. IP addresses are associated with network interface controllers (NICs). The ip command tries to be helpful and provides a bunch of information about the interface, too.
The first IP address is the (internal) loopback address used to communicate within the computer. The second is the actual (external) IP address the computer has on the local area network (LAN).
Let's break down all the information we received:
- lo: The network interface name as a string.
- <LOOPBACK,UP,LOWER_UP>: This is a loopback interface. It's
UP, meaning it's operational. The physical networking layer (layer one) is also up. - mtu 65536: The maximum transfer unit. This is the size of the largest chunk of data this interface can transmit.
- qdisc noqueue: A
qdiscis a queuing mechanism. It schedules the transmission of packets. There are different queuing techniques called disciplines. Thenoqueuediscipline means "send instantly, don't queue." This is the defaultqdiscdiscipline for virtual devices, such as the loopback address. - state UNKNOWN: This can be
DOWN(the network interface is not operational),UNKNOWN(the network interface is operational but nothing is connected), orUP(the network is operational and there is a connection). - group default: Interfaces can be grouped logically. The default is to place them all in a group called "default."
- qlen 1000: The maximum length of the transmission queue.
- link/loopback: The media access control (MAC) address of the interface.
- inet 127.0.0.1/8: The IP version 4 address. The part of the address after the forward-slash (
/) is Classless Inter-Domain Routing notation (CIDR) representing the subnet mask. It indicates how many leading contiguous bits are set to one in the subnet mask. The value of eight means eight bits. Eight bits set to one represents 255 in binary, so the subnet mask is 255.0.0.0. - scope host: The IP address scope. This IP address is only valid inside the computer (the "host").
- lo: The interface with which this IP address is associated.
- valid_lft: Valid lifetime. For an IP version 4 IP address allocated by Dynamic Host Configuration Protocol (DHCP), this is the length of time the IP address is considered valid and able to make and accept connection requests.
- preferred_lft: Preferred lifetime. For an IP version 4 IP address allocated by DHCP, this is the amount of time the IP address can be used with no restrictions. This should never be larger than the
valid_lftvalue. - inet6: The IP version 6 address,
scope,valid_lft, andpreferred_lft.
The physical interface is more interesting, as we'll show below:
- enp0s3: The network interface name as a string. The "en" stands for ethernet, "p0" is the bus number of the ethernet card, and "s3" is the slot number.
- <BROADCAST,MULTICAST,UP,LOWER_UP>: This interface supports broad- and multicasting, and the interface is
UP(operational and connected). The hardware layer of the network (layer one) is alsoUP. - mtu 1500: The maximum transfer unit this interface supports.
- qdisc fq_codel: The scheduler is using a discipline called "Fair Queuing, Controlled Delay." It's designed to provide a fair share of the bandwidth to all the traffic flows that use the queue.
- state UP: The interface is operational and connected.
- group default: This interface is in the "default" interface group.
- qlen 1000: The maximum length of the transmission queue.
- link/ether: The MAC address of the interface.
- inet 192.168.4.26/24: The IP version 4 address. The "/24" tells us there are 24 contiguous leading bits set to one in the subnet mask. That's three groups of eight bits. An eight-bit binary number equates to 255; therefore, the subnet mask is 255.255.255.0.
- brd 192.168.4.255: The broadcast address for this subnet.
- scope global: The IP address is valid everywhere on this network.
- dynamic: The IP address is lost when the interface goes down.
- noprefixroute: Do not create a route in the route table when this IP address is added. Someone has to add a route manually if he wants to use one with this IP address. Likewise, if this IP address is deleted, don't look for a route to delete.
- enp0s3: The interface with which this IP address is associated.
- valid_lft: Valid lifetime. The time the IP address will be considered valid; 86,240 seconds is 23 hours and 57 minutes.
- preferred_lft: Preferred lifetime. The time the IP address will operate without any restrictions.
- inet6: The IP version 6 address,
scope,valid_lft, andpreferred_lft.