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 ifconfig command. For example, to view information about the "eth0" interface:
$ ifconfig 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 "up" and "down" options with the ifconfig command. For example, to enable the "eth0" interface:
$ ifconfig eth0 up
And to disable the "eth0" interface:
$ ifconfig 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 ifconfig command. Here's an example of assigning the IP address 192.168.1.100 to the "eth0" interface:
$ ifconfig eth0 192.168.1.100
After running this command, the "eth0" interface will be configured with the specified IP address.
Changing Netmask and Broadcast Address:
To change the netmask or broadcast address of a network interface, use the netmask and broadcast options with the ifconfig command. Here's an example of changing the netmask and broadcast address for the "eth0" interface:
$ ifconfig eth0 netmask 255.255.255.0 broadcast 192.168.1.255
This command will set the netmask to 255.255.255.0 and the broadcast address to 192.168.1.255 for the "eth0" interface.
Assigning Multiple IP Addresses to an Interface:
It is also possible to assign multiple IP addresses to a single network interface. Use the "alias" option with the ifconfig command 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:
$ ifconfig eth0:0 192.168.1.101
$ ifconfig eth0:1 192.168.1.102
These commands will create two additional IP aliases (eth0:0 and eth0:1) with the specified IP addresses on the "eth0" interface.
The above examples use the traditional ifconfig command, which is still available in many Linux distributions. However, newer distributions are transitioning to the ip command for network configuration. It is recommended to familiarize yourself with the ip command as well.
Further reading:
Cheat List of Commonly Used Console Commands in Linux