导读 在我们新安装的Ubuntu 20.04操作系统中,我们想要查看ip地址,发现使用ifconfig命令,提示找不到这个命令。在下面文章汇总,会介绍如何安装这个工具。

当在运行ifconfig命令是,提示下面的错误,就代表没有安装它:

bob@ubuntu-20-04:~$ ifconfig

Command 'ifconfig' not found, but can be installed with:

sudo apt install net-tools

或者提示下面的信息:

-bash: ifconfig: command not found

在Ubuntu 20.04中,不建议使用ifconfig命令。这就是为什么会收到有关缺少的ifconfig命令的错误的原因。若想要查看ip地址。可以使用ip addr命令,它几乎可以执行与ifconfig命令相同的任务,如下面的代码所示:

bob@ubuntu-20-04:~$ ip addr
1: lo:  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:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:40:d4:6f brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.174/24 brd 192.168.43.255 scope global dynamic noprefixroute ens33
       valid_lft 1337sec preferred_lft 1337sec
    inet6 fe80::7559:c488:6787:289d/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever


从上面代码输出中可以看到,该命令仍将显示所有网络接口的IP地址和其他统计信息。

如果习惯使用旧的ifconfig命令,则需要安装net-tools软件包。net-tools是一个工具包,其中包含构成Linux网络基础的一系列程序。这些包括:

  • ifconfig
  • netstat
  • dig
  • hostname
  • route
  • arp
  • iptunnel
解决ifconfig命令找不到的问题

要解决以上错误,就需要安装net-tools工具包:

bob@ubuntu-20-04:~$ sudo apt install net-tools


安装成功完成后,再次尝试运行ifconfig命令,可以看到熟悉的面孔了。

总结

ifconfig已经逐渐被ip addr取代了,因为现在大部分发行版本,比如Centos\RHEL、Fedora、Ubuntu等系统都取消了net-tools工具包了。

本文原创地址:https://www.linuxprobe.com/ubuntu-ifconfig-command.html编辑:逄增宝,审核员:逄增宝