SoFunction
Updated on 2025-04-13

CentOS8 View IP Error: bash:ifconfig:command not found Reasons and Solutions

introduction

When using CentOS 8 systems, you sometimes encounter an error of ​​bash: ifconfig: command not found​​ when viewing network interface information using the ifconfig command. This is because starting from CentOS 7, the system no longer has the net-tools package installed by default, and the ​​ifconfig command is included in this package.

Cause of the problem

Ifconfig​​ is a command line tool for configuring and displaying network interfaces, and was widely used in earlier Linux distributions. However, with the development of network configuration management tools, ​​​​​ commands have gradually become the new standard. Therefore, starting with CentOS 7, the ​​net-tools​ package is no longer one of the default installed packages.

Solution

Method 1: Install the ​​net-tools​ package

If you still want to use​ifconfig​Commands can be installed by installing​net-tools​Package to solve this problem. Open the terminal and execute the following command:

sudo dnf install net-tools

After the installation is complete, you can use the ​​ifconfig command normally.

Method 2: Use the ​​ip​​ command

It is recommended to use the ​​ip​​ command instead of ​​ifconfig, because the ​​ip​​ command is more powerful and supports more network configuration operations. Here are some commonly used ​​ip​​ command examples:

  • Check the status of all network interfaces:
ip addr show
  • Check the status of a specific network interface(e.g. eth0):
ip addr show eth0
  • Enable or disable network interfaces
sudo ip link set eth0 up   # Enable the eth0 interfacesudo ip link set eth0 down # Disabled eth0 interface
  • Add or delete an IP address
sudo ip addr add 192.168.1.100/24 dev eth0  # Add IP addresssudo ip addr del 192.168.1.100/24 dev eth0  # delete IP address

In order to adapt to the development trend of modern Linux systems, it is recommended to learn and use​ip​Commands to configure and manage networks. ​​ip​​ Commands are not only powerful, but also the direction of future development. In CentOS 8, by default ​​ifconfig​The command may not be installed because CentOS 8 uses​ip​Commands are the main tool for network configuration. If you try to use​ifconfig​Commands, you may encounter​bash: ifconfig: command not found​Error.

Solution

  1. Installnet-toolsPackage: You can install itnet-toolsPackage to getifconfigOrder. Use the following command:
sudo dnf install net-tools
  • useipCommand: If you don't want to install additional packages, you can useipCommands to view and manage network interfaces. The following is usedipExample of command viewing IP address:
ip addr show

Sample code

Install ​​net-tools​​ and use ​​ifconfig​

# Install the net-tools packagesudo dnf install net-tools
 
# View the IP addresses of all network interfacesifconfig

Use the ​​ip​ command to view the IP address

# View the IP addresses of all network interfacesip addr show
 
# Check the IP address of a specific network interface, such as eth0ip addr show eth0

Practical application scenarios

Suppose you are working on a CentOS 8 server and need to check the server's IP address, but encounter it​bash: ifconfig: command not found​Error. You can follow the steps below:

  • Check if it is installednet-tools​:
ifconfig -version

If output​bash: ifconfig: command not found​, then it means​net-tools​​ Not installed.

  • Installnet-tools​:
sudo dnf install net-tools
  • useifconfigView IP address
ifconfig
  • Or use it directlyipCommand
ip addr show

Through the above steps, you can successfully view the IP address of the server, regardless of whether the ​​net-tools​​​ package is installed. In CentOS 8, the ifconfig command is not installed by default, because ifconfig is considered an older tool and has been replaced by the ​​​ip​​ command. When you try to use the ifconfig command, the system prompts ​​bash: ifconfig: command not found.

​​bash: ifconfig: command not found

Solution

Method 1: Use the ​​ip​​ command

​​​ip​​ Command is a more modern and more powerful network configuration tool. You can use the following command to view the IP address:

ip addr show

This command will display detailed information of all network interfaces, including IP addresses, subnet masks, etc.

Method 2: Install ifconfig​

If you still want to use the ifconfig command, you can install the ​​net-tools​​ package, which contains the ​​ifconfig tool.

  • Open the terminal.
  • Install ​​net-tools​​ using the following command:
sudo dnf install net-tools
  • After the installation is complete, you can use​ifconfig​Command:
ifconfig

Example

Use the ​​ip​ command to view the IP address

$ ip addr show
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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:1a:2b:3c brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic noprefixroute ens33
       valid_lft 86399sec preferred_lft 86399sec
    inet6 fe80::20c:29ff:fe1a:2b3c/64 scope link 
       valid_lft forever preferred_lft forever

In this output,​ens33​​​ is the name of the network interface,​inet 192.168.1.100/24​​ Indicates the IPv4 address and subnet mask of the interface.

Install ​​ifconfig​​ and view the IP address

$ sudo dnf install net-tools
...
Complete!
 
$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe1a:2b3c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:1a:2b:3c  txqueuelen 1000  (Ethernet)
        RX packets 12345  bytes 12345678 (11.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12345  bytes 12345678 (11.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1234  bytes 123456 (120.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1234  bytes 123456 (120.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

In this output, the IPv4 address of the ens33 interface is 192.168.1.100 and the subnet mask is 255.255.255.0.

Summarize

Although ifconfig​​ is a familiar tool, the ​​ip​​ command provides more functionality and flexibility. It is recommended to use the ​​ip​​ command in CentOS 8 and later for network configuration and management. If you really need to use ifconfig, you can do so by installing the ​​net-tools​ package.

The above is the detailed content of the reason and solution for CentOS8 to view IP error: bash:ifconfig:command not found. For more information about CentOS8 to view IP error, please pay attention to my other related articles!