User Tools

Site Tools


wiki:ip_-_the_ifconfig_replacement

IP - The ifconfig replacement



Anyone who has used Linux will likely be familiar with the ifconfig command. Apparently ifconfig was deprecated some time ago, but has still been included in CentOS and Red Hat. Well version 7 has finally left out ifconfig and so now we move on to it's replacement called ip

Basic IP Commands


  ip a


This command will list all interfaces with their associated information.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    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 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:25:73:7d brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.7/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::9c01:198b:dfcf:da93/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether b8:27:eb:70:26:28 brd ff:ff:ff:ff:ff:ff


Let’s say you only want to see IPv4 information (for clarity). To do this, issue the command:

  ip -4 a


Or, if you only want to see IPv6 information:

  ip -6 a


What if you only want to see information regarding a specific interface? You can list information for a wireless connection with the command:

  ip a show wlan0


You can even get more specific with this command. If you only want to view IPv4 on the wlan0 interface, issue the command:

  ip -4 a show wlan0


You can even list only the running interface using:

  ip link ls up


1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:25:73:7d brd ff:ff:ff:ff:ff:ff
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:70:26:28 brd ff:ff:ff:ff:ff:ff



Modifying an Interface


Now we get into the heart of the command… using it to modify an interface. Suppose you wanted to assign a specific address to the first ethernet interface, eth0. With the ifconfig command, that would look like:

  ifconfig eth0 192.168.1.101


With the ip command, this now looks like:

  ip a add 192.168.1.101/255.255.255.0 dev eth0


You could shorten this a bit with:

  ip a add 192.168.1.101/24 dev eth0


Clearly, you will need to know the subnet mask of the address you are assigning.

What about deleting an address from an interface? With the ip command, you can do that as well. For example, to delete the address just assigned to eth0, issue the following command:

  ip a del 192.168.1.101/24 dev eth0


What if you want to simply flush all addresses from all interfaces? The ip command has you covered with this command:

  ip -s -s a f to 192.168.1.0/24


Another crucial aspect of the ip command is the ability to bring up/down an interface. To bring eth0 down, issue:

  ip link set dev eth0 down


To bring eth0 back up, use:

  ip link set dev eth0 up


With the ip command, you can also add and delete default gateways. This is handled like so:

  ip route add default via 192.168.1.254


If you want to get really detailed on your interfaces, you can edit the transmit queue. You can set the transmit queue to a low value for slower interfaces and a higher value for faster interfaces. To do this, the command would look like:

  ip link set txqueuelen 10000 dev eth0


The above command would set a high transmit queue. You can play around with this value to find what works best for your hardware.

You can also set the Maximum Transmission Unit (MTU) of your network interface with the command:

  ip link set mtu 9000 dev eth0


Once you’ve made the changes, use ip a list eth0 to verify the changes have gone into effect.


Managing the Routing Table


With the ip command you can also manage the system’s routing tables. This is a very powerful element of the ip command, and you should use it with caution.

Suppose you want to view all routing tables. To do this, you would issue the command:

  ip r


The output of this command will look like that shown in Figure 2.
Now, say you want to route all traffic via the 192.168.1.254 gateway connected via eth0 network interface: To do that, issue the command:

  ip route add 192.168.1.0/24 dev eth0


To delete that same route, issue:

  ip route del 192.168.1.0/24 dev eth0



This article should serve as merely an introduction to the ip command. This, of course, doesn’t mean you must immediately jump from ifconfig. Because the deprecation of ifconfig has been so slow, the command still exists on many a distribution. But, on the occasion of ifconfig finally vanishing from sight, you’ll be ready to make the transition with ease. For more detailed information on the ip command, take a look at the ip man page by issuing the command man ip from a terminal window.


This article was taken from https://www.linux.com/learn/replacing-ifconfig-ip

wiki/ip_-_the_ifconfig_replacement.txt · Last modified: 2017/02/28 18:00 (external edit)