The "ip" command in Linux is a powerful tool for configuring and managing network interfaces. It provides more advanced features compared to the older ifconfig command.
Displaying Network Interface Information:
To view the configuration details of all network interfaces on your system, simply run the "ip" command without any arguments:
$ ip addr show
This command will display information about each network interface, including the interface name, IP address, netmask, MAC address, and more.
Displaying Information for a Specific Interface:
If you want to view the details of a specific network interface, specify its name as an argument to the ip command. For example, to view information about the "eth0" interface:
$ ip addr show eth0
This command will display the configuration details for the "eth0" interface, including its IP address, netmask, MAC address, and more.
Enabling or Disabling an Interface:
To enable or disable a network interface, you can use the "link" subcommand with the ip command. For example, to enable the "eth0" interface:
$ ip link set eth0 up
And to disable the "eth0" interface:
$ ip link set eth0 down
These commands will respectively enable or disable the specified network interface.
Assigning an IP Address to an Interface:
You can assign a specific IP address to a network interface using the ip command. Here's an example of assigning the IP address 192.168.1.100 to the "eth0" interface:
$ ip addr add 192.168.1.100/24 dev eth0
After running this command, the "eth0" interface will be configured with the specified IP address and the subnet mask of /24.
Changing Netmask and Broadcast Address:
To change the netmask or broadcast address of a network interface, use the ip command with the "addr" subcommand. Here's an example of changing the netmask and broadcast address for the "eth0" interface:
$ ip addr add 192.168.1.100/24 brd 192.168.1.255 dev eth0
This command will set the netmask to /24 and the broadcast address to 192.168.1.255 for the "eth0" interface.
Assigning Multiple IP Addresses to an Interface:
Similar to ifconfig, you can assign multiple IP addresses to a single network interface using the ip command. Use the "addr" subcommand with the "add" option to create additional IP addresses for the interface. For example, to assign two additional IP addresses (192.168.1.101 and 192.168.1.102) to the "eth0" interface:
$ ip addr add 192.168.1.101/24 dev eth0 $ ip addr add 192.168.1.102/24 dev eth0
These commands will create two additional IP addresses with the specified IP addresses on the "eth0" interface.
Deleting an IP Address:
To remove an IP address from a network interface, use the "addr" subcommand with the "del" option followed by the IP address and interface name. For example, to delete the IP address 192.168.1.101 from the "eth0" interface:
$ ip addr del 192.168.1.101/24 dev eth0
This command will remove the specified IP address from the "eth0" interface.
These are just a few examples of how you can use the "ip" command in Linux to configure and manage network interfaces. The ip command provides a wide range of functionalities beyond what is covered here, such as managing routing tables, setting up VLANs, and more. It is a versatile tool for advanced networking tasks in Linux environments.