Linux ip Command Examples


I am a new Linux system admin user. How do I use ip command line utility to display or configure networking, routing, and tunnels on Linux operating systems? How do I configures or displays network interface parameters for a network using TCP/IP on Linux operating systems?

The ip command is used to assign an address to a network interface and/or configure network interface parameters on Linux operating systems. This command replaces old good and now deprecated ifconfig command on modern Linux distributions.

It is used for the following purposes:
  1. Find out which interfaces are configured on the system.
  2. Query the status of a IP interface.
  3. Configure the local loop-back, Ethernet and other IP interfaces.
  4. Mark the interface as up or down.
  5. Configure and modify default and static routing.
  6. Set up tunnel over IP.
  7. Show ARP or NDISC cache entry.
  8. Assign, delete, set up IP address, routes, subnet and other IP information to IP interfaces.
  9. List IP Addresses and property information.
  10. Manage and display the state of all network.
  11. Gather multicast IP addresses info.
  12. Show neighbour objects i.e. ARP cache, invalidate ARP cache, add an entry to ARP cache and more.
  13. Set or delete routing entry.
  14. Find the route an address (say or will take.
  15. Modify the status of interface.


Use this command to display and configure the network parameters for host interfaces.


ip [options] OBJECT COMMAND
ip OBJECT help

Understanding ip command OBJECTS syntax

OBJECTS can be any one of the following and may be written in full or abbreviated form:

Object Abbreviated form Purpose
link l Network device.
address a
Protocol (IP or IPv6) address on a device.
addrlabel addrl Label configuration for protocol address selection.
neighbour n
ARP or NDISC cache entry.
route r Routing table entry.
rule ru Rule in routing policy database.
maddress m
Multicast address.
mroute mr Multicast routing cache entry.
tunnel t Tunnel over IP.
xfrm x Framework for IPsec protocol.

To get information about each object use help command as follows:

ip OBJECT help
ip a help
ip r help

Warning: The commands described below must be executed with care. If you make a mistake, you will lose connectivity to the server. You must take special care while working over the ssh based remote session.

ip command examples

Don’t be intimidated by ip command syntax. Let us get started quickly with examples.

Displays info about all network interfaces

Type the following command to list and show all ip address associated on on all network interfaces:
ip a
ip addr
Sample outputs:

Fig.01 Showing IP address assigned to eth0, eth1, lo using ip command

Fig.01 Showing IP address assigned to eth0, eth1, lo using ip command

You can select between IPv4 and IPv6 using the following syntax:

### Only show TCP/IP IPv4  ##
ip -4 a
### Only show TCP/IP IPv6  ###
ip -6 a

It is also possible to specify and list particular interface TCP/IP details:

### Only show eth0 interface ###
ip a show eth0
ip a list eth0
ip a show dev eth0
### Only show running interfaces ###
ip link ls up
Linux ip command examples for sysadmin

Assigns the IP address to the interface

The syntax is as follows to add an IPv4/IPv6 address:
ip a add {ip_addr/mask} dev {interface}
To assign to eth0, enter:
ip a add dev eth0
ip a add dev eth0

Adding the broadcast address on the interface

By default, the ip command does not set any broadcast address unless explicitly requested. So syntax is as follows to set broadcast ADDRESS:
ip addr add brd {ADDDRESS-HERE} dev {interface}
ip addr add broadcast {ADDDRESS-HERE} dev {interface}
ip addr add broadcast dev dummy0

It is possible to use the special symbols such as + and - instead of the broadcast address by setting/resetting the host bits of the interface pre x. In this example, add the address with netmask (/24) with standard broadcast and label “eth0Home” to the interface eth0:
ip addr add brd + dev eth0 label eth0Home
You can set loopback address to the loopback device lo as follows:
ip addr add dev lo brd + scope host

Remove / Delete the IP address from the interface

The syntax is as follows to remove an IPv4/IPv6 address:
ip a del {ipv6_addr_OR_ipv4_addr} dev {interface}

To delete from eth0, enter:
ip a del dev eth0

Flush the IP address from the interface

You can delete or remote an IPv4/IPv6 address one-by-one as described above. However, the flush command can remove as flush the IP address as per given condition. For example, you can delete all the IP addresses from the private network using the following command:
ip -s -s a f to
Sample outputs:

2: eth0    inet scope global secondary eth0
2: eth0    inet scope global eth0

*** Round 1, deleting 2 addresses ***
*** Flush is complete after 1 round ***

You can disable IP address on all the ppp (Point-to-Point) interfaces:
ip -4 addr flush label "ppp*"

Here is another example for all the Ethernet interfaces:
ip -4 addr flush label "eth*"

How do I change the state of the device to UP or DOWN?

The syntax is as follows:
ip link set dev {DEVICE} {up|down}
To make the state of the device eth1 down, enter:
ip link set dev eth1 down
To make the state of the device eth1 up, enter:
ip link set dev eth1 up

How do I change the txqueuelen of the device?

You can set the length of the transmit queue of the device using ifconfig command or ip command as follows:
ip link set txqueuelen {NUMBER} dev {DEVICE}
In this example, change the default txqueuelen from 1000 to 10000 for the eth0:
ip link set txqueuelen 10000 dev eth0
ip a list eth0

How do I change the MTU of the device?

For gigabit networks you can set maximum transmission units (MTU) sizes (JumboFrames) for better network performance. The syntax is:
ip link set mtu {NUMBER} dev {DEVICE}
To change the MTU of the device eth0 to 9000, enter:
ip link set mtu 9000 dev eth0
ip a list eth0

Sample outputs:

2: eth0:  mtu 9000 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:08:9b:c4:30:30 brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth1
    inet6 fe80::208:9bff:fec4:3030/64 scope link 
       valid_lft forever preferred_lft forever

Display neighbour/arp cache

The syntax is:
ip n show
ip neigh show

Sample outputs (note: I masked out some data with alphabets):

74.xx.yy.zz dev eth1 lladdr 00:30:48:yy:zz:ww REACHABLE dev eth0 lladdr 00:30:48:c6:0a:d8 REACHABLE dev eth1 lladdr 00:1a:30:yy:zz:ww REACHABLE dev eth0 lladdr 00:30:48:33:bc:32 REACHABLE dev eth1 lladdr 00:30:48:yy:zz:ww STALE
74.rr.ww.fff dev eth1 lladdr 00:30:48:yy:zz:ww DELAY dev eth0 lladdr 00:1a:30:38:a8:00 REACHABLE dev eth0 lladdr 00:30:48:8e:31:ac REACHABLE

The last field show the the state of the “neighbour unreachability detection” machine for this entry:

  1. STALE – The neighbour is valid, but is probably already unreachable, so the kernel will try to check it at the first transmission.
  2. DELAY – A packet has been sent to the stale neighbour and the kernel is waiting for confirmation.
  3. REACHABLE – The neighbour is valid and apparently reachable.

Add a new ARP entry

The syntax is:
ip neigh add {IP-HERE} lladdr {MAC/LLADDRESS} dev {DEVICE} nud {STATE}
In this example, add a permanent ARP entry for the neighbour on the device eth0:
ip neigh add lladdr 00:1a:30:38:a8:00 dev eth0 nud perm

neighbour state (nud) meaning
permanent The neighbour entry is valid forever and can be only be removed administratively
noarp The neighbour entry is valid. No attempts to validate this entry will be made but it can be removed when its lifetime expires.
stale The neighbour entry is valid but suspicious. This option to ip neigh does not change the neighbour state if it was valid and the address is not changed by this command.
reachable The neighbour entry is valid until the reachability timeout expires.

Delete a ARP entry

The syntax to invalidate or delete an ARP entry for the neighbour on the device eth1 is as follows.
ip neigh del {IPAddress} dev {DEVICE}
ip neigh del dev eth1

Change are state to reachable for the neighbour on the device eth1

ip neigh chg dev eth1 nud reachable

Flush ARP entry

This flush or f command flushes neighbour/arp tables, by specifying some condition. The syntax is:
ip -s -s n f {IPAddress}
In this example, flush neighbour/arp table
ip -s -s n f
ip -s -s n flush

ip route: Routing table management commands

Use the following command to manage or manipulate the kernel routing table.

Show routing table

To display the contents of the routing tables:
ip r
ip r list
ip route list
ip r list [options] ip route

Sample outputs:

default via dev eth1 dev eth1  proto kernel  scope link  src

Display routing for
ip r list
Sample outputs: dev eth1  proto kernel  scope link  src

Add a new route

The syntax is:
ip route add {NETWORK/MASK} via {GATEWAYIP}
ip route add {NETWORK/MASK} dev {DEVICE}
## Add default route using ip ##
ip route add default {NETWORK/MASK} dev {DEVICE}
ip route add default {NETWORK/MASK} via {GATEWAYIP}

Add a plain route to network via gateway
ip route add via
To route all traffic via gateway connected via eth0 network interface:
ip route add dev eth0

Delete a route

The syntax is as follows to delete default gateway:
ip route del default
In this example, delete the route created in previous subsection:
ip route del dev eth0

How to change MAC address on Linux

The MAC address of a Linux network interface card (NIC) can be changed as follows:
NIC="eno1" ## <-- My NIC name ##
ip link show $NIC
ip link set dev $NIC down
## set new MAC address ##
ip link set dev $NIC address XX:YY:ZZ:AA:BB:CC
ip link set dev $NIC up

Configure color output

We can make ip command output pretty by passing the -c option:

ip -c route
ip -c link
# The 'always' is default and color output is enabled regardless of stdout state
ip -c=always command1
# If parameter is 'auto', stdout is checked to be a terminal before enabling color output
ip -c=auto command2
# If parameter is 'never', color output is disabled
ip -c=never command3

Linux IP Command Ultimate Tutorial with Color Examples
Please note that this flag is ignored if -json option passsed to the ip command. We can create a permanent Bash alias on Linux using the alias command:

alias ip='ip -c'
alias ipc='ip -c'
# run it #
ipc route
ip link

We can ignore bash aliases and functions when running ip as follows:

\ip route
command ip link

Displaying all Linux IP address

Want to find out the IP address assigned to all interfaces and display IP only? Try:
$ sudo ip -br -c addr show
$ sudo ip -br -c link show

Print only basic information in a tabular format for better readability

Old vs. new tool

Deprecated Linux command and their replacement cheat sheet:

Old command (Deprecated) New command
ifconfig -a ip a
ifconfig enp6s0 down ip link set enp6s0 down
ifconfig enp6s0 up ip link set enp6s0 up
ifconfig enp6s0 ip addr add dev enp6s0
ifconfig enp6s0 netmask ip addr add dev enp6s0
ifconfig enp6s0 mtu 9000 ip link set enp6s0 mtu 9000
ifconfig enp6s0:0 ip addr add dev enp6s0
netstat ss
netstat -tulpn ss -tulpn
netstat -neopa ss -neopa
netstat -g ip maddr
route ip r
route add -net netmask dev enp6s0 ip route add dev enp6s0
route add default gw ip route add default via
arp -a ip neigh
arp -v ip -s neigh
arp -s 1:2:3:4:5:6 ip neigh add lladdr 1:2:3:4:5:6 dev enp6s0
arp -i enp6s0 -d ip neigh del dev wlp7s0

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 15 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
15 comments… add one
  • Alyson Calhoun Jan 24, 2014 @ 14:05

    Great information. Thank you!

  • Zhi Jan 25, 2014 @ 1:07

    what’s the command to set the interface to use DHCP?

  • Girish Jun 2, 2014 @ 3:35

    Can you please comment if it is possible to configure a point-to-point interface using the “ip” command set? I am especially looking to change the broadcast nature of an eth interface (the link encap and network type) to behave as point-to-point link. At the same time I don’t want to use the PPP, or ay other protocol.

  • positive Nov 15, 2014 @ 20:09

    good job mate

  • Kuba Dec 2, 2014 @ 10:46

    Is it possible to make permanent changes using ip command (boot persistent)?

  • zed Sep 5, 2015 @ 9:29

    How save configuration for after reboot?
    there are for example ip route save, but its in binary and mostly useless.
    ip command need to have ip xxx dump, with make valid ip calls to make same configuration. same as iptables have iptables-save.
    now, in ages of cloud, we need json interface, so we can all power of ip incorporate in couble easy steps to REST interface.

  • Ernest Jun 14, 2017 @ 11:56

    Helpful article…
    Thank You

  • Piers Sep 4, 2020 @ 18:52

    Nice article, thanks. Please fix this, doesn’t look very professional. :-)

    “…you will loos connectivity” I would think “lose” is what you’re looking for, loos are many toilets. LOL

  • Jalal Dec 3, 2020 @ 6:17

    Very nice and useful article
    Thanks a lot

  • Elmer Spencer Mar 23, 2021 @ 10:49

    Can you add a static IP config with ip? I mean where does all those settings stored? When I reboot the Debian Linux all settings are gone. Hence asking.

  • John Mar 31, 2021 @ 13:44

    I wonder if I can set the min_rto to a specific destination. Eg. I seem to have rto problems with an instrument on the local network ( and would like to set the minimum rto to say, 400ms or more (I’ve monitored the network and it seems to be 220 ms at the moment).

    • 🐧 Vivek Gite Mar 31, 2021 @ 19:09

      The syntax is

      # set rto_mi to 5ms #
      ip route change default via {IP} dev {INTERFCE} rto_min 5ms
      ip route

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum