How to use the Linux IP Command to Manage Server Network Interfaces

Updated on June 13, 2024
How to use the Linux IP Command to Manage Server Network Interfaces header image

Introduction

The IP command is a built-in network management utility that offers a wide range of features and tools to manage Linux network interfaces. It's an improved utility that combines the functionalities of legacy commands such as ifconfig, arp and route to offer improved management, monitoring and troubleshooting of your server network interfaces.

This article explains how to use the IP command to manage server network interfaces and ip objects such as links, addresses, rules and links. You will perform basic IP command functions such as interface configuration, routing, link and network address management to efficiently manage your server interfaces.

Prerequisites

Before you begin:

How to use the IP Command

The IP command uses the following syntax to manage network information and interfaces on your server.

console
$ ip [OPTIONS] OBJECT COMMAND [ARGUMENTS]

Within the above command:

  • OPTIONS: Sets the IP command operation mode.
  • OBJECT: Specifies the type of network object to view or manage. For example, link, address, route.
  • COMMAND: Defines the action to perform on the specified object. For example, add, del, show.
  • ARGUMENTS: Sets additional options to execute with the command.

View Network Interface Information

  1. Use the ip link show command to view information about all network interfaces available on the server.

    console
    $ ip link show
    

    Your output should be similar to the one below.

    1: 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
        link/ether 56:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff
    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc mq state UP mode DEFAULT group default qlen 1000
        link/ether 5a:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff

    Based on the above output, the command displays the total number of available interfaces, the MTU value, state, and MAC Address for each interface. Active interfaces use the UP state while inactive interfaces. Interfaces with a DOWN state cannot send or receive network traffic on the server unless enabled.

  2. Display network interfaces in an active and running state.

    console
    $ ip link show up
    

    Output:

    1: 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
        link/ether 56:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff
    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc mq state UP mode DEFAULT group default qlen 1000
        link/ether 5a:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff
  3. Use the br option to display only important information about the network interfaces.

    console
    $ ip -br link show
    

    Output:

    lo               UNKNOWN        00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP> 
    enp1s0           UP             56:00:04:ef:40:23 <BROADCAST,MULTICAST,UP,LOWER_UP> 
    enp8s0           UP             5a:00:04:ef:40:23 <BROADCAST,MULTICAST,UP,LOWER_UP> 
  4. Use the addr option with the IP command to view the full information including IP addresses on all network interfaces.

    console
    $ ip a
    

    Your output should look like the one below.

    1: 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
        link/ether 56:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff
        inet 192.0.2.100/23 brd 192.0.2.255 scope global dynamic enp1s0
           valid_lft 78163sec preferred_lft 78163sec
        inet6 2a05:f480:2c00:1ef7:5400:4ff:feef:4023/64 scope global dynamic mngtmpaddr noprefixroute 
           valid_lft 2591891sec preferred_lft 604691sec
        inet6 fe80::5400:4ff:feef:4023/64 scope link 
           valid_lft forever preferred_lft forever
    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc mq state UP group default qlen 1000
        link/ether 5a:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff
        inet 10.50.112.3/20 brd 10.50.127.255 scope global enp8s0
           valid_lft forever preferred_lft forever
        inet6 fe80::5800:4ff:feef:4023/64 scope link 
           valid_lft forever preferred_lft forever
  5. To view specific information about a specific network interface, include the interface name after the IP command. For example, view information about the VPC 2.0 enp8s0 interface.

    console
    $ ip addr show enp8s0
    

    Output:

    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc mq state UP group default qlen 1000
        link/ether 5a:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff
        inet 10.50.112.3/20 brd 10.50.127.255 scope global enp8s0
           valid_lft forever preferred_lft forever
        inet6 fe80::5800:4ff:feef:4023/64 scope link 
           valid_lft forever preferred_lft forever
  6. Run the following command to view detailed statistics about a specific network interface. For example, enp8s0.

    console
    $ ip -s link show enp8s0
    

    Your output should be similar to the one below.

    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 2000 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
        link/ether 56:00:04:ea:91:99 brd ff:ff:ff:ff:ff:ff
        RX:  bytes packets errors dropped  missed   mcast
          25426631   61808      0       0       0       0
        TX:  bytes packets errors dropped carrier collsns
           4351567   40677      0       0       0       0

Manage Interface IP Addresses using the IP Command

