Skip to content
Home ยป ifconfig and ip Command Gist With Practical Use Cases

ifconfig and ip Command Gist With Practical Use Cases

ifconfig Command

ifconfig (short for “interface configuration”) is a command-line utility that allows you to configure network interfaces on your system. It’s been around for a long time, and is still widely used despite the availability of newer tools like ip.

Practical use-cases for ifconfig:

Displaying network interface information:

$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:11:22:33:44:55
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::211:22ff:fe33:4455/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:31771 errors:0 dropped:0 overruns:0 frame:0
          TX packets:29072 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:49938718 (47.8 MiB)  TX bytes:3968576 (3.7 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:1456 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1456 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:127896 (124.8 KiB)  TX bytes:127896 (124.8 KiB)

This command will display information about all the network interfaces on your system, including the interface name (eth0, lo, etc.), IP address, and other important details.

Bringing a network interface up or down:

$ ifconfig eth0 down
$ ifconfig eth0 up

These commands will bring the eth0 interface down (disconnect it from the network) and then bring it back up (reconnect it to the network). This can be useful if you need to troubleshoot network issues or perform maintenance on the interface.

Changing the IP address of a network interface:

$ ifconfig eth0 192.168.1.200 netmask 255.255.255.0

This command will change the IP address of the eth0 interface to 192.168.1.200, with a netmask of 255.255.255.0. This can be useful if you need to change the IP address of your system for some reason, or if you want to assign a static IP address to your system.

ip Command

ip is a newer command-line utility that was introduced in the Linux 2.2 kernel. It’s similar to ifconfig, but it offers more advanced features and is generally considered a more powerful tool. Here are a few practical use-cases for ip:

Displaying network interface information:

$ ip address show
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 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::211:22ff:fe33:4455/64 scope link
       valid_lft forever preferred_lft forever

This command will display information about all the network interfaces on your system, including the interface name, MAC address, and IP address.

Adding or deleting IP addresses:

$ ip address add 192.168.1.200/24 dev eth0
$ ip address delete 192.168.1.200/24 dev eth0

These commands will add or delete an IP address (192.168.1.200) to/from the eth0 interface. This can be useful if you need to temporarily add an additional IP address to your system, or if you want to remove an unnecessary IP address.

Setting the default route:

$ ip route add default via 192.168.1.1 dev eth0
$ ip route delete default via 192.168.1.1 dev eth0

These commands will set or delete the default route (the route used for all outbound traffic) to go through the gateway at 192.168.1.1 on the eth0 interface. This can be useful if you need to change the gateway your system uses to access the internet, or if you want to remove the default route altogether.

Leave a Reply

Your email address will not be published. Required fields are marked *

1 + 6 =