Home > System Tutorial > LINUX > How to check the local IP in linux system

How to check the local IP in linux system

WBOY
Release: 2024-02-24 14:00:11
Original
1193 people have browsed it

There are many ways to check the local IP address in Linux system. The following are three commonly used methods and their corresponding code examples.

Method 1:
Use the ifconfig command to view the IP address of the machine.

Open the terminal and enter the following command:

ifconfig
Copy after login

In the output, you can find the IP address corresponding to the network interface you are currently using. Usually, the IP address corresponding to the line starting with "inet" is the IP address of the local machine.

Example output:

enp0s3: 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::a00:27ff:fea5:c6d3  prefixlen 64  scopeid 0x20<link>
         ether 08:00:27:a5:c6:d3  txqueuelen 1000  (Ethernet)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 0  bytes 0 (0.0 B)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Copy after login

In this example, "enp0s3" is the name of the network interface, and "inet 192.168.1.100" corresponds to the IP address of the machine.

Method 2:
Use the ip command to view the IP address of the machine.

Open the terminal and enter the following command:

ip addr show
Copy after login

In the output, you can find the line starting with "inet", and the subsequent numbers are the IP address of the machine.

Example output:

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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    inet 192.168.1.100/24 brd 192.168.1.255 scope global enp0s3
       valid_lft forever preferred_lft forever
Copy after login

In this example, "lo" is the loopback interface, "enp0s3" is the network interface, and "inet 192.168.1.100/24" corresponds to the IP of the local machine address.

Method 3:
Use the hostname command to view the IP address of the machine.

Open the terminal and enter the following command:

hostname -I
Copy after login

The command will directly output the IP address of the machine.

Example output:

192.168.1.100 
Copy after login

This is the IP address of this machine.

Whether you use the ifconfig, ip or hostname command, you can easily check the IP address of the machine in the Linux system. Just choose the method that suits you according to the specific situation.

The above is the detailed content of How to check the local IP in linux system. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template