- The ip bid has replaced nan older ifconfig bid successful modern versions of Linux.
- The ip bid allows you to configure IP addresses, web interfaces, and routing rules connected nan alert without rebooting.
- Run "ip addr" successful nan Terminal to get your PC's section IP address.
You tin configure IP addresses, web interfaces, and routing rules connected nan alert pinch nan Linux ip command. We'll show you really you tin usage this modern replacement of nan classical (and now deprecated) ifconfig .
How nan ip Command Works
With nan ip command, you tin adjust nan measurement a Linux computer handles IP addresses, network interfaces controllers (NICs), and routing rules. The changes besides return contiguous effect — you don't person to reboot. The ip bid tin do a batch much than this, but we'll attraction connected nan astir communal uses successful this article.
The ip bid has galore subcommands, each of which useful connected a type of object, specified arsenic IP addresses and routes. There are, successful turn, galore options for each of these objects. It's this richness of functionality that gives nan ip bid nan granularity you request to execute what tin beryllium delicate tasks. This isn't ax activity — it calls for a group of scalpels.
We'll look astatine nan pursuing objects:
- Address: IP addresses and ranges.
- Link: Network interfaces, specified arsenic wired connections and Wi-Fi adapters.
- Route: The rules that negociate nan routing of postulation sent to addresses via interfaces (links ).
Using ip pinch Addresses
Obviously, you first person to cognize nan settings you're dealing with. To observe which IP addresses your machine has, you usage nan ip bid pinch nan entity address. The default action is show, which lists nan IP addresses. You tin besides omit show and abbreviate reside arsenic "addr" aliases moreover "a."
The pursuing commands are each equivalent:ip reside show ip addr show ip addr ip a
We spot 2 IP addresses, on pinch a batch of different information. IP addresses are associated pinch web interface controllers (NICs). The ip bid tries to beryllium adjuvant and provides a bunch of accusation astir nan interface, too.
The first IP reside is nan (internal) loopback reside utilized to pass wrong nan computer. The 2nd is nan existent (external) IP reside nan machine has connected nan section area web (LAN).
Let's break down each nan accusation we received:
- lo: The web interface sanction arsenic a string.
- <LOOPBACK,UP,LOWER_UP>: This is simply a loopback interface. It's UP, meaning it's operational. The physical networking layer (layer one) is besides up.
- mtu 65536: The maximum transportation unit. This is nan size of nan largest chunk of information this interface tin transmit.
- qdisc noqueue: A qdisc is simply a queuing mechanism. It schedules nan transmission of packets. There are different queuing techniques called disciplines. The noqueue subject intends "send instantly, don't queue." This is nan default qdisc subject for virtual devices, specified arsenic nan loopback address.
- state UNKNOWN: This tin beryllium DOWN (the web interface is not operational), UNKNOWN (the web interface is operational but thing is connected), aliases UP (the web is operational and location is simply a connection).
- group default: Interfaces tin beryllium grouped logically. The default is to spot them each successful a group called "default."
- qlen 1000: The maximum magnitude of nan transmission queue.
- link/loopback: The media entree control (MAC) reside of nan interface.
- inet 127.0.0.1/8: The IP type 4 address. The portion of nan reside aft nan forward-slash (/) is Classless Inter-Domain Routing notation (CIDR) representing nan subnet mask. It indicates really galore starring contiguous bits are group to 1 successful nan subnet mask. The worth of 8 intends 8 bits. Eight bits group to 1 represents 255 successful binary, truthful nan subnet disguise is 255.0.0.0.
- scope host: The IP reside scope. This IP reside is only valid wrong nan machine (the "host").
- lo: The interface pinch which this IP reside is associated.
- valid_lft: Valid lifetime. For an IP type 4 IP reside allocated by Dynamic Host Configuration Protocol (DHCP), this is nan magnitude of clip nan IP reside is considered valid and capable to make and judge relationship requests.
- preferred_lft: Preferred lifetime. For an IP type 4 IP reside allocated by DHCP, this is nan magnitude of clip nan IP reside tin beryllium utilized pinch nary restrictions. This should ne'er beryllium larger than nan valid_lft value.
- inet6: The IP type 6 address, scope , valid_lft, and preferred_lft.
The beingness interface is much interesting, arsenic we'll show below:
- enp0s3: The web interface sanction arsenic a string. The "en" stands for ethernet, "p0" is nan autobus number of nan ethernet card, and "s3" is nan slot number.
- <BROADCAST,MULTICAST,UP,LOWER_UP>: This interface supports broad- and multicasting, and nan interface is UP (operational and connected). The hardware furniture of nan web (layer one) is besides UP.
- mtu 1500: The maximum transportation portion this interface supports.
- qdisc fq_codel: The scheduler is utilizing a subject called "Fair Queuing, Controlled Delay." It's designed to supply a adjacent stock of nan bandwidth to each nan postulation flows that usage nan queue.
- state UP: The interface is operational and connected.
- group default: This interface is successful nan "default" interface group.
- qlen 1000: The maximum magnitude of nan transmission queue.
- link/ether: The MAC reside of nan interface.
- inet 192.168.4.26/24: The IP type 4 address. The "/24" tells america location are 24 contiguous starring bits group to 1 successful nan subnet mask. That's 3 groups of 8 bits. An eight-bit binary number equates to 255; therefore, nan subnet disguise is 255.255.255.0.
- brd 192.168.4.255: The broadcast address for this subnet.
- scope global: The IP reside is valid everyplace connected this network.
- dynamic: The IP reside is mislaid erstwhile nan interface goes down.
- noprefixroute: Do not create a way successful nan way array erstwhile this IP reside is added. Someone has to adhd a way manually if he wants to usage 1 pinch this IP address. Likewise, if this IP reside is deleted, don't look for a way to delete.
- enp0s3: The interface pinch which this IP reside is associated.
- valid_lft: Valid lifetime. The clip nan IP reside will beryllium considered valid; 86,240 seconds is 23 hours and 57 minutes.
- preferred_lft: Preferred lifetime. The clip nan IP reside will run without immoderate restrictions.
- inet6: The IP type 6 address, scope, valid_lft, and preferred_lft.
Display Only IPv4 aliases IPv6 Addresses
If you want to limit nan output to nan IP type 4 addresses, you tin usage nan -4 option, arsenic follows:ip -4 addr
If you want to limit nan output to nan IP type 6 addresses, you tin usage nan -6 option, arsenic follows:ip -6 addr
Display Information for a Single Interface
If you want to spot nan IP reside accusation for a azygous interface, you tin usage nan show and dev options, and sanction nan interface, arsenic shown below:ip addr show dev lo ip addr show dev enp0s3
You tin besides usage nan -4 aliases -6 emblem to further refine nan output truthful you only spot that successful which you're interested.
If you want to spot nan IP type 4 accusation related to nan addresses connected interface enp0s3, type nan pursuing command:ip -4 addr show dev enp0s3
Adding an IP Address
You tin usage nan adhd and dev options to adhd an IP reside to an interface. You conscionable person to show nan ip bid which IP reside to add, and to which interface to adhd it.
We're going to adhd nan IP reside 192.168.4.44 to nan enp0s3 interface. We besides person to supply nan CIDR notation for nan subnet mask.
We type nan following:sudo ip addr adhd 192.168.4.44/24 dev enp0s3
We type nan pursuing to return different look astatine nan IP type 4 IP addresses connected this interface:ip -4 addr show dev enp0s3
The caller IP reside is coming connected this web interface. We jump connected different machine and usage nan pursuing bid to spot if we tin ping nan caller IP address:ping 192.168.4.44
The IP reside responds and sends backmost acknowledgments to nan pings. Our caller IP reside is up and moving aft 1 elemental ip command.
Deleting an IP Address
To delete an IP address, nan bid is almost nan aforesaid arsenic nan 1 to adhd one, isolated from you switch adhd pinch del, arsenic shown below:sudo ip addr del 192.168.4.44/24 dev enp0s3
If we type nan pursuing to check, we spot nan caller IP reside has been deleted:ip -4 addr show dev enp0s3
Using ip pinch Network Interfaces
You usage nan nexus entity to inspect and activity pinch web interfaces. Type nan pursuing bid to spot nan interfaces installed connected your computer:ip nexus show
To spot a azygous web interface, conscionable adhd its sanction to nan command, arsenic shown below:ip nexus show enp0s3
Starting and Stopping Links
You tin usage nan group action pinch either up aliases down to extremity aliases commencement a web interface option. You besides person to usage sudo, arsenic shown below:sudo ip nexus group enp0s3 down
We type nan pursuing to return a look astatine nan web interface:ip nexus show enp0s3
The authorities of nan web interface is DOWN. We tin usage nan up action to restart a web interface, arsenic shown below:sudo ip nexus group enp0s3 up
We type nan pursuing to do different speedy cheque connected nan authorities of nan web interface:ip nexus show enp0s3
The web interface was restarted, and nan authorities is shown arsenic UP.
Using ip pinch Routes
With nan way object, you tin inspect and manipulate routes. Routes specify to wherever web postulation to different IP addresses is forwarded, and done which web interface.
If nan destination machine aliases instrumentality shares a web pinch nan sending computer, nan sending machine tin guardant nan packet straight to it.
However, if nan destination instrumentality is not straight connected, nan sending machine forwards nan packet to nan default router. The router past decides wherever to nonstop nan packet.
To spot nan routes defined connected your computer, type nan pursuing command:ip route
Let's return a look astatine nan info we received:
- default: The default rule. This way is utilized if nary of nan different rules lucifer what's being sent.
- via 192.168.4.1: Routes nan packets via nan instrumentality astatine 192.168.4.1. This is nan IP reside of nan default router connected this network.
- dev enp0s3: Use this web interface to nonstop nan packets to nan router.
- proto dhcp: The routing protocol identifier. DHCP intends nan routes will beryllium wished dynamically.
- metric 100: An denotation of nan penchant of nan way compared to others. Routes pinch little metrics are preferentially utilized complete those pinch higher metrics. You tin usage this to springiness penchant to a wired web interface complete a Wi-Fi one.
The 2nd way governs postulation to nan IP scope of 169.254.0.0/16. This is simply a zero-configuration network, which intends it tries to self-configure for intranet communication. However, you can't usage it to nonstop packets extracurricular nan contiguous network.
The rule down zero-configuration networks is they don't trust connected DHCP and different services being coming and active. They only need to spot TCP/IP successful bid to self-identify to each of nan different devices connected nan network.
Let's return a look:
- 169.254.0.0/16: The scope of IP addresses this routing norm governs. If nan machine communicates connected this IP range, this norm cuts in.
- dev enp0s3: The web interface nan postulation governed by this way will use.
- scope link: The scope is link, which intends nan scope is constricted to nan web to which this machine is straight connected.
- metric 1000: This is simply a precocious metric and isn't a preferred route.
The 3rd way governs postulation to nan IP reside scope of 192.168.4.0/24. This is nan IP reside scope of nan section web to which this machine is connected. It's for connection across, but within, that network.
Let's break it down:
- 192.168.4.1/24: The scope of IP addresses this routing norm governs. If nan machine communicates wrong this IP range, this norm triggers and controls nan packet routing.
- dev enp0s3: The interface done which this way will nonstop packets.
- proto kernel: The way created by nan kernel during auto-configuration.
- scope link: The scope is link, which intends nan scope is constricted to nan contiguous web to which this machine is connected.
- src 192.168.4.26: The IP reside from which packets sent by this way originate.
- metric 100: This debased metric indicates a preferred route.
Display Information for a Single Route
If you want to attraction connected nan specifications of a peculiar route, you tin adhd nan database action and IP reside scope of nan way to nan bid arsenic follows:ip way database 192.168.4.0/24
Adding a Route
We conscionable added a caller web interface paper to this computer. We type nan pursuing and spot it's showing up arsenic enp0s8:ip nexus show
We'll adhd a caller way to nan machine to usage this caller interface. First, we type nan pursuing to subordinate an IP reside pinch nan interface:sudo ip addr adhd 192.168.121.1/24 dev enp0s8
A default way utilizing nan existing IP reside is added to nan caller interface. We usage nan delete option, arsenic shown below, to delete nan way and supply its details:sudo ip way delete default via 192.168.4.1 dev enp0s8
We'll now usage nan adhd action to adhd our caller route. The caller interface will grip web postulation successful nan 192.168.121.0/24 IP reside range. We'll springiness it a metric of 100; because it will beryllium nan only way handling this traffic, nan metric is beautiful overmuch academic.
We type nan following:sudo ip way adhd 192.168.121.0/24 dev enp0s8 metric 100
Now, we type nan pursuing to spot what it gives us:ip route
Our caller way is now successful place. However, we still person nan 192.168.4.0/24 way that points to interface enp0s8 — we type nan pursuing to region it:sudo ip way delete 192.168.4.0/24 dev enp0s8
We should now person a caller way that points each postulation destined for IP scope 192.168.121.0/24 done interface enp0s8. It should besides beryllium nan only way that uses our caller interface.
We type nan pursuing to confirm:ip route
Taken Route, Not Taken Root
The awesome point astir these commands is they're not permanent. If you want to clear them, conscionable reboot your system. This intends you tin research pinch them until they activity nan measurement you want. And it's a very bully point if you make a unspeakable messiness of your strategy — a elemental reboot will reconstruct order.
On nan different hand, if you want nan changes to beryllium permanent, you person to do immoderate much work. Exactly what varies depending connected nan distribution family, but they each impact changing config files.
This way, though, you tin test-drive commands earlier you make thing permanent.