多种方法在ubuntu系统上查看ip地址

参考:

https://www.howtouseubuntu.com/network/ubuntu-command-terminal-find-ip-address-in-ubuntu/

当使用命令行在Ubuntu系统上获取IP地址时,以下是几个示例:

  1. 使用ip命令获取IP地址:

    $ ip addr show
    

    示例输出:

    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic eth0
           valid_lft 86400sec preferred_lft 86400sec
    

    在上述示例中,eth0接口的IP地址是192.168.1.10。

  2. 使用ifconfig命令获取IP地址:

    $ ifconfig
    

    示例输出:

    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::a00:27ff:fe5c:ebac  prefixlen 64  scopeid 0x20<link>
            ether 08:00:27:5c:eb:ac  txqueuelen 1000  (Ethernet)
            RX packets 26284  bytes 2144348 (2.1 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 24776  bytes 1939930 (1.9 MB)
            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 1558  bytes 115900 (115.9 KB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 1558  bytes 115900 (115.9 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

    在上述示例中,eth0接口的IP地址是192.168.1.10。

  3. 使用hostname命令获取主机名和IP地址:

    $ hostname -I
    

    示例输出:

    192.168.1.10
    

    在上述示例中,主机的IP地址是192.168.1.10。

这些示例演示了如何使用命令行在Ubuntu系统上获取IP地址。根据你的系统配置和网络接口,IP地址可能会有所不同。

猜你喜欢

转载自blog.csdn.net/linux_tcpdump/article/details/131743223