ip Command: Checking Linux IP and Managing Interfaces and Routing
The ip command is a key tool for managing the network on Linux and can carry out a wide range of network tasks. On an AlmaLinux 9 server, ip addr, ip link, ip route and ip neigh were run in turn, and four commands were enough to check the server's IP address, the interface status, the default gateway and even its MAC address.
It can check the status of network interfaces or enable and disable them, and it can also check IP addresses or add and delete them manually. It also provides a range of network features, including routing management that views the routing table and adds or removes routes, checking and modifying the ARP table, and tunnel setup.
| Features | Description |
|---|---|
| Checking network status | Check interface status (UP/DOWN), link information, etc. |
| IP address management | Check, add and delete IP addresses |
| Routing table management | Check routing information, add and delete routes |
| ARP table management | Check and modify the ARP cache |
| Interface control | Enable or disable interfaces |
| Tunnel setup | Create and manage tunnel interfaces |
Commands that change the server network, such as adding and deleting IP addresses or turning off an interface, were not run on the test server. The IP addresses and MAC addresses in the output below are example values.
1️⃣ Basic Syntax of the ip Command
The ip command takes options (OPTIONS), followed by the object to work on (OBJECT) and the command to run (COMMAND), in that order. Typing just ip with nothing after it prints the usage.
ipUsage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
where OBJECT := { address | addrlabel | fou | help | ila | ioam | l2tp | link |
macsec | maddress | monitor | mptcp | mroute | mrule |
neighbor | neighbour | netconf | netns | nexthop | ntable |
ntbl | route | rule | sr | stats | tap | tcpmetrics |
token | tunnel | tuntap | vrf | xfrm }
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec | -j[son] | -p[retty] |
-f[amily] { inet | inet6 | mpls | bridge | link } |
-4 | -6 | -M | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } | -echo | -br[ief] |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
-rc[vbuf] [size] | -n[etns] name | -N[umeric] | -a[ll] |
-c[olor]}The output of ip on its own was identical, character for character, to that of ip --help and ip help.
OBJECT can be written as the full name or a short name. According to man ip, address can be shortened to addr or a, and when tried, ip r, ip n and ip l also gave the same output as ip route show, ip neigh show and ip link show.
Splitting ip -4 addr show into options, object and command looks like this.
show can be omitted, so ip -4 addr is the same command.
Adding help after an object prints only the commands and arguments that can be used with that object.
ip addr show helpUsage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]
[ CONFFLAG-LIST ]
ip address del IFADDR dev IFNAME [mngtmpaddr]
ip address {save|flush} [ dev IFNAME ] [ scope SCOPE-ID ] [ to PREFIX ]
[ FLAG-LIST ] [ label LABEL ] [ { up | down } ]
ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]
[ nomaster ]
[ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]
[ label LABEL ] [ { up | down } ] [ vrf NAME ]
[ proto ADDRPROTO ] ]
ip address {showdump|restore}
IFADDR := PREFIX | ADDR peer PREFIX
[ broadcast ADDR ] [ anycast ADDR ]
[ label IFNAME ] [ scope SCOPE-ID ] [ metric METRIC ]
[ proto ADDRPROTO ]
SCOPE-ID := [ host | link | global | NUMBER ]
FLAG-LIST := [ FLAG-LIST ] FLAG
FLAG := [ permanent | dynamic | secondary | primary |
[-]tentative | [-]deprecated | [-]dadfailed | temporary |
CONFFLAG-LIST ]
CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG
CONFFLAG := [ home | nodad | mngtmpaddr | noprefixroute | autojoin ]
LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ]
LFT := forever | SECONDS
ADDRPROTO := [ NAME | NUMBER ]
TYPE := { amt | bareudp | bond | bond_slave | bridge | bridge_slave |
dsa | dummy | erspan | geneve | gre | gretap | gtp | hsr |
ifb | ip6erspan | ip6gre | ip6gretap | ip6tnl |
ipip | ipoib | ipvlan | ipvtap |
macsec | macvlan | macvtap | netdevsim |
netkit | nlmon | pfcp | rmnet | sit | team | team_slave |
vcan | veth | vlan | vrf | vti | vxcan | vxlan | wwan |
xfrm | virt_wifi }This usage shows that ip address takes commands such as add, del and show, and arguments such as dev and scope.
2️⃣ Commonly Used ip Commands
The ten commands below are the ones most often used in practice. The commands that check things (show) only read the settings, while add, del and set change the network settings the moment they run.
| Command | Description |
|---|---|
| ip a (ip addr) | Print network interfaces and IP addresses |
| ip link show | Check network interface status |
| ip addr add | Add an IP address |
| ip addr del | Delete an IP address |
| ip route show | Print the routing table |
| ip route add | Add a route |
| ip route del | Delete a route |
| ip neigh show | View the ARP table |
| ip link set up/down | Enable/disable an interface |
| ip tunnel add | Create a tunnel |
Tunnels are checked with ip tunnel show. On the test server, where no tunnel had been created, it printed nothing.
3️⃣ Linux Command to Check the IP: ip addr
To check a server's IP address on Linux, run ip a, the short form of ip addr.
ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
link/ether 02:00:00:00:00:10 brd ff:ff:ff:ff:ff:ff
altname enp0s5
altname ens5
inet 192.0.2.10/24 brd 192.0.2.255 scope global dynamic noprefixroute eth0
valid_lft 3536sec preferred_lft 3536sec
inet6 2001:db8:0:1::10/128 scope global dynamic noprefixroute
valid_lft 446sec preferred_lft 136sec
inet6 fe80::ff:fe00:10/64 scope link noprefixroute
valid_lft forever preferred_lft foreverThe output starts each interface with a number and a name. 1: lo is the loopback interface used only inside the server, and 2: eth0 is the Ethernet interface that actually communicates. The meaning of each item is shown below.
| Item | Contents |
|---|---|
| 1: lo | Loopback interface (for internal communication) · 127.0.0.1/8 |
| 2: eth0 | Ethernet interface |
| UP, LOWER_UP | Status — enabled |
| mtu 9001 | MTU — short for Maximum Transmission Unit, the largest data packet size that can be sent over the network at one time |
| link/ether | MAC address |
| inet 192.0.2.10/24 | IPv4 address (subnet mask 255.255.255.0) |
| brd 192.0.2.255 | Broadcast address |
| scope global | Range (scope) — global (system-wide) |
| dynamic | Address with a limited lifetime (address obtained via DHCP) |
| noprefixroute | Does not create a prefix route automatically |
| valid_lft | Address lifetime (forever = unlimited) |
| inet6 fe80::…/64 | IPv6 link-local address (scope link) |
The MTU of eth0 was 9001, a value larger than the Ethernet default of 1500. valid_lft showed 3536sec, and when run again a few minutes later it had dropped to 2933sec. An address obtained via DHCP has a fixed lease time, so the remaining time keeps going down. 127.0.0.1 on lo showed forever.
To see only IPv4 addresses, add the -4 option.
ip -4 a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
altname enp0s5
altname ens5
inet 192.0.2.10/24 brd 192.0.2.255 scope global dynamic noprefixroute eth0
valid_lft 3536sec preferred_lft 3536secWith -4, the link/ether and inet6 lines disappear and only the IPv4 addresses remain.
For a quick check of just the server IP, the output of the -br (brief) option is the shortest.
ip -br alo UNKNOWN 127.0.0.1/8 ::1/128
eth0 UP 192.0.2.10/24 2001:db8:0:1::10/128 fe80::ff:fe00:10/64Each interface gets one line with its name, status and addresses, but the MTU and lifetime are left out, so check those values with ip a when they are needed. To see a single interface, put its name after dev as in ip addr show dev eth0; giving a name that does not exist printed an error saying the device does not exist, with exit code 1.
4️⃣ Checking Interface Status with the ip Command: ip link
Even if an IP address is assigned, packets do not go out while the interface is down, so check the interface status separately with ip link show.
ip link show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 02:00:00:00:00:10 brd ff:ff:ff:ff:ff:ff
altname enp0s5
altname ens5ip link show prints only the interface names, status and MAC addresses, without IP addresses. UP, LOWER_UP and state UP on the eth0 line mean the interface is on and the link is connected. For lo, the loopback, state showed UNKNOWN.
For a quick look at just the MAC addresses, ip -br link prints one line per interface.
ip -br linklo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
eth0 UP 02:00:00:00:00:10 <BROADCAST,MULTICAST,UP,LOWER_UP>The second column is the status and the third column is the MAC address. The command that turns an interface off and on is ip link set.
ip link set dev eth0 downdown turns the interface off, and up turns it back on.
ip link set dev eth0 upOn a server reached over SSH, bringing down the interface used for the connection drops the connection at that moment, and the up command to turn it back on cannot be sent either. That is why this command is used only on servers that can be accessed directly through a console.
5️⃣ Adding and Deleting IP Addresses: ip addr add and del
The ip command applies network settings immediately, but these settings are temporary. The changes disappear after a reboot, so settings that should stay are better applied with nmtui or a similar command.
Below is the result of adding one more IP address to the enp0s3 interface of a test virtual machine. Put the subnet mask after the address, as in /24, and the interface name after dev.
ip addr add 192.0.2.201/24 dev enp0s3A successful add prints nothing, so check the result with ip a.
ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 02:00:00:00:00:20 brd ff:ff:ff:ff:ff:ff
inet 192.0.2.200/24 brd 192.0.2.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
inet 192.0.2.201/24 scope global secondary enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::200/64 scope link noprefixroute
valid_lft forever preferred_lft foreverIn the output above, 192.0.2.201, added in the same range as the first address 192.0.2.200, is attached as secondary, with no brd address and a lifetime of forever.
To delete, use del in place of add, with the same address and subnet mask as when adding.
ip addr del 192.0.2.201/24 dev enp0s3A successful delete also prints nothing, so check the remaining IPv4 addresses with ip -4 addr.
ip -4 addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.0.2.200/24 brd 192.0.2.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft foreverAs in the output above, only the first address 192.0.2.200 remains after the deletion.
6️⃣ Checking the Routing Table and ARP with the ip Command
The path that packets leaving the server take is in the routing table, which is checked with ip route show.
ip route showdefault via 192.0.2.1 dev eth0 proto dhcp src 192.0.2.10 metric 100
192.0.2.0/24 dev eth0 proto kernel scope link src 192.0.2.10 metric 100show can be omitted, so ip route and ip r give the same output. 192.0.2.1 after default via is the default gateway, and 192.0.2.10 after src is the IP address this server uses when sending packets.
proto dhcp means this route was obtained via DHCP. The second line means that addresses in the same range (192.0.2.0/24) are sent straight out through eth0 without going through the gateway.
Which route is used to reach a specific destination is checked with ip route get.
ip route get 8.8.8.88.8.8.8 via 192.0.2.1 dev eth0 src 192.0.2.10 uid 0
cacheIn the output above, packets to 8.8.8.8 go out through eth0 via the default gateway 192.0.2.1, and the source address is 192.0.2.10.
To add or delete routes directly, use ip route add and ip route del.
ip route add 198.51.100.0/24 via 192.0.2.1 dev eth0According to man ip-route, write the destination range after add, the gateway after via, and the interface after dev.
ip route del 198.51.100.0/24After del, write the destination range to delete.
To hand packets to the gateway within the same network, the gateway's MAC address is needed, and that value is kept in the ARP table.
ip neigh show192.0.2.2 dev eth0 lladdr 02:00:00:00:00:01 REACHABLE
192.0.2.1 dev eth0 lladdr 02:00:00:00:00:01 REACHABLE
fe80::ff:fe00:1 dev eth0 lladdr 02:00:00:00:00:01 router REACHABLEWhat follows lladdr is the neighbor's MAC address, and the IPv6 gateway line has router attached. According to man ip-neighbour, REACHABLE at the end means the entry is valid until its confirmation time runs out.
Matching the values the four commands print to a single packet going to 8.8.8.8 gives the following.
inet 192.0.2.10/24 brd 192.0.2.255 scope global dynamic noprefixroute eth0$ ip link show
2: eth0: … state UP … link/ether 02:00:00:00:00:10$ ip route get 8.8.8.8
8.8.8.8 via 192.0.2.1 dev eth0 src 192.0.2.10 uid 0$ ip neigh show
192.0.2.1 dev eth0 lladdr 02:00:00:00:00:01 REACHABLE
🔲 ip Command Simulator
On the virtual server in the simulator below, ip addr, ip link, ip route and ip neigh can be typed in directly. Adding an IP address makes a secondary address appear in the status panel, and turning off the interface changes eth0 to DOWN.
🔢 FAQ & Recommended Content
Firewall · FirewallD
Installing FirewallD on Linux and configuring the daemon
The order of FirewallD settings for opening and closing ports, IPs, and http and https services with Zone and Service instead of iptables rules.
DNS · nslookup
nslookup Command: Usage and Options, Record Lookups and Choosing a DNS Server
An article covering how to look up a domain's IP address and DNS records, along with reverse lookups and option usage.
Remote Access · SSH
SSH Command: How to Use the -l, -p, and -i Options and Check Connection Errors
Basic usage of the SSH command for connecting to another Linux server over the network, with option examples.
ℹ️ Affiliate Disclosure
This site's content contains affiliate links. When a visitor buys a product or service through one of them, the site receives a commission from the seller. The amount the buyer pays(it goes down during event discounts ↓)does not go up. Posted prices, discounts, and stock reflect the time of writing and may differ, so confirm with the seller before buying. Products are chosen and reviewed by our own standards, and commissions do not affect the order or content of reviews.