IP addresses can be assigned to network interfaces using the Dynamic Host Control Protocol (DHCP) or static addressing to enable network connections on the interface. DHCP is the default address assignment protocol on most servers, but static IP addressing may be required when working with multiple addresses or new interfaces on your server. Follow the steps below to add or remove IP addresses on your server network interfaces.

  1. Run the following command to add a new IP address on your network interface. Replace enp8s0 with your desired interface name.

    console
    $ sudo ip addr add 198.168.1.10/24 dev enp8s0
    

    The above command adds a new private network address 192.168.1.10 to the enp8s0 interface. Depending on your addressing scheme, the interface can run with multiple IP addresses that offer different functions or services on your server.

  2. View the interface information to verify that the new IP address is available.

    console
    $ ip addr show enp8s0
    

    Output:

    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc mq state UP group default qlen 1000
        link/ether 5a:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff
        inet 10.50.112.3/20 brd 10.50.127.255 scope global enp8s0
           valid_lft forever preferred_lft forever
        inet 198.168.1.10/24 scope global enp8s0
           valid_lft forever preferred_lft forever
        inet6 fe80::5800:4ff:feef:4023/64 scope link 
           valid_lft forever preferred_lft forever

    When using multiple IP addresses, you may need to configure routing to enable specific network connections to use the interface IP address.

  3. Use the del option to remove IP addresses on network interfaces. For example, remove the 192.168.1.10/24 address on the enp8so interface.

    console
    $ sudo ip addr del 198.168.1.10/24 dev enp8s0
    
  4. View the interface address information to verify that the address is removed.

    console
    $ ip addr show enp1s0
    

    Output:

    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc mq state UP group default qlen 1000
        link/ether 5a:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff
        inet 10.50.112.3/20 brd 10.50.127.255 scope global enp8s0
           valid_lft forever preferred_lft forever
        inet6 fe80::5800:4ff:feef:4023/64 scope link 
           valid_lft forever preferred_lft forever

Configure Static Routing using the IP Command

Static routing directs traffic to remote networks through a specific network interface or IP address as the next hop to reach the network. Network requests to all addresses 0.0.0.0 are directed through the main server interface by default while network requests to unknown routes may fail due to missing route information. Follow the steps below to configure static routes using the IP command on your server.

  1. View the default IP routing table.

    console
    $ ip route show
    

    Your output should be similar to the one below.

    default via 192.0.2.100 dev enp1s0 proto dhcp src 192.0.2.100 metric 100 
    10.50.112.0/20 dev enp8s0 proto kernel scope link src 10.50.112.3 
    192.0.2.0/23 dev enp1s0 proto kernel scope link src 192.0.2.100 
    169.254.169.254 via 192.0.2.100 dev enp1s0 proto dhcp src 192.0.2.100 metric 100 

    Based on the above output, direct network addresses use the dev option while non-linked addresses use the via option to direct network traffic using the specified address as the next hop. The default route handles all unknown routes on the server unless specified in the routing table.

  2. Add a new static route to a remote network such as 10.0.0.0/16 accessible using a Vultr VPC 2.0 server IP address 10.50.112.4 as the next hop.

    console
    $ sudo ip route add 10.0.0.0/16 via 10.50.112.4
    
  3. View the routing table again to verify that the new route is available.

    console
    $ ip route show
    

    Output:

    default via 192.0.2.100 dev enp1s0 proto dhcp src 192.0.2.100 metric 100 
    10.0.0.0/16 via 10.50.112.4 dev enp8s0 
    10.50.112.0/20 dev enp8s0 proto kernel scope link src 10.50.112.3 
    192.0.2.0/23 dev enp1s0 proto kernel scope link src 192.0.2.100 
    169.254.169.254 via 192.0.2.100 dev enp1s0 proto dhcp src 192.0.2.100 metric 100 

Enable or Disable Network Interfaces

  1. Use the ip link set command to modify the status of a network interface with a specific option. For example, run the following command to disable the enp8s0 interface.

    console
    $ sudo ip link set dev enp8s0 down
    
  2. View the network interface status and verify that the state is DOWN.

    console
    $ ip link show enp8s0
    

    Output:

    3: enp8s0: <BROADCAST,MULTICAST> mtu 1450 qdisc mq state DOWN mode DEFAULT group default qlen 1000
        link/ether 5a:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff
  3. Enable the network interface.

    console
    $ sudo ip link set dev enp8s0 up
    
  4. View the interface information to verify the new status.

    console
    $ ip link show enp8s0
    

    Output:

    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc mq state UP mode DEFAULT group default qlen 1000    link/ether 5a:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff

Managing the Network Interface MTU (Maximum Transmission Unit)

MTU is the maximum size of a packet in bytes that can be transmitted over a network interface without fragmentation. The default MTU value on most network interfaces is 1500. Depending on your needs, modify the value to allow the transfer of large or small data packets on private networks such as Vultr VPC 2.0 network as described in the following steps.

  1. View your target interface MTU value. For example, the VPC 2.0 interface enp8s0.

    console
    $ ip link show enp8s0
    
  2. Verify the MTU value in your output similar to the one below.

    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
        link/ether 56:00:04:ea:91:99 brd ff:ff:ff:ff:ff:ff
  3. Set a new MTU value on the interface. For example, 3000 to transfer large data packets and improve efficiency with other servers in the VPC 2.0 network.

    console
    $ sudo ip link set dev enp8s0 mtu 3000
    
  4. View the interface information again and verify the new MTU value.

    console
    $ ip link show enp8s0
    

    Output:

    3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 3000 qdisc mq state UP mode DEFAULT group default qlen 1000    link/ether 5a:00:04:ef:40:23 brd ff:ff:ff:ff:ff:ff

Conclusion

You have explored the IP command on your Linux server and performed basic network interface management tasks. The IP command is important when troubleshooting, setting up IP addresses, and optimizing your server network connections. For more information and configuration options, run man ip to view the IP command manual.